package service import ( "encoding/json" "net/url" "github.com/fleetdm/fleet/v4/server/fleet" ) // ListTeams retrieves the list of teams. func (c *Client) ListTeams(query string) ([]fleet.Team, error) { verb, path := "GET", "/api/latest/fleet/teams" var responseBody listTeamsResponse err := c.authenticatedRequestWithQuery(nil, verb, path, &responseBody, query) if err != nil { return nil, err } return responseBody.Teams, nil } // ApplyTeams sends the list of Teams to be applied to the // Fleet instance. func (c *Client) ApplyTeams(specs []json.RawMessage, opts fleet.ApplySpecOptions) error { verb, path := "POST", "/api/latest/fleet/spec/teams" var responseBody applyTeamSpecsResponse return c.authenticatedRequestWithQuery(map[string]interface{}{"specs": specs}, verb, path, &responseBody, opts.RawQuery()) } // ApplyTeamProfiles sends the list of profiles to be applied for the specified // team. func (c *Client) ApplyTeamProfiles(tmName string, profiles [][]byte, opts fleet.ApplySpecOptions) error { verb, path := "POST", "/api/latest/fleet/mdm/apple/profiles/batch" query, err := url.ParseQuery(opts.RawQuery()) if err != nil { return err } query.Add("team_name", tmName) return c.authenticatedRequestWithQuery(map[string]interface{}{"profiles": profiles}, verb, path, nil, query.Encode()) } // ApplyPolicies sends the list of Policies to be applied to the // Fleet instance. func (c *Client) ApplyPolicies(specs []*fleet.PolicySpec) error { req := applyPolicySpecsRequest{Specs: specs} verb, path := "POST", "/api/latest/fleet/spec/policies" var responseBody applyPolicySpecsResponse return c.authenticatedRequest(req, verb, path, &responseBody) }