Skip to content

A free open source IT asset/license management system

Removed dead code - Fleet doesn’t push

snipebd91dd04bca5
diff --git a/app/SyncAdapters/Fleet/FleetAdapter.php b/app/SyncAdapters/Fleet/FleetAdapter.php
index c0b05d9536..8e389ae777 100644
--- a/app/SyncAdapters/Fleet/FleetAdapter.php
+++ b/app/SyncAdapters/Fleet/FleetAdapter.php
@@ -272,91 +272,4 @@ class FleetAdapter extends ConfigurableAdapter
return Carbon::parse($value);
}
-
- /**
- * Push Snipe-IT-authoritative fields to Fleet as manual labels.
- * Fleet has no native asset_tag / notes columns, so each push-
- * directed field becomes a per-host manual label named
- * `snipeit_{field}_{value}`. Membership is set via label-spec so
- * one API call creates the label (if new) and sets its member
- * host in a single round trip.
- *
- * Uses the asset's serial number to identify the host to Fleet
- * because serial is more stable than hostname across renames
- * and re-enrollments. Silently no-ops when the asset has no
- * serial (nothing to identify the Fleet host with).
- *
- * @param array<int, string> $changedFields
- */
- public function push(Asset $asset, array $changedFields = []): void
- {
- $pushFields = $this->pushDirectedFields();
- if ($pushFields === []) {
- return;
- }
-
- if ($changedFields !== [] && array_intersect($changedFields, $pushFields) === []) {
- return;
- }
-
- $externalSource = AssetExternalSource::query()
- ->where('asset_id', $asset->id)
- ->where('source', $this->name())
- ->first();
-
- if ($externalSource === null) {
- return;
- }
-
- $serial = $asset->serial;
- if ($serial === null || $serial === '') {
- return;
- }
-
- $client = new FleetClient(baseUrl: $this->url(), token: $this->credential('token'));
-
- foreach ($pushFields as $field) {
- $value = $this->assetValueForSourceField($asset, $field);
- if ($value === null || $value === '') {
- continue;
- }
-
- $labelName = self::labelNameFor($field, $value);
- $client->upsertManualLabelForHost($labelName, $serial);
-
- Log::channel('sync-adapters')->info(sprintf(
- '%s push: set label "%s" on Fleet host serial=%s',
- $this->name(),
- $labelName,
- $serial,
- ));
- }
- }
-
- /**
- * Build the Fleet label name for a Snipe-IT source-field / value
- * pair. `snipeit_` prefix so admins can filter Fleet's label list
- * down to the sync-managed ones. Underscore separator between
- * field name and value because Fleet's label names allow letters,
- * digits, underscores, and hyphens but not colons or slashes.
- * Value is sanitized to the same charset.
- */
- private static function labelNameFor(string $field, string $value): string
- {
- return 'snipeit_'.$field.'_'.preg_replace('/[^A-Za-z0-9_\\-]/', '_', $value);
- }
-
- /**
- * Resolve a Snipe-IT source of truth for a given source-field
- * name. Currently only asset_tag is push-supported for Fleet
- * (the vendor field most commonly requested); additional fields
- * add cases here as we wire them.
- */
- private function assetValueForSourceField(Asset $asset, string $field): ?string
- {
- return match ($field) {
- 'asset_tag' => $asset->asset_tag,
- default => null,
- };
- }
}
diff --git a/app/SyncAdapters/Fleet/FleetClient.php b/app/SyncAdapters/Fleet/FleetClient.php
index bcc29c635a..044ee12ca6 100644
--- a/app/SyncAdapters/Fleet/FleetClient.php
+++ b/app/SyncAdapters/Fleet/FleetClient.php
@@ -114,71 +114,6 @@ class FleetClient
return is_string($tier) ? strtolower($tier) : null;
}
- /**
- * Upsert a manual label with the specified host as its sole member.
- * Fleet's spec-apply endpoint is gated behind Premium / gitops mode
- * on some builds, so this uses the individual /labels endpoints
- * instead: GET to find an existing label by name, PATCH to update
- * host membership, or POST to create when absent. Two API calls in
- * the update path, three in the create path (list + create + noop).
- *
- * Fleet identifies label hosts by "identifier" (hostname, hardware
- * serial, or UUID). Serial is the most stable of the three across
- * renames and re-enrollments, so callers pass that.
- *
- * Silently no-ops when either arg is blank so a partial-config
- * push doesn't punch a random label into the fleet.
- */
- public function upsertManualLabelForHost(string $labelName, string $hostIdentifier): void
- {
- if ($labelName === '' || $hostIdentifier === '') {
- return;
- }
-
- $existingId = $this->findLabelIdByName($labelName);
-
- if ($existingId !== null) {
- $this->request()
- ->patch('/api/latest/fleet/labels/'.$existingId, [
- 'hosts' => [$hostIdentifier],
- ])
- ->throw();
-
- return;
- }
-
- $this->request()
- ->post('/api/latest/fleet/labels', [
- 'name' => $labelName,
- 'description' => 'Managed by Snipe-IT sync push',
- 'label_membership_type' => 'manual',
- 'hosts' => [$hostIdentifier],
- ])
- ->throw();
- }
-
- /**
- * Look up a Fleet label id by its exact name. Fleet's /labels
- * endpoint doesn't support server-side name filtering, so we page
- * through and match client-side. Returns null when no label with
- * that name exists.
- */
- private function findLabelIdByName(string $name): ?int
- {
- $response = $this->request()
- ->get('/api/latest/fleet/labels', ['per_page' => 500])
- ->throw()
- ->json();
-
- foreach ($response['labels'] ?? [] as $label) {
- if (($label['name'] ?? null) === $name) {
- return (int) $label['id'];
- }
- }
-
- return null;
- }
-
private function request(): PendingRequest
{
return Http::baseUrl(rtrim($this->baseUrl, '/'))