1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package iot
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/iot/types"
11	"github.com/aws/smithy-go/middleware"
12	smithyhttp "github.com/aws/smithy-go/transport/http"
13)
14
15// Lists OTA updates.
16func (c *Client) ListOTAUpdates(ctx context.Context, params *ListOTAUpdatesInput, optFns ...func(*Options)) (*ListOTAUpdatesOutput, error) {
17	if params == nil {
18		params = &ListOTAUpdatesInput{}
19	}
20
21	result, metadata, err := c.invokeOperation(ctx, "ListOTAUpdates", params, optFns, addOperationListOTAUpdatesMiddlewares)
22	if err != nil {
23		return nil, err
24	}
25
26	out := result.(*ListOTAUpdatesOutput)
27	out.ResultMetadata = metadata
28	return out, nil
29}
30
31type ListOTAUpdatesInput struct {
32
33	// The maximum number of results to return at one time.
34	MaxResults *int32
35
36	// A token used to retrieve the next set of results.
37	NextToken *string
38
39	// The OTA update job status.
40	OtaUpdateStatus types.OTAUpdateStatus
41}
42
43type ListOTAUpdatesOutput struct {
44
45	// A token to use to get the next set of results.
46	NextToken *string
47
48	// A list of OTA update jobs.
49	OtaUpdates []types.OTAUpdateSummary
50
51	// Metadata pertaining to the operation's result.
52	ResultMetadata middleware.Metadata
53}
54
55func addOperationListOTAUpdatesMiddlewares(stack *middleware.Stack, options Options) (err error) {
56	err = stack.Serialize.Add(&awsRestjson1_serializeOpListOTAUpdates{}, middleware.After)
57	if err != nil {
58		return err
59	}
60	err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListOTAUpdates{}, middleware.After)
61	if err != nil {
62		return err
63	}
64	if err = addSetLoggerMiddleware(stack, options); err != nil {
65		return err
66	}
67	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
68		return err
69	}
70	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
71		return err
72	}
73	if err = addResolveEndpointMiddleware(stack, options); err != nil {
74		return err
75	}
76	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
77		return err
78	}
79	if err = addRetryMiddlewares(stack, options); err != nil {
80		return err
81	}
82	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
83		return err
84	}
85	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
86		return err
87	}
88	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
89		return err
90	}
91	if err = addClientUserAgent(stack); err != nil {
92		return err
93	}
94	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
95		return err
96	}
97	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
98		return err
99	}
100	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListOTAUpdates(options.Region), middleware.Before); err != nil {
101		return err
102	}
103	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
104		return err
105	}
106	if err = addResponseErrorMiddleware(stack); err != nil {
107		return err
108	}
109	if err = addRequestResponseLogging(stack, options); err != nil {
110		return err
111	}
112	return nil
113}
114
115// ListOTAUpdatesAPIClient is a client that implements the ListOTAUpdates
116// operation.
117type ListOTAUpdatesAPIClient interface {
118	ListOTAUpdates(context.Context, *ListOTAUpdatesInput, ...func(*Options)) (*ListOTAUpdatesOutput, error)
119}
120
121var _ ListOTAUpdatesAPIClient = (*Client)(nil)
122
123// ListOTAUpdatesPaginatorOptions is the paginator options for ListOTAUpdates
124type ListOTAUpdatesPaginatorOptions struct {
125	// The maximum number of results to return at one time.
126	Limit int32
127
128	// Set to true if pagination should stop if the service returns a pagination token
129	// that matches the most recent token provided to the service.
130	StopOnDuplicateToken bool
131}
132
133// ListOTAUpdatesPaginator is a paginator for ListOTAUpdates
134type ListOTAUpdatesPaginator struct {
135	options   ListOTAUpdatesPaginatorOptions
136	client    ListOTAUpdatesAPIClient
137	params    *ListOTAUpdatesInput
138	nextToken *string
139	firstPage bool
140}
141
142// NewListOTAUpdatesPaginator returns a new ListOTAUpdatesPaginator
143func NewListOTAUpdatesPaginator(client ListOTAUpdatesAPIClient, params *ListOTAUpdatesInput, optFns ...func(*ListOTAUpdatesPaginatorOptions)) *ListOTAUpdatesPaginator {
144	if params == nil {
145		params = &ListOTAUpdatesInput{}
146	}
147
148	options := ListOTAUpdatesPaginatorOptions{}
149	if params.MaxResults != nil {
150		options.Limit = *params.MaxResults
151	}
152
153	for _, fn := range optFns {
154		fn(&options)
155	}
156
157	return &ListOTAUpdatesPaginator{
158		options:   options,
159		client:    client,
160		params:    params,
161		firstPage: true,
162	}
163}
164
165// HasMorePages returns a boolean indicating whether more pages are available
166func (p *ListOTAUpdatesPaginator) HasMorePages() bool {
167	return p.firstPage || p.nextToken != nil
168}
169
170// NextPage retrieves the next ListOTAUpdates page.
171func (p *ListOTAUpdatesPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListOTAUpdatesOutput, error) {
172	if !p.HasMorePages() {
173		return nil, fmt.Errorf("no more pages available")
174	}
175
176	params := *p.params
177	params.NextToken = p.nextToken
178
179	var limit *int32
180	if p.options.Limit > 0 {
181		limit = &p.options.Limit
182	}
183	params.MaxResults = limit
184
185	result, err := p.client.ListOTAUpdates(ctx, &params, optFns...)
186	if err != nil {
187		return nil, err
188	}
189	p.firstPage = false
190
191	prevToken := p.nextToken
192	p.nextToken = result.NextToken
193
194	if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken {
195		p.nextToken = nil
196	}
197
198	return result, nil
199}
200
201func newServiceMetadataMiddleware_opListOTAUpdates(region string) *awsmiddleware.RegisterServiceMetadata {
202	return &awsmiddleware.RegisterServiceMetadata{
203		Region:        region,
204		ServiceID:     ServiceID,
205		SigningName:   "execute-api",
206		OperationName: "ListOTAUpdates",
207	}
208}
209