/******************************************************************************* * 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.DocDB; using Amazon.DocDB.Model; namespace Amazon.PowerShell.Cmdlets.DOC { /// /// Copies a snapshot of a cluster. /// /// /// /// To copy a cluster snapshot from a shared manual cluster snapshot, SourceDBClusterSnapshotIdentifier /// must be the Amazon Resource Name (ARN) of the shared cluster snapshot. You can only /// copy a shared DB cluster snapshot, whether encrypted or not, in the same Amazon Web /// Services Region. /// /// To cancel the copy operation after it is in progress, delete the target cluster snapshot /// identified by TargetDBClusterSnapshotIdentifier while that cluster snapshot /// is in the copying status. /// /// [Cmdlet("Copy", "DOCDBClusterSnapshot", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.DocDB.Model.DBClusterSnapshot")] [AWSCmdlet("Calls the Amazon DocumentDB (with MongoDB compatibility) CopyDBClusterSnapshot API operation.", Operation = new[] {"CopyDBClusterSnapshot"}, SelectReturnType = typeof(Amazon.DocDB.Model.CopyDBClusterSnapshotResponse))] [AWSCmdletOutput("Amazon.DocDB.Model.DBClusterSnapshot or Amazon.DocDB.Model.CopyDBClusterSnapshotResponse", "This cmdlet returns an Amazon.DocDB.Model.DBClusterSnapshot object.", "The service call response (type Amazon.DocDB.Model.CopyDBClusterSnapshotResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class CopyDOCDBClusterSnapshotCmdlet : AmazonDocDBClientCmdlet, IExecutor { #region Parameter CopyTag /// /// /// Set to true to copy all tags from the source cluster snapshot to the /// target cluster snapshot, and otherwise false. The default is false. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("CopyTags")] public System.Boolean? CopyTag { get; set; } #endregion #region Parameter KmsKeyId /// /// /// The KMS key ID for an encrypted cluster snapshot. The KMS key ID is the Amazon Resource /// Name (ARN), KMS key identifier, or the KMS key alias for the KMS encryption key. If you copy an encrypted cluster snapshot from your Amazon Web Services account, you /// can specify a value for KmsKeyId to encrypt the copy with a new KMS encryption /// key. If you don't specify a value for KmsKeyId, then the copy of the /// cluster snapshot is encrypted with the same KMS key as the source cluster snapshot.If you copy an encrypted cluster snapshot that is shared from another Amazon Web Services /// account, then you must specify a value for KmsKeyId.To copy an encrypted cluster snapshot to another Amazon Web Services Region, set KmsKeyId /// to the KMS key ID that you want to use to encrypt the copy of the cluster snapshot /// in the destination Region. KMS encryption keys are specific to the Amazon Web Services /// Region that they are created in, and you can't use encryption keys from one Amazon /// Web Services Region in another Amazon Web Services Region.If you copy an unencrypted 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 /// /// /// The URL that contains a Signature Version 4 signed request for theCopyDBClusterSnapshot /// API action in the Amazon Web Services Region that contains the source cluster snapshot /// to copy. You must use the PreSignedUrl parameter when copying a cluster /// snapshot from another Amazon Web Services Region.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 pre-signed URL that /// is a valid request for the operation that can be executed in the source Amazon Web /// Services Region.The presigned URL must be a valid request for the CopyDBClusterSnapshot /// API action that can be executed in the source Amazon Web Services Region that contains /// the cluster snapshot to be copied. The presigned URL request must contain the following /// parameter values: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PreSignedUrl { get; set; } #endregion #region Parameter SourceDBClusterSnapshotIdentifier /// /// /// The identifier of the cluster snapshot to copy. This parameter is not case sensitive.Constraints:Example: my-cluster-snapshot1 /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = 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 tags to be assigned to the cluster snapshot. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DocDB.Model.Tag[] Tag { get; set; } #endregion #region Parameter TargetDBClusterSnapshotIdentifier /// /// /// The identifier of the new cluster snapshot to create from the source cluster snapshot. /// This parameter is not case sensitive.Constraints:Example: my-cluster-snapshot2 /// /// #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 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.DocDB.Model.CopyDBClusterSnapshotResponse). /// Specifying the name of a property of type Amazon.DocDB.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 TargetDBClusterSnapshotIdentifier parameter. /// The -PassThru parameter is deprecated, use -Select '^TargetDBClusterSnapshotIdentifier' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^TargetDBClusterSnapshotIdentifier' 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.TargetDBClusterSnapshotIdentifier), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Copy-DOCDBClusterSnapshot (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.TargetDBClusterSnapshotIdentifier; } #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.DocDB.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.DocDB.Model.CopyDBClusterSnapshotResponse CallAWSServiceOperation(IAmazonDocDB client, Amazon.DocDB.Model.CopyDBClusterSnapshotRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon DocumentDB (with MongoDB compatibility)", "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; } } }