@@ -36,6 +36,12 @@ type AgentPools interface {
36
36
// UpdateAllowedWorkspaces updates the list of allowed workspaces associated with an agent pool.
37
37
UpdateAllowedWorkspaces (ctx context.Context , agentPool string , options AgentPoolAllowedWorkspacesUpdateOptions ) (* AgentPool , error )
38
38
39
+ // UpdateAllowedProjects updates the list of allowed projects associated with an agent pool.
40
+ UpdateAllowedProjects (ctx context.Context , agentPool string , options AgentPoolAllowedProjectsUpdateOptions ) (* AgentPool , error )
41
+
42
+ // UpdateExcludedWorkspaces updates the list of excluded workspaces associated with an agent pool.
43
+ UpdateExcludedWorkspaces (ctx context.Context , agentPool string , options AgentPoolExcludedWorkspacesUpdateOptions ) (* AgentPool , error )
44
+
39
45
// Delete an agent pool by its ID.
40
46
Delete (ctx context.Context , agentPoolID string ) error
41
47
}
@@ -60,9 +66,11 @@ type AgentPool struct {
60
66
CreatedAt time.Time `jsonapi:"attr,created-at,iso8601"`
61
67
62
68
// Relations
63
- Organization * Organization `jsonapi:"relation,organization"`
64
- Workspaces []* Workspace `jsonapi:"relation,workspaces"`
65
- AllowedWorkspaces []* Workspace `jsonapi:"relation,allowed-workspaces"`
69
+ Organization * Organization `jsonapi:"relation,organization"`
70
+ Workspaces []* Workspace `jsonapi:"relation,workspaces"`
71
+ AllowedWorkspaces []* Workspace `jsonapi:"relation,allowed-workspaces"`
72
+ AllowedProjects []* Project `jsonapi:"relation,allowed-projects"`
73
+ ExcludedWorkspaces []* Workspace `jsonapi:"relation,excluded-workspaces"`
66
74
}
67
75
68
76
// A list of relations to include
@@ -87,6 +95,9 @@ type AgentPoolListOptions struct {
87
95
88
96
// Optional: String (workspace name) used to filter the results.
89
97
AllowedWorkspacesName string `url:"filter[allowed_workspaces][name],omitempty"`
98
+
99
+ // Optional: String (project name) used to filter the results.
100
+ AllowedProjectsName string `url:"filter[allowed_projects][name],omitempty"`
90
101
}
91
102
92
103
// AgentPoolCreateOptions represents the options for creating an agent pool.
@@ -105,6 +116,12 @@ type AgentPoolCreateOptions struct {
105
116
106
117
// List of workspaces that are associated with an agent pool.
107
118
AllowedWorkspaces []* Workspace `jsonapi:"relation,allowed-workspaces,omitempty"`
119
+
120
+ // List of projects that are associated with an agent pool.
121
+ AllowedProjects []* Project `jsonapi:"relation,allowed-projects,omitempty"`
122
+
123
+ // List of workspaces that are excluded from the scope of an agent pool.
124
+ ExcludedWorkspaces []* Workspace `jsonapi:"relation,excluded-workspaces,omitempty"`
108
125
}
109
126
110
127
// List all the agent pools of the given organization.
@@ -201,9 +218,15 @@ type AgentPoolUpdateOptions struct {
201
218
202
219
// A new list of workspaces that are associated with an agent pool.
203
220
AllowedWorkspaces []* Workspace `jsonapi:"relation,allowed-workspaces,omitempty"`
221
+
222
+ // A new list of projects that are associated with an agent pool.
223
+ AllowedProjects []* Project `jsonapi:"relation,allowed-projects,omitempty"`
224
+
225
+ // A new list of workspaces that are excluded from the scope of an agent pool.
226
+ ExcludedWorkspaces []* Workspace `jsonapi:"relation,excluded-workspaces,omitempty"`
204
227
}
205
228
206
- // AgentPoolUpdateAllowedWorkspacesOptions represents the options for updating the allowed workspace on an agent pool
229
+ // AgentPoolAllowedWorkspacesUpdateOptions represents the options for updating the allowed workspace on an agent pool
207
230
type AgentPoolAllowedWorkspacesUpdateOptions struct {
208
231
// Type is a public field utilized by JSON:API to
209
232
// set the resource type via the field tag.
@@ -215,8 +238,33 @@ type AgentPoolAllowedWorkspacesUpdateOptions struct {
215
238
AllowedWorkspaces []* Workspace `jsonapi:"relation,allowed-workspaces"`
216
239
}
217
240
241
+ // AgentPoolAllowedProjectsUpdateOptions represents the options for updating the allowed projects on an agent pool
242
+ type AgentPoolAllowedProjectsUpdateOptions struct {
243
+ // Type is a public field utilized by JSON:API to
244
+ // set the resource type via the field tag.
245
+ // It is not a user-defined value and does not need to be set.
246
+ // https://jsonapi.org/format/#crud-creating
247
+ Type string `jsonapi:"primary,agent-pools"`
248
+
249
+ // A new list of projects that are associated with an agent pool.
250
+ AllowedProjects []* Project `jsonapi:"relation,allowed-projects"`
251
+ }
252
+
253
+ // AgentPoolExcludedWorkspacesUpdateOptions represents the options for updating the excluded workspace on an agent pool
254
+ type AgentPoolExcludedWorkspacesUpdateOptions struct {
255
+ // Type is a public field utilized by JSON:API to
256
+ // set the resource type via the field tag.
257
+ // It is not a user-defined value and does not need to be set.
258
+ // https://jsonapi.org/format/#crud-creating
259
+ Type string `jsonapi:"primary,agent-pools"`
260
+
261
+ // A new list of workspaces that are excluded from the scope of an agent pool.
262
+ ExcludedWorkspaces []* Workspace `jsonapi:"relation,excluded-workspaces"`
263
+ }
264
+
218
265
// Update an agent pool by its ID.
219
- // **Note:** This method cannot be used to clear the allowed workspaces field, instead use UpdateAllowedWorkspaces
266
+ // **Note:** This method cannot be used to clear the allowed workspaces, allowed projects, or excluded workspaces fields.
267
+ // instead use UpdateAllowedWorkspaces, UpdateAllowedProjects, or UpdateExcludedWorkspaces methods respectively.
220
268
func (s * agentPools ) Update (ctx context.Context , agentPoolID string , options AgentPoolUpdateOptions ) (* AgentPool , error ) {
221
269
if ! validStringID (& agentPoolID ) {
222
270
return nil , ErrInvalidAgentPoolID
@@ -242,23 +290,15 @@ func (s *agentPools) Update(ctx context.Context, agentPoolID string, options Age
242
290
}
243
291
244
292
func (s * agentPools ) UpdateAllowedWorkspaces (ctx context.Context , agentPoolID string , options AgentPoolAllowedWorkspacesUpdateOptions ) (* AgentPool , error ) {
245
- if ! validStringID (& agentPoolID ) {
246
- return nil , ErrInvalidAgentPoolID
247
- }
248
-
249
- u := fmt .Sprintf ("agent-pools/%s" , url .PathEscape (agentPoolID ))
250
- req , err := s .client .NewRequest ("PATCH" , u , & options )
251
- if err != nil {
252
- return nil , err
253
- }
293
+ return s .updateArrayAttribute (ctx , agentPoolID , & options )
294
+ }
254
295
255
- k := & AgentPool {}
256
- err = req .Do (ctx , k )
257
- if err != nil {
258
- return nil , err
259
- }
296
+ func (s * agentPools ) UpdateAllowedProjects (ctx context.Context , agentPoolID string , options AgentPoolAllowedProjectsUpdateOptions ) (* AgentPool , error ) {
297
+ return s .updateArrayAttribute (ctx , agentPoolID , & options )
298
+ }
260
299
261
- return k , nil
300
+ func (s * agentPools ) UpdateExcludedWorkspaces (ctx context.Context , agentPoolID string , options AgentPoolExcludedWorkspacesUpdateOptions ) (* AgentPool , error ) {
301
+ return s .updateArrayAttribute (ctx , agentPoolID , & options )
262
302
}
263
303
264
304
// Delete an agent pool by its ID.
@@ -276,6 +316,30 @@ func (s *agentPools) Delete(ctx context.Context, agentPoolID string) error {
276
316
return req .Do (ctx , nil )
277
317
}
278
318
319
+ // updateArrayAttribute is a helper function to update array attributes of an agent pool, such as allowed workspaces, allowed projects, or excluded workspaces.
320
+ // Note: This function does not validate the options parameter, so it should be used with caution. It is intended to be used with options structs
321
+ // (e.g. AgentPoolAllowedWorkspacesUpdateOptions, AgentPoolAllowedProjectsUpdateOptions, AgentPoolExcludedWorkspacesUpdateOptions) whose array
322
+ // attributes are NOT marked `omitempty`, so that an empty array is sent to the API to clear the existing values.
323
+ func (s * agentPools ) updateArrayAttribute (ctx context.Context , agentPoolID string , options any ) (* AgentPool , error ) {
324
+ if ! validStringID (& agentPoolID ) {
325
+ return nil , ErrInvalidAgentPoolID
326
+ }
327
+
328
+ u := fmt .Sprintf ("agent-pools/%s" , url .PathEscape (agentPoolID ))
329
+ req , err := s .client .NewRequest ("PATCH" , u , options )
330
+ if err != nil {
331
+ return nil , err
332
+ }
333
+
334
+ k := & AgentPool {}
335
+ err = req .Do (ctx , k )
336
+ if err != nil {
337
+ return nil , err
338
+ }
339
+
340
+ return k , nil
341
+ }
342
+
279
343
func (o AgentPoolCreateOptions ) valid () error {
280
344
if ! validString (o .Name ) {
281
345
return ErrRequiredName
0 commit comments