fleet/server/service/client_appconfig.go
Victor Lyuboslavsky e4d5e27dd9
fleetctl gitops (#16535)
Add `fleetctl gitops` command for #13643 

Code review video:
https://www.loom.com/share/7941c51c709b44ccafd618dd05837d99?sid=27b923d7-1393-4396-bac7-30616b2d6de9

fleet-gitops PR that also needs review:
https://github.com/fleetdm/fleet-gitops/pull/26

Working global/team gitops configs that can be used for testing:
https://github.com/fleetdm/fleet-gitops/tree/victor/fixing-configs

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/` or
`orbit/changes/`.
- [x] Added/updated tests
- [x] Manual QA for all new/changed functionality
2024-02-09 13:34:57 -06:00

59 lines
2.2 KiB
Go

package service
import (
"github.com/fleetdm/fleet/v4/server/fleet"
"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
return c.authenticatedRequestWithQuery(payload, 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) error {
req := applyEnrollSecretSpecRequest{Spec: spec}
verb, path := "POST", "/api/latest/fleet/spec/enroll_secret"
var responseBody applyEnrollSecretSpecResponse
return c.authenticatedRequest(req, verb, path, &responseBody)
}
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
}