@@ -59,22 +59,36 @@ func (c *Client) ListAgents(ctx context.Context) ([]Agent, error) {
5959 }
6060
6161 var resp struct {
62- List []Agent `json:"list"`
62+ List []Agent `json:"list"`
63+ Items []Agent `json:"items"`
6364 }
6465
6566 if err := json .Unmarshal (respBody , & resp ); err != nil {
6667 return nil , fmt .Errorf ("could not convert list agents (response) to JSON: %w" , err )
6768 }
6869
69- return resp .List , nil
70+ switch {
71+ case c .semver .Major () < 9 :
72+ return resp .List , nil
73+ default :
74+ return resp .Items , nil
75+ }
7076}
7177
7278// AssignPolicyToAgent assigns the given Policy to the given Agent.
7379func (c * Client ) AssignPolicyToAgent (ctx context.Context , a Agent , p Policy ) error {
7480 reqBody := `{ "policy_id": "` + p .ID + `" }`
75-
7681 path := fmt .Sprintf ("%s/agents/%s/reassign" , FleetAPI , a .ID )
77- statusCode , respBody , err := c .put (ctx , path , []byte (reqBody ))
82+
83+ var statusCode int
84+ var err error
85+ var respBody []byte
86+ switch {
87+ case c .semver .Major () < 9 :
88+ statusCode , respBody , err = c .put (ctx , path , []byte (reqBody ))
89+ default :
90+ statusCode , respBody , err = c .post (ctx , path , []byte (reqBody ))
91+ }
7892 if err != nil {
7993 return fmt .Errorf ("could not assign policy to agent: %w" , err )
8094 }
0 commit comments