1// Code generated by smithy-go-codegen DO NOT EDIT. 2 3package opsworkscm 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/opsworkscm/types" 11 "github.com/aws/smithy-go/middleware" 12 smithyhttp "github.com/aws/smithy-go/transport/http" 13) 14 15// Describes backups. The results are ordered by time, with newest backups first. 16// If you do not specify a BackupId or ServerName, the command returns all backups. 17// This operation is synchronous. A ResourceNotFoundException is thrown when the 18// backup does not exist. A ValidationException is raised when parameters of the 19// request are not valid. 20func (c *Client) DescribeBackups(ctx context.Context, params *DescribeBackupsInput, optFns ...func(*Options)) (*DescribeBackupsOutput, error) { 21 if params == nil { 22 params = &DescribeBackupsInput{} 23 } 24 25 result, metadata, err := c.invokeOperation(ctx, "DescribeBackups", params, optFns, addOperationDescribeBackupsMiddlewares) 26 if err != nil { 27 return nil, err 28 } 29 30 out := result.(*DescribeBackupsOutput) 31 out.ResultMetadata = metadata 32 return out, nil 33} 34 35type DescribeBackupsInput struct { 36 37 // Describes a single backup. 38 BackupId *string 39 40 // This is not currently implemented for DescribeBackups requests. 41 MaxResults *int32 42 43 // This is not currently implemented for DescribeBackups requests. 44 NextToken *string 45 46 // Returns backups for the server with the specified ServerName. 47 ServerName *string 48} 49 50type DescribeBackupsOutput struct { 51 52 // Contains the response to a DescribeBackups request. 53 Backups []types.Backup 54 55 // This is not currently implemented for DescribeBackups requests. 56 NextToken *string 57 58 // Metadata pertaining to the operation's result. 59 ResultMetadata middleware.Metadata 60} 61 62func addOperationDescribeBackupsMiddlewares(stack *middleware.Stack, options Options) (err error) { 63 err = stack.Serialize.Add(&awsAwsjson11_serializeOpDescribeBackups{}, middleware.After) 64 if err != nil { 65 return err 66 } 67 err = stack.Deserialize.Add(&awsAwsjson11_deserializeOpDescribeBackups{}, middleware.After) 68 if err != nil { 69 return err 70 } 71 if err = addSetLoggerMiddleware(stack, options); err != nil { 72 return err 73 } 74 if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil { 75 return err 76 } 77 if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil { 78 return err 79 } 80 if err = addResolveEndpointMiddleware(stack, options); err != nil { 81 return err 82 } 83 if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil { 84 return err 85 } 86 if err = addRetryMiddlewares(stack, options); err != nil { 87 return err 88 } 89 if err = addHTTPSignerV4Middleware(stack, options); err != nil { 90 return err 91 } 92 if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil { 93 return err 94 } 95 if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil { 96 return err 97 } 98 if err = addClientUserAgent(stack); err != nil { 99 return err 100 } 101 if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil { 102 return err 103 } 104 if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil { 105 return err 106 } 107 if err = stack.Initialize.Add(newServiceMetadataMiddleware_opDescribeBackups(options.Region), middleware.Before); err != nil { 108 return err 109 } 110 if err = addRequestIDRetrieverMiddleware(stack); err != nil { 111 return err 112 } 113 if err = addResponseErrorMiddleware(stack); err != nil { 114 return err 115 } 116 if err = addRequestResponseLogging(stack, options); err != nil { 117 return err 118 } 119 return nil 120} 121 122// DescribeBackupsAPIClient is a client that implements the DescribeBackups 123// operation. 124type DescribeBackupsAPIClient interface { 125 DescribeBackups(context.Context, *DescribeBackupsInput, ...func(*Options)) (*DescribeBackupsOutput, error) 126} 127 128var _ DescribeBackupsAPIClient = (*Client)(nil) 129 130// DescribeBackupsPaginatorOptions is the paginator options for DescribeBackups 131type DescribeBackupsPaginatorOptions struct { 132 // This is not currently implemented for DescribeBackups requests. 133 Limit int32 134 135 // Set to true if pagination should stop if the service returns a pagination token 136 // that matches the most recent token provided to the service. 137 StopOnDuplicateToken bool 138} 139 140// DescribeBackupsPaginator is a paginator for DescribeBackups 141type DescribeBackupsPaginator struct { 142 options DescribeBackupsPaginatorOptions 143 client DescribeBackupsAPIClient 144 params *DescribeBackupsInput 145 nextToken *string 146 firstPage bool 147} 148 149// NewDescribeBackupsPaginator returns a new DescribeBackupsPaginator 150func NewDescribeBackupsPaginator(client DescribeBackupsAPIClient, params *DescribeBackupsInput, optFns ...func(*DescribeBackupsPaginatorOptions)) *DescribeBackupsPaginator { 151 options := DescribeBackupsPaginatorOptions{} 152 if params.MaxResults != nil { 153 options.Limit = *params.MaxResults 154 } 155 156 for _, fn := range optFns { 157 fn(&options) 158 } 159 160 if params == nil { 161 params = &DescribeBackupsInput{} 162 } 163 164 return &DescribeBackupsPaginator{ 165 options: options, 166 client: client, 167 params: params, 168 firstPage: true, 169 } 170} 171 172// HasMorePages returns a boolean indicating whether more pages are available 173func (p *DescribeBackupsPaginator) HasMorePages() bool { 174 return p.firstPage || p.nextToken != nil 175} 176 177// NextPage retrieves the next DescribeBackups page. 178func (p *DescribeBackupsPaginator) NextPage(ctx context.Context, optFns ...func(*Options)) (*DescribeBackupsOutput, error) { 179 if !p.HasMorePages() { 180 return nil, fmt.Errorf("no more pages available") 181 } 182 183 params := *p.params 184 params.NextToken = p.nextToken 185 186 var limit *int32 187 if p.options.Limit > 0 { 188 limit = &p.options.Limit 189 } 190 params.MaxResults = limit 191 192 result, err := p.client.DescribeBackups(ctx, ¶ms, optFns...) 193 if err != nil { 194 return nil, err 195 } 196 p.firstPage = false 197 198 prevToken := p.nextToken 199 p.nextToken = result.NextToken 200 201 if p.options.StopOnDuplicateToken && prevToken != nil && p.nextToken != nil && *prevToken == *p.nextToken { 202 p.nextToken = nil 203 } 204 205 return result, nil 206} 207 208func newServiceMetadataMiddleware_opDescribeBackups(region string) *awsmiddleware.RegisterServiceMetadata { 209 return &awsmiddleware.RegisterServiceMetadata{ 210 Region: region, 211 ServiceID: ServiceID, 212 SigningName: "opsworks-cm", 213 OperationName: "DescribeBackups", 214 } 215} 216