1// Code generated by smithy-go-codegen DO NOT EDIT.
2
3package docdb
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/docdb/types"
11	presignedurlcust "github.com/aws/aws-sdk-go-v2/service/internal/presigned-url"
12	"github.com/aws/smithy-go/middleware"
13	smithyhttp "github.com/aws/smithy-go/transport/http"
14)
15
16// Copies a snapshot of a cluster. To copy a cluster snapshot from a shared manual
17// cluster snapshot, SourceDBClusterSnapshotIdentifier must be the Amazon Resource
18// Name (ARN) of the shared cluster snapshot. You can only copy a shared DB cluster
19// snapshot, whether encrypted or not, in the same AWS Region. To cancel the copy
20// operation after it is in progress, delete the target cluster snapshot identified
21// by TargetDBClusterSnapshotIdentifier while that cluster snapshot is in the
22// copying status.
23func (c *Client) CopyDBClusterSnapshot(ctx context.Context, params *CopyDBClusterSnapshotInput, optFns ...func(*Options)) (*CopyDBClusterSnapshotOutput, error) {
24	if params == nil {
25		params = &CopyDBClusterSnapshotInput{}
26	}
27
28	result, metadata, err := c.invokeOperation(ctx, "CopyDBClusterSnapshot", params, optFns, addOperationCopyDBClusterSnapshotMiddlewares)
29	if err != nil {
30		return nil, err
31	}
32
33	out := result.(*CopyDBClusterSnapshotOutput)
34	out.ResultMetadata = metadata
35	return out, nil
36}
37
38// Represents the input to CopyDBClusterSnapshot.
39type CopyDBClusterSnapshotInput struct {
40
41	// The identifier of the cluster snapshot to copy. This parameter is not case
42	// sensitive. Constraints:
43	//
44	// * Must specify a valid system snapshot in the available
45	// state.
46	//
47	// * If the source snapshot is in the same AWS Region as the copy, specify
48	// a valid snapshot identifier.
49	//
50	// * If the source snapshot is in a different AWS
51	// Region than the copy, specify a valid cluster snapshot ARN.
52	//
53	// Example:
54	// my-cluster-snapshot1
55	//
56	// This member is required.
57	SourceDBClusterSnapshotIdentifier *string
58
59	// The identifier of the new cluster snapshot to create from the source cluster
60	// snapshot. This parameter is not case sensitive. Constraints:
61	//
62	// * Must contain
63	// from 1 to 63 letters, numbers, or hyphens.
64	//
65	// * The first character must be a
66	// letter.
67	//
68	// * Cannot end with a hyphen or contain two consecutive
69	// hyphens.
70	//
71	// Example: my-cluster-snapshot2
72	//
73	// This member is required.
74	TargetDBClusterSnapshotIdentifier *string
75
76	// Set to true to copy all tags from the source cluster snapshot to the target
77	// cluster snapshot, and otherwise false. The default is false.
78	CopyTags *bool
79
80	// The AWS KMS key ID for an encrypted cluster snapshot. The AWS KMS key ID is the
81	// Amazon Resource Name (ARN), AWS KMS key identifier, or the AWS KMS key alias for
82	// the AWS KMS encryption key. If you copy an encrypted cluster snapshot from your
83	// AWS account, you can specify a value for KmsKeyId to encrypt the copy with a new
84	// AWS KMS encryption key. If you don't specify a value for KmsKeyId, then the copy
85	// of the cluster snapshot is encrypted with the same AWS KMS key as the source
86	// cluster snapshot. If you copy an encrypted cluster snapshot that is shared from
87	// another AWS account, then you must specify a value for KmsKeyId. To copy an
88	// encrypted cluster snapshot to another AWS Region, set KmsKeyId to the AWS KMS
89	// key ID that you want to use to encrypt the copy of the cluster snapshot in the
90	// destination Region. AWS KMS encryption keys are specific to the AWS Region that
91	// they are created in, and you can't use encryption keys from one AWS Region in
92	// another AWS Region. If you copy an unencrypted cluster snapshot and specify a
93	// value for the KmsKeyId parameter, an error is returned.
94	KmsKeyId *string
95
96	// The URL that contains a Signature Version 4 signed request for the
97	// CopyDBClusterSnapshot API action in the AWS Region that contains the source
98	// cluster snapshot to copy. You must use the PreSignedUrl parameter when copying a
99	// cluster snapshot from another AWS Region. If you are using an AWS SDK tool or
100	// the AWS CLI, you can specify SourceRegion (or --source-region for the AWS CLI)
101	// instead of specifying PreSignedUrl manually. Specifying SourceRegion
102	// autogenerates a pre-signed URL that is a valid request for the operation that
103	// can be executed in the source AWS Region. The presigned URL must be a valid
104	// request for the CopyDBClusterSnapshot API action that can be executed in the
105	// source AWS Region that contains the cluster snapshot to be copied. The presigned
106	// URL request must contain the following parameter values:
107	//
108	// * SourceRegion - The
109	// ID of the region that contains the snapshot to be copied.
110	//
111	// *
112	// SourceDBClusterSnapshotIdentifier - The identifier for the the encrypted cluster
113	// snapshot to be copied. This identifier must be in the Amazon Resource Name (ARN)
114	// format for the source AWS Region. For example, if you are copying an encrypted
115	// cluster snapshot from the us-east-1 AWS Region, then your
116	// SourceDBClusterSnapshotIdentifier looks something like the following:
117	// arn:aws:rds:us-east-1:12345678012:sample-cluster:sample-cluster-snapshot.
118	//
119	// *
120	// TargetDBClusterSnapshotIdentifier - The identifier for the new cluster snapshot
121	// to be created. This parameter isn't case sensitive.
122	PreSignedUrl *string
123
124	// The AWS region the resource is in. The presigned URL will be created with this
125	// region, if the PresignURL member is empty set.
126	SourceRegion *string
127
128	// The tags to be assigned to the cluster snapshot.
129	Tags []types.Tag
130
131	// Used by the SDK's PresignURL autofill customization to specify the region the of
132	// the client's request.
133	destinationRegion *string
134}
135
136type CopyDBClusterSnapshotOutput struct {
137
138	// Detailed information about a cluster snapshot.
139	DBClusterSnapshot *types.DBClusterSnapshot
140
141	// Metadata pertaining to the operation's result.
142	ResultMetadata middleware.Metadata
143}
144
145func addOperationCopyDBClusterSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
146	err = stack.Serialize.Add(&awsAwsquery_serializeOpCopyDBClusterSnapshot{}, middleware.After)
147	if err != nil {
148		return err
149	}
150	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCopyDBClusterSnapshot{}, middleware.After)
151	if err != nil {
152		return err
153	}
154	if err = addSetLoggerMiddleware(stack, options); err != nil {
155		return err
156	}
157	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
158		return err
159	}
160	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
161		return err
162	}
163	if err = addResolveEndpointMiddleware(stack, options); err != nil {
164		return err
165	}
166	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
167		return err
168	}
169	if err = addRetryMiddlewares(stack, options); err != nil {
170		return err
171	}
172	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
173		return err
174	}
175	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
176		return err
177	}
178	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
179		return err
180	}
181	if err = addClientUserAgent(stack); err != nil {
182		return err
183	}
184	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
185		return err
186	}
187	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
188		return err
189	}
190	if err = addCopyDBClusterSnapshotPresignURLMiddleware(stack, options); err != nil {
191		return err
192	}
193	if err = addOpCopyDBClusterSnapshotValidationMiddleware(stack); err != nil {
194		return err
195	}
196	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCopyDBClusterSnapshot(options.Region), middleware.Before); err != nil {
197		return err
198	}
199	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
200		return err
201	}
202	if err = addResponseErrorMiddleware(stack); err != nil {
203		return err
204	}
205	if err = addRequestResponseLogging(stack, options); err != nil {
206		return err
207	}
208	return nil
209}
210
211func copyCopyDBClusterSnapshotInputForPresign(params interface{}) (interface{}, error) {
212	input, ok := params.(*CopyDBClusterSnapshotInput)
213	if !ok {
214		return nil, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
215	}
216	cpy := *input
217	return &cpy, nil
218}
219func getCopyDBClusterSnapshotPreSignedUrl(params interface{}) (string, bool, error) {
220	input, ok := params.(*CopyDBClusterSnapshotInput)
221	if !ok {
222		return ``, false, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
223	}
224	if input.PreSignedUrl == nil || len(*input.PreSignedUrl) == 0 {
225		return ``, false, nil
226	}
227	return *input.PreSignedUrl, true, nil
228}
229func getCopyDBClusterSnapshotSourceRegion(params interface{}) (string, bool, error) {
230	input, ok := params.(*CopyDBClusterSnapshotInput)
231	if !ok {
232		return ``, false, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
233	}
234	if input.SourceRegion == nil || len(*input.SourceRegion) == 0 {
235		return ``, false, nil
236	}
237	return *input.SourceRegion, true, nil
238}
239func setCopyDBClusterSnapshotPreSignedUrl(params interface{}, value string) error {
240	input, ok := params.(*CopyDBClusterSnapshotInput)
241	if !ok {
242		return fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
243	}
244	input.PreSignedUrl = &value
245	return nil
246}
247func setCopyDBClusterSnapshotdestinationRegion(params interface{}, value string) error {
248	input, ok := params.(*CopyDBClusterSnapshotInput)
249	if !ok {
250		return fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
251	}
252	input.destinationRegion = &value
253	return nil
254}
255func addCopyDBClusterSnapshotPresignURLMiddleware(stack *middleware.Stack, options Options) error {
256	return presignedurlcust.AddMiddleware(stack, presignedurlcust.Options{
257		Accessor: presignedurlcust.ParameterAccessor{
258			GetPresignedURL: getCopyDBClusterSnapshotPreSignedUrl,
259
260			GetSourceRegion: getCopyDBClusterSnapshotSourceRegion,
261
262			CopyInput: copyCopyDBClusterSnapshotInputForPresign,
263
264			SetDestinationRegion: setCopyDBClusterSnapshotdestinationRegion,
265
266			SetPresignedURL: setCopyDBClusterSnapshotPreSignedUrl,
267		},
268		Presigner: &presignAutoFillCopyDBClusterSnapshotClient{client: NewPresignClient(New(options))},
269	})
270}
271
272type presignAutoFillCopyDBClusterSnapshotClient struct {
273	client *PresignClient
274}
275
276// PresignURL is a middleware accessor that satisfies URLPresigner interface.
277func (c *presignAutoFillCopyDBClusterSnapshotClient) PresignURL(ctx context.Context, srcRegion string, params interface{}) (*v4.PresignedHTTPRequest, error) {
278	input, ok := params.(*CopyDBClusterSnapshotInput)
279	if !ok {
280		return nil, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
281	}
282	optFn := func(o *Options) {
283		o.Region = srcRegion
284		o.APIOptions = append(o.APIOptions, presignedurlcust.RemoveMiddleware)
285	}
286	presignOptFn := WithPresignClientFromClientOptions(optFn)
287	return c.client.PresignCopyDBClusterSnapshot(ctx, input, presignOptFn)
288}
289
290func newServiceMetadataMiddleware_opCopyDBClusterSnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
291	return &awsmiddleware.RegisterServiceMetadata{
292		Region:        region,
293		ServiceID:     ServiceID,
294		SigningName:   "rds",
295		OperationName: "CopyDBClusterSnapshot",
296	}
297}
298
299// PresignCopyDBClusterSnapshot is used to generate a presigned HTTP Request which
300// contains presigned URL, signed headers and HTTP method used.
301func (c *PresignClient) PresignCopyDBClusterSnapshot(ctx context.Context, params *CopyDBClusterSnapshotInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
302	if params == nil {
303		params = &CopyDBClusterSnapshotInput{}
304	}
305	options := c.options.copy()
306	for _, fn := range optFns {
307		fn(&options)
308	}
309	clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
310
311	result, _, err := c.client.invokeOperation(ctx, "CopyDBClusterSnapshot", params, clientOptFns,
312		addOperationCopyDBClusterSnapshotMiddlewares,
313		presignConverter(options).convertToPresignMiddleware,
314	)
315	if err != nil {
316		return nil, err
317	}
318
319	out := result.(*v4.PresignedHTTPRequest)
320	return out, nil
321}
322