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