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 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, c.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 Region as the copy, specify a
48	// valid snapshot identifier.
49	//
50	// * If the source snapshot is in a different Region
51	// 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 KMS key ID for an encrypted cluster snapshot. The KMS key ID is the Amazon
81	// Resource Name (ARN), KMS key identifier, or the KMS key alias for the KMS
82	// encryption key. If you copy an encrypted cluster snapshot from your account, you
83	// can specify a value for KmsKeyId to encrypt the copy with a new KMS encryption
84	// key. If you don't specify a value for KmsKeyId, then the copy of the cluster
85	// snapshot is encrypted with the same KMS key as the source cluster snapshot. If
86	// you copy an encrypted cluster snapshot that is shared from another account, then
87	// you must specify a value for KmsKeyId. To copy an encrypted cluster snapshot to
88	// another Region, set KmsKeyId to the KMS key ID that you want to use to encrypt
89	// the copy of the cluster snapshot in the destination Region. KMS encryption keys
90	// are specific to the Region that they are created in, and you can't use
91	// encryption keys from one Region in another Region. If you copy an unencrypted
92	// cluster snapshot and specify a value for the KmsKeyId parameter, an error is
93	// returned.
94	KmsKeyId *string
95
96	// The URL that contains a Signature Version 4 signed request for
97	// theCopyDBClusterSnapshot API action in the Region that contains the source
98	// cluster snapshot to copy. You must use the PreSignedUrl parameter when copying a
99	// cluster snapshot from another Region. If you are using an Amazon Web Services
100	// SDK tool or the CLI, you can specify SourceRegion (or --source-region for the
101	// CLI) 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 Region. The presigned URL must be a valid request
104	// for the CopyDBClusterSnapshot API action that can be executed in the source
105	// Region that contains the cluster snapshot to be copied. The presigned URL
106	// request must contain the following parameter values:
107	//
108	// * SourceRegion - The ID of
109	// 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 Region. For example, if you are copying an encrypted
115	// cluster snapshot from the us-east-1 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	noSmithyDocumentSerde
136}
137
138type CopyDBClusterSnapshotOutput struct {
139
140	// Detailed information about a cluster snapshot.
141	DBClusterSnapshot *types.DBClusterSnapshot
142
143	// Metadata pertaining to the operation's result.
144	ResultMetadata middleware.Metadata
145
146	noSmithyDocumentSerde
147}
148
149func (c *Client) addOperationCopyDBClusterSnapshotMiddlewares(stack *middleware.Stack, options Options) (err error) {
150	err = stack.Serialize.Add(&awsAwsquery_serializeOpCopyDBClusterSnapshot{}, middleware.After)
151	if err != nil {
152		return err
153	}
154	err = stack.Deserialize.Add(&awsAwsquery_deserializeOpCopyDBClusterSnapshot{}, middleware.After)
155	if err != nil {
156		return err
157	}
158	if err = addSetLoggerMiddleware(stack, options); err != nil {
159		return err
160	}
161	if err = awsmiddleware.AddClientRequestIDMiddleware(stack); err != nil {
162		return err
163	}
164	if err = smithyhttp.AddComputeContentLengthMiddleware(stack); err != nil {
165		return err
166	}
167	if err = addResolveEndpointMiddleware(stack, options); err != nil {
168		return err
169	}
170	if err = v4.AddComputePayloadSHA256Middleware(stack); err != nil {
171		return err
172	}
173	if err = addRetryMiddlewares(stack, options); err != nil {
174		return err
175	}
176	if err = addHTTPSignerV4Middleware(stack, options); err != nil {
177		return err
178	}
179	if err = awsmiddleware.AddRawResponseToMetadata(stack); err != nil {
180		return err
181	}
182	if err = awsmiddleware.AddRecordResponseTiming(stack); err != nil {
183		return err
184	}
185	if err = addClientUserAgent(stack); err != nil {
186		return err
187	}
188	if err = smithyhttp.AddErrorCloseResponseBodyMiddleware(stack); err != nil {
189		return err
190	}
191	if err = smithyhttp.AddCloseResponseBodyMiddleware(stack); err != nil {
192		return err
193	}
194	if err = addCopyDBClusterSnapshotPresignURLMiddleware(stack, options); err != nil {
195		return err
196	}
197	if err = addOpCopyDBClusterSnapshotValidationMiddleware(stack); err != nil {
198		return err
199	}
200	if err = stack.Initialize.Add(newServiceMetadataMiddleware_opCopyDBClusterSnapshot(options.Region), middleware.Before); err != nil {
201		return err
202	}
203	if err = addRequestIDRetrieverMiddleware(stack); err != nil {
204		return err
205	}
206	if err = addResponseErrorMiddleware(stack); err != nil {
207		return err
208	}
209	if err = addRequestResponseLogging(stack, options); err != nil {
210		return err
211	}
212	return nil
213}
214
215func copyCopyDBClusterSnapshotInputForPresign(params interface{}) (interface{}, error) {
216	input, ok := params.(*CopyDBClusterSnapshotInput)
217	if !ok {
218		return nil, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
219	}
220	cpy := *input
221	return &cpy, nil
222}
223func getCopyDBClusterSnapshotPreSignedUrl(params interface{}) (string, bool, error) {
224	input, ok := params.(*CopyDBClusterSnapshotInput)
225	if !ok {
226		return ``, false, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
227	}
228	if input.PreSignedUrl == nil || len(*input.PreSignedUrl) == 0 {
229		return ``, false, nil
230	}
231	return *input.PreSignedUrl, true, nil
232}
233func getCopyDBClusterSnapshotSourceRegion(params interface{}) (string, bool, error) {
234	input, ok := params.(*CopyDBClusterSnapshotInput)
235	if !ok {
236		return ``, false, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
237	}
238	if input.SourceRegion == nil || len(*input.SourceRegion) == 0 {
239		return ``, false, nil
240	}
241	return *input.SourceRegion, true, nil
242}
243func setCopyDBClusterSnapshotPreSignedUrl(params interface{}, value string) error {
244	input, ok := params.(*CopyDBClusterSnapshotInput)
245	if !ok {
246		return fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
247	}
248	input.PreSignedUrl = &value
249	return nil
250}
251func setCopyDBClusterSnapshotdestinationRegion(params interface{}, value string) error {
252	input, ok := params.(*CopyDBClusterSnapshotInput)
253	if !ok {
254		return fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
255	}
256	input.destinationRegion = &value
257	return nil
258}
259func addCopyDBClusterSnapshotPresignURLMiddleware(stack *middleware.Stack, options Options) error {
260	return presignedurlcust.AddMiddleware(stack, presignedurlcust.Options{
261		Accessor: presignedurlcust.ParameterAccessor{
262			GetPresignedURL: getCopyDBClusterSnapshotPreSignedUrl,
263
264			GetSourceRegion: getCopyDBClusterSnapshotSourceRegion,
265
266			CopyInput: copyCopyDBClusterSnapshotInputForPresign,
267
268			SetDestinationRegion: setCopyDBClusterSnapshotdestinationRegion,
269
270			SetPresignedURL: setCopyDBClusterSnapshotPreSignedUrl,
271		},
272		Presigner: &presignAutoFillCopyDBClusterSnapshotClient{client: NewPresignClient(New(options))},
273	})
274}
275
276type presignAutoFillCopyDBClusterSnapshotClient struct {
277	client *PresignClient
278}
279
280// PresignURL is a middleware accessor that satisfies URLPresigner interface.
281func (c *presignAutoFillCopyDBClusterSnapshotClient) PresignURL(ctx context.Context, srcRegion string, params interface{}) (*v4.PresignedHTTPRequest, error) {
282	input, ok := params.(*CopyDBClusterSnapshotInput)
283	if !ok {
284		return nil, fmt.Errorf("expect *CopyDBClusterSnapshotInput type, got %T", params)
285	}
286	optFn := func(o *Options) {
287		o.Region = srcRegion
288		o.APIOptions = append(o.APIOptions, presignedurlcust.RemoveMiddleware)
289	}
290	presignOptFn := WithPresignClientFromClientOptions(optFn)
291	return c.client.PresignCopyDBClusterSnapshot(ctx, input, presignOptFn)
292}
293
294func newServiceMetadataMiddleware_opCopyDBClusterSnapshot(region string) *awsmiddleware.RegisterServiceMetadata {
295	return &awsmiddleware.RegisterServiceMetadata{
296		Region:        region,
297		ServiceID:     ServiceID,
298		SigningName:   "rds",
299		OperationName: "CopyDBClusterSnapshot",
300	}
301}
302
303// PresignCopyDBClusterSnapshot is used to generate a presigned HTTP Request which
304// contains presigned URL, signed headers and HTTP method used.
305func (c *PresignClient) PresignCopyDBClusterSnapshot(ctx context.Context, params *CopyDBClusterSnapshotInput, optFns ...func(*PresignOptions)) (*v4.PresignedHTTPRequest, error) {
306	if params == nil {
307		params = &CopyDBClusterSnapshotInput{}
308	}
309	options := c.options.copy()
310	for _, fn := range optFns {
311		fn(&options)
312	}
313	clientOptFns := append(options.ClientOptions, withNopHTTPClientAPIOption)
314
315	result, _, err := c.client.invokeOperation(ctx, "CopyDBClusterSnapshot", params, clientOptFns,
316		c.client.addOperationCopyDBClusterSnapshotMiddlewares,
317		presignConverter(options).convertToPresignMiddleware,
318	)
319	if err != nil {
320		return nil, err
321	}
322
323	out := result.(*v4.PresignedHTTPRequest)
324	return out, nil
325}
326