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