mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
b3e038fffc
#11531 How to use: ``` go run ./tools/mdm/apple/loadtest -api_token $API_TOKEN -fleet_url https://fleet.example.com -team_count 5 -team_extra_count 2 -loop_count 1 2023-05-15T16:05:06Z: 1. Creating 5 teams... (press enter to proceed) 2023-05-15T16:05:18Z: 1. Duration: 165.020742ms 2023-05-15T16:05:18Z: 2. Transfering one host to each team... (press enter to proceed) 2023-05-15T16:05:20Z: 2. Duration: 370.515741ms 2023-05-15T16:05:20Z: 3a. Add 10 profiles to all teams... (press enter to proceed) 2023-05-15T16:05:22Z: Applying profiles to team Team 0... 2023-05-15T16:05:22Z: Applying profiles to team Team 1... 2023-05-15T16:05:22Z: Applying profiles to team Team 2... 2023-05-15T16:05:22Z: Applying profiles to team Team 3... 2023-05-15T16:05:22Z: Applying profiles to team Team 4... 2023-05-15T16:05:22Z: 3a. Duration: 502.557741ms 2023-05-15T16:05:22Z: 3b. Waiting for all profiles to be applied on all teams... 2023-05-15T16:05:22Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:27Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:32Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:37Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:42Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:1 Pending:0 Failed:0} 43:{Verifying:1 Pending:0 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:48Z: 3b. Duration: 25.487993296s 2023-05-15T16:05:48Z: 4a. Modify a profile on all teams... (press enter to proceed) 2023-05-15T16:05:50Z: 4a. Duration: 654.712391ms 2023-05-15T16:05:50Z: 4b. Waiting for all profiles to be applied on all hosts of all teams... 2023-05-15T16:05:50Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:05:55Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:06:00Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:06:05Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:0 Pending:1 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:06:10Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:1 Pending:0 Failed:0} 43:{Verifying:0 Pending:1 Failed:0} 44:{Verifying:0 Pending:1 Failed:0} 45:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:06:15Z: Waiting for all profiles to be applied on hosts..., summary: map[41:{Verifying:0 Pending:1 Failed:0} 42:{Verifying:1 Pending:0 Failed:0} 43:{Verifying:1 Pending:0 Failed:0} 44:{Verifying:1 Pending:0 Failed:0} 45:{Verifying:1 Pending:0 Failed:0}] 2023-05-15T16:06:20Z: 4b. Duration: 30.48166655s 2023-05-15T16:06:20Z: 5. Creating extra 2 teams... (press enter to proceed) 2023-05-15T16:06:22Z: 5. Duration: 72.531251ms 2023-05-15T16:06:22Z: 6a. Moving one host to each new extra 2 teams... (press enter to proceed) 2023-05-15T16:07:23Z: 6a. Duration: 164.446788ms 2023-05-15T16:07:23Z: 6b. Waiting for all profiles to be applied on all hosts of the extra teams... 2023-05-15T16:07:23Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:07:29Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:07:34Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:07:39Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:07:44Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:1 Pending:0 Failed:0}] 2023-05-15T16:07:49Z: 6b. Duration: 25.210811603s 2023-05-15T16:07:49Z: 7a. Add 10 profiles to all extra 2 teams... (press enter to proceed) 2023-05-15T16:07:50Z: 7a. Duration: 175.694423ms 2023-05-15T16:07:50Z: 7b. Waiting for all profiles to be applied on all hosts of the extra teams... 2023-05-15T16:07:50Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:07:55Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:08:01Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:08:06Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:0 Pending:1 Failed:0}] 2023-05-15T16:08:11Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:1 Pending:0 Failed:0}] 2023-05-15T16:08:16Z: Waiting for all profiles to be applied on hosts..., summary: map[46:{Verifying:0 Pending:1 Failed:0} 47:{Verifying:1 Pending:0 Failed:0}] 2023-05-15T16:08:21Z: 7b. Duration: 30.219261468s 2023-05-15T16:08:21Z: 8. Destroy 2 extra teams... (press enter to proceed) 2023-05-15T16:08:31Z: 8. Duration: 134.372194ms ``` - ~[ ] Changes file added for user-visible changes in `changes/` or `orbit/changes/`.~ See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - ~[ ] Documented any API changes (docs/Using-Fleet/REST-API.md or docs/Contributing/API-for-contributors.md)~ - ~[ ] Documented any permissions changes~ - ~[ ] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements)~ - ~[ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for new osquery data ingestion features.~ - ~[ ] Added/updated tests~ - [X] Manual QA for all new/changed functionality - ~For Orbit and Fleet Desktop changes:~ - ~[ ] Manual QA must be performed in the three main OSs, macOS, Windows and Linux.~ - ~[ ] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).~
71 lines
2.3 KiB
Go
71 lines
2.3 KiB
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/url"
|
|
"strconv"
|
|
|
|
"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
|
|
}
|
|
|
|
// CreateTeam creates a new team.
|
|
func (c *Client) CreateTeam(teamPayload fleet.TeamPayload) (*fleet.Team, error) {
|
|
req := createTeamRequest{
|
|
TeamPayload: teamPayload,
|
|
}
|
|
verb, path := "POST", "/api/latest/fleet/teams"
|
|
var responseBody teamResponse
|
|
err := c.authenticatedRequest(req, verb, path, &responseBody)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return responseBody.Team, nil
|
|
}
|
|
|
|
// DeleteTeam deletes a team.
|
|
func (c *Client) DeleteTeam(teamID uint) error {
|
|
verb, path := "DELETE", "/api/latest/fleet/teams/"+strconv.FormatUint(uint64(teamID), 10)
|
|
var responseBody deleteTeamResponse
|
|
return c.authenticatedRequest(nil, verb, path, &responseBody)
|
|
}
|
|
|
|
// 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)
|
|
}
|