@@ -26,6 +26,9 @@ type Stacks interface {
26
26
// Update updates a stack.
27
27
Update (ctx context.Context , stackID string , options StackUpdateOptions ) (* Stack , error )
28
28
29
+ // Update updates the agent pool in use by a stack.
30
+ UpdateAgentPool (ctx context.Context , stackID string , agentPoolID string ) (* Stack , error )
31
+
29
32
// Delete deletes a stack.
30
33
Delete (ctx context.Context , stackID string ) error
31
34
@@ -34,7 +37,14 @@ type Stacks interface {
34
37
35
38
// FetchLatestFromVcs updates the configuration of a stack, triggering stack preparation.
36
39
FetchLatestFromVcs (ctx context.Context , stackID string ) (* Stack , error )
37
- }
40
+
41
+ // ListDeployments returns a list of deployments for the given stack.
42
+ ListDeployments (ctx context.Context , stackID string , options * StackListDeploymentsOptions ) (* StackDeploymentList , error )
43
+
44
+ // ListDeploymentRunsForDeployment returns a list of deployments for the given
45
+ // stack and deployment.
46
+ ListDeploymentRunsForDeployment (ctx context.Context , stackID string , deployment string , options * StackListDeploymentRunsForDeploymentOptions ) (* StackDeploymentRunList , error )
47
+
38
48
39
49
// stacks implements Stacks.
40
50
type stacks struct {
@@ -86,6 +96,7 @@ type StackVCSRepoOptions struct {
86
96
// Stack represents a stack.
87
97
type Stack struct {
88
98
ID string `jsonapi:"primary,stacks"`
99
+
89
100
Name string `jsonapi:"attr,name"`
90
101
Description string `jsonapi:"attr,description"`
91
102
VCSRepo * StackVCSRepo `jsonapi:"attr,vcs-repo"`
@@ -138,23 +149,6 @@ type StackConfiguration struct {
138
149
IngressAttributes * IngressAttributes `jsonapi:"relation,ingress-attributes"`
139
150
}
140
151
141
- // StackState represents a stack state
142
- type StackState struct {
143
- // Attributes
144
- ID string `jsonapi:"primary,stack-states"`
145
- Description string `jsonapi:"attr,description"`
146
- Generation int `jsonapi:"attr,generation"`
147
- Status string `jsonapi:"attr,status"`
148
- Deployment string `jsonapi:"attr,deployment"`
149
- Components string `jsonapi:"attr,components"`
150
- IsCurrent bool `jsonapi:"attr,is-current"`
151
- ResourceInstanceCount int `jsonapi:"attr,resource-instance-count"`
152
-
153
- // Relationships
154
- Stack * Stack `jsonapi:"relation,stack"`
155
- StackDeploymentRun * StackDeploymentRun `jsonapi:"relation,stack-deployment-run"`
156
- }
157
-
158
152
// StackListOptions represents the options for listing stacks.
159
153
type StackListOptions struct {
160
154
ListOptions
@@ -163,6 +157,10 @@ type StackListOptions struct {
163
157
SearchByName string `url:"search[name],omitempty"`
164
158
}
165
159
160
+ func (s * StackListOptions ) valid () error {
161
+ return nil
162
+ }
163
+
166
164
// StackCreateOptions represents the options for creating a stack. The project
167
165
// relation is required.
168
166
type StackCreateOptions struct {
@@ -174,6 +172,18 @@ type StackCreateOptions struct {
174
172
AgentPool * AgentPool `jsonapi:"relation,agent-pool"`
175
173
}
176
174
175
+ func (s StackCreateOptions ) valid () error {
176
+ if s .Name == "" {
177
+ return ErrRequiredName
178
+ }
179
+
180
+ if s .Project .ID == "" {
181
+ return ErrRequiredProject
182
+ }
183
+
184
+ return nil
185
+ }
186
+
177
187
// StackUpdateOptions represents the options for updating a stack.
178
188
type StackUpdateOptions struct {
179
189
Name * string `jsonapi:"attr,name,omitempty"`
@@ -286,6 +296,27 @@ func (s stacks) Update(ctx context.Context, stackID string, options StackUpdateO
286
296
return stack , nil
287
297
}
288
298
299
+ // UpdateAgentPool updates the agent pool in use by a stack.
300
+ func (s stacks ) UpdateAgentPool (ctx context.Context , stackID string , agentPoolID string ) (* Stack , error ) {
301
+ options := StackUpdateOptions {
302
+ AgentPool : & AgentPool {
303
+ ID : agentPoolID ,
304
+ },
305
+ }
306
+
307
+ req , err := s .client .NewRequest ("PATCH" , fmt .Sprintf ("stacks/%s" , url .PathEscape (stackID )), & options )
308
+ if err != nil {
309
+ return nil , err
310
+ }
311
+
312
+ stack := & Stack {}
313
+ if err = req .Do (ctx , stack ); err != nil {
314
+ return nil , err
315
+ }
316
+
317
+ return stack , nil
318
+ }
319
+
289
320
// Delete deletes a stack.
290
321
func (s stacks ) Delete (ctx context.Context , stackID string ) error {
291
322
req , err := s .client .NewRequest ("DELETE" , fmt .Sprintf ("stacks/%s" , url .PathEscape (stackID )), nil )
@@ -306,22 +337,81 @@ func (s stacks) ForceDelete(ctx context.Context, stackID string) error {
306
337
return req .Do (ctx , nil )
307
338
}
308
339
309
- func (s * StackListOptions ) valid () error {
340
+ // StackListDeploymentsOptions represents the options for listing stack
341
+ // deployments.
342
+ type StackListDeploymentsOptions struct {
343
+ ListOptions
344
+ }
345
+
346
+ // valid validates the StackListDeploymentsOptions values.
347
+ func (s * StackListDeploymentsOptions ) valid () error {
310
348
return nil
311
349
}
312
350
313
- func (s StackCreateOptions ) valid () error {
314
- if s .Name == "" {
315
- return ErrRequiredName
351
+ // StackDeploymentList represents a list of stack deployments.
352
+ type StackDeploymentList struct {
353
+ * Pagination
354
+ Items []* StackDeployment
355
+ }
356
+
357
+ // StackDeployment represents a stack deployment.
358
+ type StackDeployment struct {
359
+ // Attributes
360
+ ID string `jsonapi:"primary,stack-states"`
361
+ Name string `jsonapi:"attr,name"`
362
+
363
+ // Relationships
364
+ Stack * Stack `jsonapi:"relation,stack"`
365
+ LatestDeploymentRun * StackDeploymentRun `jsonapi:"relation,latest-deployment-run"`
366
+ }
367
+
368
+ // ListDeployments returns a list of deployments for the given stack.
369
+ func (s stacks ) ListDeployments (ctx context.Context , stackID string , options * StackListDeploymentsOptions ) (* StackDeploymentList , error ) {
370
+ if err := options .valid (); err != nil {
371
+ return nil , err
316
372
}
317
373
318
- if s .Project .ID == "" {
319
- return ErrRequiredProject
374
+ req , err := s .client .NewRequest ("GET" , fmt .Sprintf ("stacks/%s/deployments" , url .PathEscape (stackID )), options )
375
+ if err != nil {
376
+ return nil , err
320
377
}
321
378
379
+ sdl := & StackDeploymentList {}
380
+ if err = req .Do (ctx , sdl ); err != nil {
381
+ return nil , err
382
+ }
383
+
384
+ return sdl , nil
385
+ }
386
+
387
+ type StackListDeploymentRunsForDeploymentOptions struct {
388
+ ListOptions
389
+ }
390
+
391
+ func (s * StackListDeploymentRunsForDeploymentOptions ) valid () error {
322
392
return nil
323
393
}
324
394
395
+ // ListDeploymentRunsForDeployment returns a list of deployment runs for the
396
+ // given stack and deployment.
397
+ func (s stacks ) ListDeploymentRunsForDeployment (ctx context.Context , stackID , deployment string , options * StackListDeploymentRunsForDeploymentOptions ) (* StackDeploymentRunList , error ) {
398
+ if err := options .valid (); err != nil {
399
+ return nil , err
400
+ }
401
+
402
+ req , err := s .client .NewRequest ("GET" , fmt .Sprintf ("stacks/%s/stack-deployments/%s/stack-deployment-runs" , url .PathEscape (stackID ), url .PathEscape (deployment )), options )
403
+ if err != nil {
404
+ return nil , err
405
+ }
406
+
407
+ sdl := & StackDeploymentRunList {}
408
+ if err := req .Do (ctx , sdl ); err != nil {
409
+ return nil , err
410
+ }
411
+
412
+ return sdl , nil
413
+ }
414
+
325
415
// awaitPoll is a helper function that uses a callback to read a status, then
326
416
// waits for a terminal status or an error. The callback should return the
327
417
// current status, or an error. For each time the status changes, the channel
0 commit comments