1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package robomaker
4
5import (
6	"context"
7	"fmt"
8	awsmiddleware "github.com/aws/aws-sdk-go-v2/aws/middleware"
9	"github.com/aws/aws-sdk-go-v2/aws/signer/v4"
10	"github.com/aws/aws-sdk-go-v2/service/robomaker/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Returns a list of deployment jobs for a fleet. You can optionally provide
16// filters to retrieve specific deployment jobs.
17func (c *Client) ListDeploymentJobs(ctx context.Context, params *ListDeploymentJobsInput, optFns ...func(*Options)) (*ListDeploymentJobsOutput, error) {
18	if params == nil {
19		params = &ListDeploymentJobsInput{}
20	}
21
22	result, metadata, err := c.invokeOperation(ctx, "ListDeploymentJobs", params, optFns, addOperationListDeploymentJobsMiddlewares)
23	if err != nil {
24		return nil, err
25	}
26
27	out := result.(*ListDeploymentJobsOutput)
28	out.ResultMetadata = metadata
29	return out, nil
30}
31
32type ListDeploymentJobsInput struct {
33
34	// Optional filters to limit results. The filter names status and fleetName are
35	// supported. When filtering, you must use the complete value of the filtered item.
36	// You can use up to three filters, but they must be for the same named item. For
37	// example, if you are looking for items with the status InProgress or the status
38	// Pending.
39	Filters []types.Filter
40
41	// When this parameter is used, ListDeploymentJobs only returns maxResults results
42	// in a single page along with a nextToken response element. The remaining results
43	// of the initial request can be seen by sending another ListDeploymentJobs request
44	// with the returned nextToken value. This value can be between 1 and 200. If this
45	// parameter is not used, then ListDeploymentJobs returns up to 200 results and a
46	// nextToken value if applicable.
47	MaxResults *int32
48
49	// If the previous paginated request did not return all of the remaining results,
50	// the response object's nextToken parameter value is set to a token. To retrieve
51	// the next set of results, call ListDeploymentJobs again and assign that token to
52	// the request object's nextToken parameter. If there are no remaining results, the
53	// previous response object's NextToken parameter is set to null.
54	NextToken *string
55}
56
57type ListDeploymentJobsOutput struct {
58
59	// A list of deployment jobs that meet the criteria of the request.
60	DeploymentJobs []types.DeploymentJob
61
62	// If the previous paginated request did not return all of the remaining results,
63	// the response object's nextToken parameter value is set to a token. To retrieve
64	// the next set of results, call ListDeploymentJobs again and assign that token to
65	// the request object's nextToken parameter. If there are no remaining results, the
66	// previous response object's NextToken parameter is set to null.
67	NextToken *string
68
69	// Metadata pertaining to the operation's result.
70	ResultMetadata middleware.Metadata
71}
72
73func addOperationListDeploymentJobsMiddlewares(stack *middleware.Stack, options Options) (err error) {
74	err = stack.Serialize.Add(&awsRestjson1_serializeOpListDeploymentJobs{}, middleware.After)
75	if err != nil {
76		return err
77	}
78	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListDeploymentJobs{}, middleware.After)
79	if err != nil {
80		return err
81	}
82	if err = addSetLoggerMiddleware(stack, options); err != nil {
83		return err
84	}
85	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
86		return err
87	}
88	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
89		return err
90	}
91	if err = addResolveEndpointMiddleware(stack, options); err != nil {
92		return err
93	}
94	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
95		return err
96	}
97	if err = addRetryMiddlewares(stack, options); err != nil {
98		return err
99	}
100	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
101		return err
102	}
103	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
104		return err
105	}
106	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
107		return err
108	}
109	if err = addClientUserAgent(stack); err != nil {
110		return err
111	}
112	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
113		return err
114	}
115	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
116		return err
117	}
118	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDeploymentJobs(options.Region), middleware.Before); err != nil {
119		return err
120	}
121	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
122		return err
123	}
124	if err = addResponseErrorMiddleware(stack); err != nil {
125		return err
126	}
127	if err = addRequestResponseLogging(stack, options); err != nil {
128		return err
129	}
130	return nil
131}
132
133// ListDeploymentJobsAPIClient is a client that implements the ListDeploymentJobs
134// operation.
135type ListDeploymentJobsAPIClient interface {
136	ListDeploymentJobs(context.Context, *ListDeploymentJobsInput, ...func(*Options)) (*ListDeploymentJobsOutput, error)
137}
138
139var _ ListDeploymentJobsAPIClient = (*Client)(nil)
140
141// ListDeploymentJobsPaginatorOptions is the paginator options for
142// ListDeploymentJobs
143type ListDeploymentJobsPaginatorOptions struct {
144	// When this parameter is used, ListDeploymentJobs only returns maxResults results
145	// in a single page along with a nextToken response element. The remaining results
146	// of the initial request can be seen by sending another ListDeploymentJobs request
147	// with the returned nextToken value. This value can be between 1 and 200. If this
148	// parameter is not used, then ListDeploymentJobs returns up to 200 results and a
149	// nextToken value if applicable.
150	Limit int32
151
152	// Set to true if pagination should stop if the service returns a pagination token
153	// that matches the most recent token provided to the service.
154	StopOnDuplicateToken bool
155}
156
157// ListDeploymentJobsPaginator is a paginator for ListDeploymentJobs
158type ListDeploymentJobsPaginator struct {
159	options   ListDeploymentJobsPaginatorOptions
160	client    ListDeploymentJobsAPIClient
161	params    *ListDeploymentJobsInput
162	nextToken *string
163	firstPage bool
164}
165
166// NewListDeploymentJobsPaginator returns a new ListDeploymentJobsPaginator
167func NewListDeploymentJobsPaginator(client ListDeploymentJobsAPIClient, params *ListDeploymentJobsInput, optFns ...func(*ListDeploymentJobsPaginatorOptions)) *ListDeploymentJobsPaginator {
168	if params == nil {
169		params = &ListDeploymentJobsInput{}
170	}
171
172	options := ListDeploymentJobsPaginatorOptions{}
173	if params.MaxResults != nil {
174		options.Limit = *params.MaxResults
175	}
176
177	for _, fn := range optFns {
178		fn(&options)
179	}
180
181	return &ListDeploymentJobsPaginator{
182		options:   options,
183		client:    client,
184		params:    params,
185		firstPage: true,
186	}
187}
188
189// HasMorePages returns a boolean indicating whether more pages are available
190func (p *ListDeploymentJobsPaginator) HasMorePages() bool {
191	return p.firstPage || p.nextToken != nil
192}
193
194// NextPage retrieves the next ListDeploymentJobs page.
195func (p *ListDeploymentJobsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDeploymentJobsOutput, error) {
196	if !p.HasMorePages() {
197		return nil, fmt.Errorf("no more pages available")
198	}
199
200	params := *p.params
201	params.NextToken = p.nextToken
202
203	var limit *int32
204	if p.options.Limit > 0 {
205		limit = &p.options.Limit
206	}
207	params.MaxResults = limit
208
209	result, err := p.client.ListDeploymentJobs(ctx, &params, optFns...)
210	if err != nil {
211		return nil, err
212	}
213	p.firstPage = false
214
215	prevToken := p.nextToken
216	p.nextToken = result.NextToken
217
218	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
219		p.nextToken = nil
220	}
221
222	return result, nil
223}
224
225func newServiceMetadataMiddleware_opListDeploymentJobs(region string) *awsmiddleware.RegisterServiceMetadata {
226	return &awsmiddleware.RegisterServiceMetadata{
227		Region:        region,
228		ServiceID:     ServiceID,
229		SigningName:   "robomaker",
230		OperationName: "ListDeploymentJobs",
231	}
232}
233