1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package cloudhsmv2 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/cloudhsmv2/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Gets information about AWS CloudHSM clusters. This is a paginated operation, 16// which means that each response might contain only a subset of all the clusters. 17// When the response contains only a subset of clusters, it includes a NextToken 18// value. Use this value in a subsequent DescribeClusters request to get more 19// clusters. When you receive a response with no NextToken (or an empty or null 20// value), that means there are no more clusters to get. 21func (c *Client) DescribeClusters(ctx context.Context, params *DescribeClustersInput, optFns ...func(*Options)) (*DescribeClustersOutput, error) { 22 if params == nil { 23 params = &DescribeClustersInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "DescribeClusters", params, optFns, addOperationDescribeClustersMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*DescribeClustersOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type DescribeClustersInput struct { 37 38 // One or more filters to limit the items returned in the response. Use the 39 // clusterIds filter to return only the specified clusters. Specify clusters by 40 // their cluster identifier (ID). Use the vpcIds filter to return only the clusters 41 // in the specified virtual private clouds (VPCs). Specify VPCs by their VPC 42 // identifier (ID). Use the states filter to return only clusters that match the 43 // specified state. 44 Filters map[string][]string 45 46 // The maximum number of clusters to return in the response. When there are more 47 // clusters than the number you specify, the response contains a NextToken value. 48 MaxResults *int32 49 50 // The NextToken value that you received in the previous response. Use this value 51 // to get more clusters. 52 NextToken *string 53} 54 55type DescribeClustersOutput struct { 56 57 // A list of clusters. 58 Clusters []types.Cluster 59 60 // An opaque string that indicates that the response contains only a subset of 61 // clusters. Use this value in a subsequent DescribeClusters request to get more 62 // clusters. 63 NextToken *string 64 65 // Metadata pertaining to the operation's result. 66 ResultMetadata middleware.Metadata 67} 68 69func addOperationDescribeClustersMiddlewares(stack *middleware.Stack, options Options) (err error) { 70 err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeClusters{}, middleware.After) 71 if err != nil { 72 return err 73 } 74 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeClusters{}, 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_opDescribeClusters(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// DescribeClustersAPIClient is a client that implements the DescribeClusters 130// operation. 131type DescribeClustersAPIClient interface { 132 DescribeClusters(context.Context, *DescribeClustersInput, ...func(*Options)) (*DescribeClustersOutput, error) 133} 134 135var _ DescribeClustersAPIClient = (*Client)(nil) 136 137// DescribeClustersPaginatorOptions is the paginator options for DescribeClusters 138type DescribeClustersPaginatorOptions struct { 139 // The maximum number of clusters to return in the response. When there are more 140 // clusters than the number you specify, the response contains a NextToken value. 141 Limit int32 142 143 // Set to true if pagination should stop if the service returns a pagination token 144 // that matches the most recent token provided to the service. 145 StopOnDuplicateToken bool 146} 147 148// DescribeClustersPaginator is a paginator for DescribeClusters 149type DescribeClustersPaginator struct { 150 options DescribeClustersPaginatorOptions 151 client DescribeClustersAPIClient 152 params *DescribeClustersInput 153 nextToken *string 154 firstPage bool 155} 156 157// NewDescribeClustersPaginator returns a new DescribeClustersPaginator 158func NewDescribeClustersPaginator(client DescribeClustersAPIClient, params *DescribeClustersInput, optFns ...func(*DescribeClustersPaginatorOptions)) *DescribeClustersPaginator { 159 if params == nil { 160 params = &DescribeClustersInput{} 161 } 162 163 options := DescribeClustersPaginatorOptions{} 164 if params.MaxResults != nil { 165 options.Limit = *params.MaxResults 166 } 167 168 for _, fn := range optFns { 169 fn(&options) 170 } 171 172 return &DescribeClustersPaginator{ 173 options: options, 174 client: client, 175 params: params, 176 firstPage: true, 177 } 178} 179 180// HasMorePages returns a boolean indicating whether more pages are available 181func (p *DescribeClustersPaginator) HasMorePages() bool { 182 return p.firstPage || p.nextToken != nil 183} 184 185// NextPage retrieves the next DescribeClusters page. 186func (p *DescribeClustersPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeClustersOutput, error) { 187 if !p.HasMorePages() { 188 return nil, fmt.Errorf("no more pages available") 189 } 190 191 params := *p.params 192 params.NextToken = p.nextToken 193 194 var limit *int32 195 if p.options.Limit > 0 { 196 limit = &p.options.Limit 197 } 198 params.MaxResults = limit 199 200 result, err := p.client.DescribeClusters(ctx, ¶ms, optFns...) 201 if err != nil { 202 return nil, err 203 } 204 p.firstPage = false 205 206 prevToken := p.nextToken 207 p.nextToken = result.NextToken 208 209 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 210 p.nextToken = nil 211 } 212 213 return result, nil 214} 215 216func newServiceMetadataMiddleware_opDescribeClusters(region string) *awsmiddleware.RegisterServiceMetadata { 217 return &awsmiddleware.RegisterServiceMetadata{ 218 Region: region, 219 ServiceID: ServiceID, 220 SigningName: "cloudhsm", 221 OperationName: "DescribeClusters", 222 } 223} 224