2018-05-22 23:57:56 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2024-01-02 21:22:52 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/version"
|
2018-05-22 23:57:56 +00:00
|
|
|
)
|
|
|
|
|
2019-11-20 05:13:15 +00:00
|
|
|
// ApplyAppConfig sends the application config to be applied to the Fleet instance.
|
2022-09-19 17:53:44 +00:00
|
|
|
func (c *Client) ApplyAppConfig(payload interface{}, opts fleet.ApplySpecOptions) error {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "PATCH", "/api/latest/fleet/config"
|
2018-05-22 23:57:56 +00:00
|
|
|
var responseBody appConfigResponse
|
2022-09-19 17:53:44 +00:00
|
|
|
return c.authenticatedRequestWithQuery(payload, verb, path, &responseBody, opts.RawQuery())
|
2019-11-20 05:13:15 +00:00
|
|
|
}
|
2018-05-22 23:57:56 +00:00
|
|
|
|
2023-02-15 18:01:44 +00:00
|
|
|
// ApplyNoTeamProfiles sends the list of profiles to be applied for the hosts
|
|
|
|
// in no team.
|
2024-02-09 19:34:57 +00:00
|
|
|
func (c *Client) ApplyNoTeamProfiles(profiles []fleet.MDMProfileBatchPayload, opts fleet.ApplySpecOptions, assumeEnabled bool) error {
|
2023-11-29 14:32:42 +00:00
|
|
|
verb, path := "POST", "/api/latest/fleet/mdm/profiles/batch"
|
2024-02-09 19:34:57 +00:00
|
|
|
query := opts.RawQuery()
|
|
|
|
if assumeEnabled {
|
|
|
|
if query != "" {
|
|
|
|
query += "&"
|
|
|
|
}
|
|
|
|
query += "assume_enabled=true"
|
|
|
|
}
|
|
|
|
return c.authenticatedRequestWithQuery(map[string]interface{}{"profiles": profiles}, verb, path, nil, query)
|
2023-02-15 18:01:44 +00:00
|
|
|
}
|
|
|
|
|
2019-11-20 05:13:15 +00:00
|
|
|
// GetAppConfig fetches the application config from the server API
|
2021-10-07 13:19:10 +00:00
|
|
|
func (c *Client) GetAppConfig() (*fleet.EnrichedAppConfig, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/config"
|
2022-01-24 19:40:51 +00:00
|
|
|
var responseBody fleet.EnrichedAppConfig
|
|
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
|
|
return &responseBody, err
|
2019-11-20 05:13:15 +00:00
|
|
|
}
|
|
|
|
|
2020-05-29 16:12:39 +00:00
|
|
|
// GetEnrollSecretSpec fetches the enroll secrets stored on the server
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) GetEnrollSecretSpec() (*fleet.EnrollSecretSpec, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/spec/enroll_secret"
|
2020-05-29 16:12:39 +00:00
|
|
|
var responseBody getEnrollSecretSpecResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
|
|
return responseBody.Spec, err
|
2020-05-29 16:12:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ApplyEnrollSecretSpec applies the enroll secrets.
|
2021-06-06 22:07:29 +00:00
|
|
|
func (c *Client) ApplyEnrollSecretSpec(spec *fleet.EnrollSecretSpec) error {
|
2020-05-29 16:12:39 +00:00
|
|
|
req := applyEnrollSecretSpecRequest{Spec: spec}
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "POST", "/api/latest/fleet/spec/enroll_secret"
|
2020-05-29 16:12:39 +00:00
|
|
|
var responseBody applyEnrollSecretSpecResponse
|
2022-01-24 19:40:51 +00:00
|
|
|
return c.authenticatedRequest(req, verb, path, &responseBody)
|
2020-05-29 16:12:39 +00:00
|
|
|
}
|
2022-02-14 16:43:34 +00:00
|
|
|
|
|
|
|
func (c *Client) Version() (*version.Info, error) {
|
2022-04-05 15:35:53 +00:00
|
|
|
verb, path := "GET", "/api/latest/fleet/version"
|
2022-02-14 16:43:34 +00:00
|
|
|
var responseBody versionResponse
|
|
|
|
err := c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
|
|
return responseBody.Info, err
|
|
|
|
}
|