mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #41385 # Details This PR updates `fleetctl` to use the new API urls and params when communicating with Fleet server. This avoids deprecation warnings showing up on the server that users won't be able to fix. Most of the changes are straightforward `team_id` -> `fleet_id`. A couple of code changes have been pointed out. The most interesting is in icon URLs, which can be persisted in the database (so we'll need to do a migration in Fleet 5 if we want to drop support for `team_id`. Similarly the FMA download urls are briefly persisted in the db for the purpose of sending MDM commands. If we drop team_id support in Fleet 5 there could be a brief window where there are unprocessed commands in the db still with `team_id` in them, so we'll probably want to migrate those as well. # Checklist for submitter If some of the following don't apply, delete the relevant line. - [ ] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. n/a - all internal ## Testing - [X] Added/updated automated tests - [X] QA'd all new/changed functionality manually - [X] ran `fleetctl gitops` on main and saw a bunch of deprecation warnings, ran it on this branch and the warnings were gone 💨 - [X] same with `fleetctl generate-gitops` - [X] ran `fleetctl get` commands and verified that the new URLs and params were used - [X] ran `fleetctl apply` commands and verified that the new URLs and params were used
69 lines
2.5 KiB
Go
69 lines
2.5 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
|
"github.com/fleetdm/fleet/v4/server/platform/endpointer"
|
|
"github.com/fleetdm/fleet/v4/server/version"
|
|
)
|
|
|
|
// ApplyAppConfig sends the application config to be applied to the Fleet instance.
|
|
func (c *Client) ApplyAppConfig(payload interface{}, opts fleet.ApplySpecOptions) error {
|
|
verb, path := "PATCH", "/api/latest/fleet/config"
|
|
var responseBody appConfigResponse
|
|
data, err := json.Marshal(payload)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
data, err = endpointer.RewriteOldToNewKeys(data, endpointer.ExtractAliasRules(fleet.AppConfig{}))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return c.authenticatedRequestWithQuery(data, verb, path, &responseBody, opts.RawQuery())
|
|
}
|
|
|
|
// ApplyNoTeamProfiles sends the list of profiles to be applied for the hosts
|
|
// in no team.
|
|
func (c *Client) ApplyNoTeamProfiles(profiles []fleet.MDMProfileBatchPayload, opts fleet.ApplySpecOptions, assumeEnabled bool) error {
|
|
verb, path := "POST", "/api/latest/fleet/mdm/profiles/batch"
|
|
query := opts.RawQuery()
|
|
if assumeEnabled {
|
|
if query != "" {
|
|
query += "&"
|
|
}
|
|
query += "assume_enabled=true"
|
|
}
|
|
return c.authenticatedRequestWithQuery(map[string]interface{}{"profiles": profiles}, verb, path, nil, query)
|
|
}
|
|
|
|
// GetAppConfig fetches the application config from the server API
|
|
func (c *Client) GetAppConfig() (*fleet.EnrichedAppConfig, error) {
|
|
verb, path := "GET", "/api/latest/fleet/config"
|
|
var responseBody fleet.EnrichedAppConfig
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return &responseBody, err
|
|
}
|
|
|
|
// GetEnrollSecretSpec fetches the enroll secrets stored on the server
|
|
func (c *Client) GetEnrollSecretSpec() (*fleet.EnrollSecretSpec, error) {
|
|
verb, path := "GET", "/api/latest/fleet/spec/enroll_secret"
|
|
var responseBody getEnrollSecretSpecResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Spec, err
|
|
}
|
|
|
|
// ApplyEnrollSecretSpec applies the enroll secrets.
|
|
func (c *Client) ApplyEnrollSecretSpec(spec *fleet.EnrollSecretSpec, opts fleet.ApplySpecOptions) error {
|
|
req := applyEnrollSecretSpecRequest{Spec: spec}
|
|
verb, path := "POST", "/api/latest/fleet/spec/enroll_secret"
|
|
var responseBody applyEnrollSecretSpecResponse
|
|
return c.authenticatedRequestWithQuery(req, verb, path, &responseBody, opts.RawQuery())
|
|
}
|
|
|
|
func (c *Client) Version() (*version.Info, error) {
|
|
verb, path := "GET", "/api/latest/fleet/version"
|
|
var responseBody versionResponse
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
return responseBody.Info, err
|
|
}
|