1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package greengrassv2 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/greengrassv2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Retrieves a paginated list of deployments. 16func (c *Client) ListDeployments(ctx context.Context, params *ListDeploymentsInput, optFns ...func(*Options)) (*ListDeploymentsOutput, error) { 17 if params == nil { 18 params = &ListDeploymentsInput{} 19 } 20 21 result, metadata, err := c.invokeOperation(ctx, "ListDeployments", params, optFns, addOperationListDeploymentsMiddlewares) 22 if err != nil { 23 return nil, err 24 } 25 26 out := result.(*ListDeploymentsOutput) 27 out.ResultMetadata = metadata 28 return out, nil 29} 30 31type ListDeploymentsInput struct { 32 33 // The filter for the list of deployments. Choose one of the following options: 34 // 35 // * 36 // ALL – The list includes all deployments. 37 // 38 // * LATEST_ONLY – The list includes only 39 // the latest revision of each deployment. 40 // 41 // Default: LATEST_ONLY 42 HistoryFilter types.DeploymentHistoryFilter 43 44 // The maximum number of results to be returned per paginated request. 45 MaxResults int32 46 47 // The token to be used for the next set of paginated results. 48 NextToken *string 49 50 // The ARN 51 // (https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html) of 52 // the target AWS IoT thing or thing group. 53 TargetArn *string 54} 55 56type ListDeploymentsOutput struct { 57 58 // A list that summarizes each deployment. 59 Deployments []types.Deployment 60 61 // The token for the next set of results, or null if there are no additional 62 // results. 63 NextToken *string 64 65 // Metadata pertaining to the operation's result. 66 ResultMetadata middleware.Metadata 67} 68 69func addOperationListDeploymentsMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsRestjson1_serializeOpListDeployments{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsRestjson1_deserializeOpListDeployments{}, middleware.After) 75 if err != nil { 76 return err 77 } 78 if err = addSetLoggerMiddleware(stack, options); err != nil { 79 return err 80 } 81 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 82 return err 83 } 84 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 85 return err 86 } 87 if err = addResolveEndpointMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 91 return err 92 } 93 if err = addRetryMiddlewares(stack, options); err != nil { 94 return err 95 } 96 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 97 return err 98 } 99 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 100 return err 101 } 102 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 103 return err 104 } 105 if err = addClientUserAgent(stack); err != nil { 106 return err 107 } 108 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 109 return err 110 } 111 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 112 return err 113 } 114 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opListDeployments(options.Region), middleware.Before); err != nil { 115 return err 116 } 117 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 118 return err 119 } 120 if err = addResponseErrorMiddleware(stack); err != nil { 121 return err 122 } 123 if err = addRequestResponseLogging(stack, options); err != nil { 124 return err 125 } 126 return nil 127} 128 129// ListDeploymentsAPIClient is a client that implements the ListDeployments 130// operation. 131type ListDeploymentsAPIClient interface { 132 ListDeployments(context.Context, *ListDeploymentsInput, ...func(*Options)) (*ListDeploymentsOutput, error) 133} 134 135var _ ListDeploymentsAPIClient = (*Client)(nil) 136 137// ListDeploymentsPaginatorOptions is the paginator options for ListDeployments 138type ListDeploymentsPaginatorOptions struct { 139 // The maximum number of results to be returned per paginated request. 140 Limit int32 141 142 // Set to true if pagination should stop if the service returns a pagination token 143 // that matches the most recent token provided to the service. 144 StopOnDuplicateToken bool 145} 146 147// ListDeploymentsPaginator is a paginator for ListDeployments 148type ListDeploymentsPaginator struct { 149 options ListDeploymentsPaginatorOptions 150 client ListDeploymentsAPIClient 151 params *ListDeploymentsInput 152 nextToken *string 153 firstPage bool 154} 155 156// NewListDeploymentsPaginator returns a new ListDeploymentsPaginator 157func NewListDeploymentsPaginator(client ListDeploymentsAPIClient, params *ListDeploymentsInput, optFns ...func(*ListDeploymentsPaginatorOptions)) *ListDeploymentsPaginator { 158 options := ListDeploymentsPaginatorOptions{} 159 if params.MaxResults != 0 { 160 options.Limit = params.MaxResults 161 } 162 163 for _, fn := range optFns { 164 fn(&options) 165 } 166 167 if params == nil { 168 params = &ListDeploymentsInput{} 169 } 170 171 return &ListDeploymentsPaginator{ 172 options: options, 173 client: client, 174 params: params, 175 firstPage: true, 176 } 177} 178 179// HasMorePages returns a boolean indicating whether more pages are available 180func (p *ListDeploymentsPaginator) HasMorePages() bool { 181 return p.firstPage || p.nextToken != nil 182} 183 184// NextPage retrieves the next ListDeployments page. 185func (p *ListDeploymentsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*ListDeploymentsOutput, error) { 186 if !p.HasMorePages() { 187 return nil, fmt.Errorf("no more pages available") 188 } 189 190 params := *p.params 191 params.NextToken = p.nextToken 192 193 params.MaxResults = p.options.Limit 194 195 result, err := p.client.ListDeployments(ctx, ¶ms, optFns...) 196 if err != nil { 197 return nil, err 198 } 199 p.firstPage = false 200 201 prevToken := p.nextToken 202 p.nextToken = result.NextToken 203 204 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 205 p.nextToken = nil 206 } 207 208 return result, nil 209} 210 211func newServiceMetadataMiddleware_opListDeployments(region string) *awsmiddleware.RegisterServiceMetadata { 212 return &awsmiddleware.RegisterServiceMetadata{ 213 Region: region, 214 ServiceID: ServiceID, 215 SigningName: "greengrass", 216 OperationName: "ListDeployments", 217 } 218} 219