/******************************************************************************* * Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). You may not use * this file except in compliance with the License. A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR * CONDITIONS OF ANY KIND, either express or implied. See the License for the * specific language governing permissions and limitations under the License. * ***************************************************************************** * * AWS Tools for Windows (TM) PowerShell (TM) * */ using System; using System.Collections.Generic; using System.Linq; using System.Management.Automation; using System.Text; using Amazon.PowerShell.Common; using Amazon.Runtime; using Amazon.RDS; using Amazon.RDS.Model; namespace Amazon.PowerShell.Cmdlets.RDS { /// /// Copies a snapshot of a DB cluster. /// /// /// /// To copy a DB cluster snapshot from a shared manual DB cluster snapshot, SourceDBClusterSnapshotIdentifier /// must be the Amazon Resource Name (ARN) of the shared DB cluster snapshot. /// /// You can copy an encrypted DB cluster snapshot from another Amazon Web Services Region. /// In that case, the Amazon Web Services Region where you call the CopyDBClusterSnapshot /// operation is the destination Amazon Web Services Region for the encrypted DB cluster /// snapshot to be copied to. To copy an encrypted DB cluster snapshot from another Amazon /// Web Services Region, you must provide the following values: /// /// To cancel the copy operation once it is in progress, delete the target DB cluster /// snapshot identified by TargetDBClusterSnapshotIdentifier while that DB /// cluster snapshot is in "copying" status. /// /// For more information on copying encrypted Amazon Aurora DB cluster snapshots from /// one Amazon Web Services Region to another, see /// Copying a Snapshot in the Amazon Aurora User Guide. /// /// For more information on Amazon Aurora DB clusters, see /// What is Amazon Aurora? in the Amazon Aurora User Guide. /// /// For more information on Multi-AZ DB clusters, see /// Multi-AZ DB cluster deployments in the Amazon RDS User Guide. /// /// [Cmdlet("Copy", "RDSDBClusterSnapshot", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.RDS.Model.DBClusterSnapshot")] [AWSCmdlet("Calls the Amazon Relational Database Service CopyDBClusterSnapshot API operation.", Operation = new[] {"CopyDBClusterSnapshot"}, SelectReturnType = typeof(Amazon.RDS.Model.CopyDBClusterSnapshotResponse))] [AWSCmdletOutput("Amazon.RDS.Model.DBClusterSnapshot or Amazon.RDS.Model.CopyDBClusterSnapshotResponse", "This cmdlet returns an Amazon.RDS.Model.DBClusterSnapshot object.", "The service call response (type Amazon.RDS.Model.CopyDBClusterSnapshotResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class CopyRDSDBClusterSnapshotCmdlet : AmazonRDSClientCmdlet, IExecutor { #region Parameter CopyTag /// /// /// A value that indicates whether to copy all tags from the source DB cluster snapshot /// to the target DB cluster snapshot. By default, tags are not copied. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("CopyTags")] public System.Boolean? CopyTag { get; set; } #endregion #region Parameter KmsKeyId /// /// /// The Amazon Web Services KMS key identifier for an encrypted DB cluster snapshot. The /// Amazon Web Services KMS key identifier is the key ARN, key ID, alias ARN, or alias /// name for the Amazon Web Services KMS key.If you copy an encrypted DB cluster snapshot from your Amazon Web Services account, /// you can specify a value for KmsKeyId to encrypt the copy with a new KMS /// key. If you don't specify a value for KmsKeyId, then the copy of the /// DB cluster snapshot is encrypted with the same KMS key as the source DB cluster snapshot.If you copy an encrypted DB cluster snapshot that is shared from another Amazon Web /// Services account, then you must specify a value for KmsKeyId.To copy an encrypted DB cluster snapshot to another Amazon Web Services Region, you /// must set KmsKeyId to the Amazon Web Services KMS key identifier you want /// to use to encrypt the copy of the DB cluster snapshot in the destination Amazon Web /// Services Region. KMS keys are specific to the Amazon Web Services Region that they /// are created in, and you can't use KMS keys from one Amazon Web Services Region in /// another Amazon Web Services Region.If you copy an unencrypted DB cluster snapshot and specify a value for the KmsKeyId /// parameter, an error is returned. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KmsKeyId { get; set; } #endregion #region Parameter PreSignedUrl /// /// /// When you are copying a DB cluster snapshot from one Amazon Web Services GovCloud (US) /// Region to another, the URL that contains a Signature Version 4 signed request for /// the CopyDBClusterSnapshot API operation in the Amazon Web Services Region /// that contains the source DB cluster snapshot to copy. Use the PreSignedUrl /// parameter when copying an encrypted DB cluster snapshot from another Amazon Web Services /// Region. Don't specify PreSignedUrl when copying an encrypted DB cluster /// snapshot in the same Amazon Web Services Region.This setting applies only to Amazon Web Services GovCloud (US) Regions. It's ignored /// in other Amazon Web Services Regions.The presigned URL must be a valid request for the CopyDBClusterSnapshot /// API operation that can run in the source Amazon Web Services Region that contains /// the encrypted DB cluster snapshot to copy. The presigned URL request must contain /// the following parameter values:To learn how to generate a Signature Version 4 signed request, see /// Authenticating Requests: Using Query Parameters (Amazon Web Services Signature Version /// 4) and /// Signature Version 4 Signing Process.If you are using an Amazon Web Services SDK tool or the CLI, you can specify SourceRegion /// (or --source-region for the CLI) instead of specifying PreSignedUrl /// manually. Specifying SourceRegion autogenerates a presigned URL that /// is a valid request for the operation that can run in the source Amazon Web Services /// Region. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PreSignedUrl { get; set; } #endregion #region Parameter SourceDBClusterSnapshotIdentifier /// /// /// The identifier of the DB cluster snapshot to copy. This parameter isn't case-sensitive.You can't copy an encrypted, shared DB cluster snapshot from one Amazon Web Services /// Region to another.Constraints:Example: my-cluster-snapshot1 /// /// #if !MODULAR [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)] #else [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String SourceDBClusterSnapshotIdentifier { get; set; } #endregion #region Parameter SourceRegion /// /// /// The SourceRegion for generating the PreSignedUrl property. /// /// If SourceRegion is set and the PreSignedUrl property is not, /// then PreSignedUrl will be automatically generated by the client. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SourceRegion { get; set; } #endregion #region Parameter Tag /// /// /// The service has not provided documentation for this parameter; please refer to the service's API reference documentation for the latest available information. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.RDS.Model.Tag[] Tag { get; set; } #endregion #region Parameter TargetDBClusterSnapshotIdentifier /// /// /// The identifier of the new DB cluster snapshot to create from the source DB cluster /// snapshot. This parameter isn't case-sensitive.Constraints:Example: my-cluster-snapshot2 /// /// #if !MODULAR [System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String TargetDBClusterSnapshotIdentifier { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'DBClusterSnapshot'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.RDS.Model.CopyDBClusterSnapshotResponse). /// Specifying the name of a property of type Amazon.RDS.Model.CopyDBClusterSnapshotResponse will result in that property being returned. /// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public string Select { get; set; } = "DBClusterSnapshot"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the SourceDBClusterSnapshotIdentifier parameter. /// The -PassThru parameter is deprecated, use -Select '^SourceDBClusterSnapshotIdentifier' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^SourceDBClusterSnapshotIdentifier' instead. This parameter will be removed in a future version.")] [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter PassThru { get; set; } #endregion #region Parameter Force /// /// This parameter overrides confirmation prompts to force /// the cmdlet to continue its operation. This parameter should always /// be used with caution. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public SwitchParameter Force { get; set; } #endregion protected override void ProcessRecord() { this._AWSSignerType = "v4"; base.ProcessRecord(); var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.SourceDBClusterSnapshotIdentifier), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Copy-RDSDBClusterSnapshot (CopyDBClusterSnapshot)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); if (this.PassThru.IsPresent) { throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select)); } } else if (this.PassThru.IsPresent) { context.Select = (response, cmdlet) => this.SourceDBClusterSnapshotIdentifier; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.SourceRegion = this.SourceRegion; context.CopyTag = this.CopyTag; context.KmsKeyId = this.KmsKeyId; context.PreSignedUrl = this.PreSignedUrl; context.SourceDBClusterSnapshotIdentifier = this.SourceDBClusterSnapshotIdentifier; #if MODULAR if (this.SourceDBClusterSnapshotIdentifier == null && ParameterWasBound(nameof(this.SourceDBClusterSnapshotIdentifier))) { WriteWarning("You are passing $null as a value for parameter SourceDBClusterSnapshotIdentifier which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif if (this.Tag != null) { context.Tag = new List(this.Tag); } context.TargetDBClusterSnapshotIdentifier = this.TargetDBClusterSnapshotIdentifier; #if MODULAR if (this.TargetDBClusterSnapshotIdentifier == null && ParameterWasBound(nameof(this.TargetDBClusterSnapshotIdentifier))) { WriteWarning("You are passing $null as a value for parameter TargetDBClusterSnapshotIdentifier which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues."); } #endif // allow further manipulation of loaded context prior to processing PostExecutionContextLoad(context); var output = Execute(context) as CmdletOutput; ProcessOutput(output); } #region IExecutor Members public object Execute(ExecutorContext context) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.RDS.Model.CopyDBClusterSnapshotRequest(); if (cmdletContext.SourceRegion != null) { request.SourceRegion = cmdletContext.SourceRegion; } if (cmdletContext.CopyTag != null) { request.CopyTags = cmdletContext.CopyTag.Value; } if (cmdletContext.KmsKeyId != null) { request.KmsKeyId = cmdletContext.KmsKeyId; } if (cmdletContext.PreSignedUrl != null) { request.PreSignedUrl = cmdletContext.PreSignedUrl; } if (cmdletContext.SourceDBClusterSnapshotIdentifier != null) { request.SourceDBClusterSnapshotIdentifier = cmdletContext.SourceDBClusterSnapshotIdentifier; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.TargetDBClusterSnapshotIdentifier != null) { request.TargetDBClusterSnapshotIdentifier = cmdletContext.TargetDBClusterSnapshotIdentifier; } CmdletOutput output; // issue call var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); try { var response = CallAWSServiceOperation(client, request); object pipelineOutput = null; pipelineOutput = cmdletContext.Select(response, this); output = new CmdletOutput { PipelineOutput = pipelineOutput, ServiceResponse = response }; } catch (Exception e) { output = new CmdletOutput { ErrorResponse = e }; } return output; } public ExecutorContext CreateContext() { return new CmdletContext(); } #endregion #region AWS Service Operation Call private Amazon.RDS.Model.CopyDBClusterSnapshotResponse CallAWSServiceOperation(IAmazonRDS client, Amazon.RDS.Model.CopyDBClusterSnapshotRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Relational Database Service", "CopyDBClusterSnapshot"); try { #if DESKTOP return client.CopyDBClusterSnapshot(request); #elif CORECLR return client.CopyDBClusterSnapshotAsync(request).GetAwaiter().GetResult(); #else #error "Unknown build edition" #endif } catch (AmazonServiceException exc) { var webException = exc.InnerException as System.Net.WebException; if (webException != null) { throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); } throw; } } #endregion internal partial class CmdletContext : ExecutorContext { public System.String SourceRegion { get; set; } public System.Boolean? CopyTag { get; set; } public System.String KmsKeyId { get; set; } public System.String PreSignedUrl { get; set; } public System.String SourceDBClusterSnapshotIdentifier { get; set; } public List Tag { get; set; } public System.String TargetDBClusterSnapshotIdentifier { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.DBClusterSnapshot; } } }