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 backups of AWS CloudHSM clusters. This is a paginated 16// operation, which means that each response might contain only a subset of all the 17// backups. When the response contains only a subset of backups, it includes a 18// NextToken value. Use this value in a subsequent DescribeBackups request to get 19// more backups. When you receive a response with no NextToken (or an empty or null 20// value), that means there are no more backups to get. 21func (c *Client) DescribeBackups(ctx context.Context, params *DescribeBackupsInput, optFns ...func(*Options)) (*DescribeBackupsOutput, error) { 22 if params == nil { 23 params = &DescribeBackupsInput{} 24 } 25 26 result, metadata, err := c.invokeOperation(ctx, "DescribeBackups", params, optFns, addOperationDescribeBackupsMiddlewares) 27 if err != nil { 28 return nil, err 29 } 30 31 out := result.(*DescribeBackupsOutput) 32 out.ResultMetadata = metadata 33 return out, nil 34} 35 36type DescribeBackupsInput struct { 37 38 // One or more filters to limit the items returned in the response. Use the 39 // backupIds filter to return only the specified backups. Specify backups by their 40 // backup identifier (ID). Use the sourceBackupIds filter to return only the 41 // backups created from a source backup. The sourceBackupID of a source backup is 42 // returned by the CopyBackupToRegion operation. Use the clusterIds filter to 43 // return only the backups for the specified clusters. Specify clusters by their 44 // cluster identifier (ID). Use the states filter to return only backups that match 45 // the specified state. Use the neverExpires filter to return backups filtered by 46 // the value in the neverExpires parameter. True returns all backups exempt from 47 // the backup retention policy. False returns all backups with a backup retention 48 // policy defined at the cluster. 49 Filters map[string][]string 50 51 // The maximum number of backups to return in the response. When there are more 52 // backups than the number you specify, the response contains a NextToken value. 53 MaxResults *int32 54 55 // The NextToken value that you received in the previous response. Use this value 56 // to get more backups. 57 NextToken *string 58 59 // Designates whether or not to sort the return backups by ascending chronological 60 // order of generation. 61 SortAscending *bool 62} 63 64type DescribeBackupsOutput struct { 65 66 // A list of backups. 67 Backups []types.Backup 68 69 // An opaque string that indicates that the response contains only a subset of 70 // backups. Use this value in a subsequent DescribeBackups request to get more 71 // backups. 72 NextToken *string 73 74 // Metadata pertaining to the operation's result. 75 ResultMetadata middleware.Metadata 76} 77 78func addOperationDescribeBackupsMiddlewares(stack *middleware.Stack, options Options) (err error) { 79 err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeBackups{}, middleware.After) 80 if err != nil { 81 return err 82 } 83 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeBackups{}, middleware.After) 84 if err != nil { 85 return err 86 } 87 if err = addSetLoggerMiddleware(stack, options); err != nil { 88 return err 89 } 90 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 91 return err 92 } 93 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 94 return err 95 } 96 if err = addResolveEndpointMiddleware(stack, options); err != nil { 97 return err 98 } 99 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 100 return err 101 } 102 if err = addRetryMiddlewares(stack, options); err != nil { 103 return err 104 } 105 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 106 return err 107 } 108 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 109 return err 110 } 111 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 112 return err 113 } 114 if err = addClientUserAgent(stack); err != nil { 115 return err 116 } 117 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 118 return err 119 } 120 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 121 return err 122 } 123 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeBackups(options.Region), middleware.Before); err != nil { 124 return err 125 } 126 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 127 return err 128 } 129 if err = addResponseErrorMiddleware(stack); err != nil { 130 return err 131 } 132 if err = addRequestResponseLogging(stack, options); err != nil { 133 return err 134 } 135 return nil 136} 137 138// DescribeBackupsAPIClient is a client that implements the DescribeBackups 139// operation. 140type DescribeBackupsAPIClient interface { 141 DescribeBackups(context.Context, *DescribeBackupsInput, ...func(*Options)) (*DescribeBackupsOutput, error) 142} 143 144var _ DescribeBackupsAPIClient = (*Client)(nil) 145 146// DescribeBackupsPaginatorOptions is the paginator options for DescribeBackups 147type DescribeBackupsPaginatorOptions struct { 148 // The maximum number of backups to return in the response. When there are more 149 // backups than the number you specify, the response contains a NextToken value. 150 Limit int32 151 152 // Set to true if pagination should stop if the service returns a pagination token 153 // that matches the most recent token provided to the service. 154 StopOnDuplicateToken bool 155} 156 157// DescribeBackupsPaginator is a paginator for DescribeBackups 158type DescribeBackupsPaginator struct { 159 options DescribeBackupsPaginatorOptions 160 client DescribeBackupsAPIClient 161 params *DescribeBackupsInput 162 nextToken *string 163 firstPage bool 164} 165 166// NewDescribeBackupsPaginator returns a new DescribeBackupsPaginator 167func NewDescribeBackupsPaginator(client DescribeBackupsAPIClient, params *DescribeBackupsInput, optFns ...func(*DescribeBackupsPaginatorOptions)) *DescribeBackupsPaginator { 168 if params == nil { 169 params = &DescribeBackupsInput{} 170 } 171 172 options := DescribeBackupsPaginatorOptions{} 173 if params.MaxResults != nil { 174 options.Limit = *params.MaxResults 175 } 176 177 for _, fn := range optFns { 178 fn(&options) 179 } 180 181 return &DescribeBackupsPaginator{ 182 options: options, 183 client: client, 184 params: params, 185 firstPage: true, 186 } 187} 188 189// HasMorePages returns a boolean indicating whether more pages are available 190func (p *DescribeBackupsPaginator) HasMorePages() bool { 191 return p.firstPage || p.nextToken != nil 192} 193 194// NextPage retrieves the next DescribeBackups page. 195func (p *DescribeBackupsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeBackupsOutput, error) { 196 if !p.HasMorePages() { 197 return nil, fmt.Errorf("no more pages available") 198 } 199 200 params := *p.params 201 params.NextToken = p.nextToken 202 203 var limit *int32 204 if p.options.Limit > 0 { 205 limit = &p.options.Limit 206 } 207 params.MaxResults = limit 208 209 result, err := p.client.DescribeBackups(ctx, ¶ms, optFns...) 210 if err != nil { 211 return nil, err 212 } 213 p.firstPage = false 214 215 prevToken := p.nextToken 216 p.nextToken = result.NextToken 217 218 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 219 p.nextToken = nil 220 } 221 222 return result, nil 223} 224 225func newServiceMetadataMiddleware_opDescribeBackups(region string) *awsmiddleware.RegisterServiceMetadata { 226 return &awsmiddleware.RegisterServiceMetadata{ 227 Region: region, 228 ServiceID: ServiceID, 229 SigningName: "cloudhsm", 230 OperationName: "DescribeBackups", 231 } 232} 233