/******************************************************************************* * 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 { /// /// Creates a new Amazon DocumentDB cluster. /// [Cmdlet("New", "DOCDBCluster", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.DocDB.Model.DBCluster")] [AWSCmdlet("Calls the Amazon DocumentDB (with MongoDB compatibility) CreateDBCluster API operation.", Operation = new[] {"CreateDBCluster"}, SelectReturnType = typeof(Amazon.DocDB.Model.CreateDBClusterResponse))] [AWSCmdletOutput("Amazon.DocDB.Model.DBCluster or Amazon.DocDB.Model.CreateDBClusterResponse", "This cmdlet returns an Amazon.DocDB.Model.DBCluster object.", "The service call response (type Amazon.DocDB.Model.CreateDBClusterResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewDOCDBClusterCmdlet : AmazonDocDBClientCmdlet, IExecutor { #region Parameter AvailabilityZone /// /// /// A list of Amazon EC2 Availability Zones that instances in the cluster can be created /// in. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("AvailabilityZones")] public System.String[] AvailabilityZone { get; set; } #endregion #region Parameter BackupRetentionPeriod /// /// /// The number of days for which automated backups are retained. You must specify a minimum /// value of 1.Default: 1Constraints: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? BackupRetentionPeriod { get; set; } #endregion #region Parameter DBClusterIdentifier /// /// /// The cluster identifier. This parameter is stored as a lowercase string.Constraints:Example: my-cluster /// /// #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 DBClusterIdentifier { get; set; } #endregion #region Parameter DBClusterParameterGroupName /// /// /// The name of the cluster parameter group to associate with this cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String DBClusterParameterGroupName { get; set; } #endregion #region Parameter DBSubnetGroupName /// /// /// A subnet group to associate with this cluster.Constraints: Must match the name of an existing DBSubnetGroup. Must not /// be default.Example: mySubnetgroup /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String DBSubnetGroupName { get; set; } #endregion #region Parameter DeletionProtection /// /// /// Specifies whether this cluster can be deleted. If DeletionProtection /// is enabled, the cluster cannot be deleted unless it is modified and DeletionProtection /// is disabled. DeletionProtection protects clusters from being accidentally /// deleted. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? DeletionProtection { get; set; } #endregion #region Parameter EnableCloudwatchLogsExport /// /// /// A list of log types that need to be enabled for exporting to Amazon CloudWatch Logs. /// You can enable audit logs or profiler logs. For more information, see /// Auditing Amazon DocumentDB Events and /// Profiling Amazon DocumentDB Operations. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("EnableCloudwatchLogsExports")] public System.String[] EnableCloudwatchLogsExport { get; set; } #endregion #region Parameter Engine /// /// /// The name of the database engine to be used for this cluster.Valid values: docdb /// /// #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 Engine { get; set; } #endregion #region Parameter EngineVersion /// /// /// The version number of the database engine to use. The --engine-version /// will default to the latest major engine version. For production workloads, we recommend /// explicitly declaring this parameter with the intended major engine version. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String EngineVersion { get; set; } #endregion #region Parameter GlobalClusterIdentifier /// /// /// The cluster identifier of the new global cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String GlobalClusterIdentifier { get; set; } #endregion #region Parameter KmsKeyId /// /// /// The KMS key identifier for an encrypted cluster.The KMS key identifier is the Amazon Resource Name (ARN) for the KMS encryption key. /// If you are creating a cluster using the same Amazon Web Services account that owns /// the KMS encryption key that is used to encrypt the new cluster, you can use the KMS /// key alias instead of the ARN for the KMS encryption key.If an encryption key is not specified in KmsKeyId: KMS creates the default encryption key for your Amazon Web Services account. Your /// Amazon Web Services account has a different default encryption key for each Amazon /// Web Services Regions. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KmsKeyId { get; set; } #endregion #region Parameter MasterUsername /// /// /// The name of the master user for the cluster.Constraints: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String MasterUsername { get; set; } #endregion #region Parameter MasterUserPassword /// /// /// The password for the master database user. This password can contain any printable /// ASCII character except forward slash (/), double quote ("), or the "at" symbol (@).Constraints: Must contain from 8 to 100 characters. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String MasterUserPassword { get; set; } #endregion #region Parameter Port /// /// /// The port number on which the instances in the cluster accept connections. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? Port { get; set; } #endregion #region Parameter PreferredBackupWindow /// /// /// The daily time range during which automated backups are created if automated backups /// are enabled using the BackupRetentionPeriod parameter. The default is a 30-minute window selected at random from an 8-hour block of time /// for each Amazon Web Services Region. Constraints: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PreferredBackupWindow { get; set; } #endregion #region Parameter PreferredMaintenanceWindow /// /// /// The weekly time range during which system maintenance can occur, in Universal Coordinated /// Time (UTC).Format: ddd:hh24:mi-ddd:hh24:miThe default is a 30-minute window selected at random from an 8-hour block of time /// for each Amazon Web Services Region, occurring on a random day of the week.Valid days: Mon, Tue, Wed, Thu, Fri, Sat, SunConstraints: Minimum 30-minute window. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PreferredMaintenanceWindow { get; set; } #endregion #region Parameter PreSignedUrl /// /// /// Not currently supported. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PreSignedUrl { 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 StorageEncrypted /// /// /// Specifies whether the cluster is encrypted. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? StorageEncrypted { get; set; } #endregion #region Parameter Tag /// /// /// The tags to be assigned to the cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DocDB.Model.Tag[] Tag { get; set; } #endregion #region Parameter VpcSecurityGroupId /// /// /// A list of EC2 VPC security groups to associate with this cluster. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("VpcSecurityGroupIds")] public System.String[] VpcSecurityGroupId { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'DBCluster'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DocDB.Model.CreateDBClusterResponse). /// Specifying the name of a property of type Amazon.DocDB.Model.CreateDBClusterResponse 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; } = "DBCluster"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the DBClusterIdentifier parameter. /// The -PassThru parameter is deprecated, use -Select '^DBClusterIdentifier' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^DBClusterIdentifier' 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.DBClusterIdentifier), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DOCDBCluster (CreateDBCluster)")) { 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.DBClusterIdentifier; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.SourceRegion = this.SourceRegion; if (this.AvailabilityZone != null) { context.AvailabilityZone = new List(this.AvailabilityZone); } context.BackupRetentionPeriod = this.BackupRetentionPeriod; context.DBClusterIdentifier = this.DBClusterIdentifier; #if MODULAR if (this.DBClusterIdentifier == null && ParameterWasBound(nameof(this.DBClusterIdentifier))) { WriteWarning("You are passing $null as a value for parameter DBClusterIdentifier 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 context.DBClusterParameterGroupName = this.DBClusterParameterGroupName; context.DBSubnetGroupName = this.DBSubnetGroupName; context.DeletionProtection = this.DeletionProtection; if (this.EnableCloudwatchLogsExport != null) { context.EnableCloudwatchLogsExport = new List(this.EnableCloudwatchLogsExport); } context.Engine = this.Engine; #if MODULAR if (this.Engine == null && ParameterWasBound(nameof(this.Engine))) { WriteWarning("You are passing $null as a value for parameter Engine 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 context.EngineVersion = this.EngineVersion; context.GlobalClusterIdentifier = this.GlobalClusterIdentifier; context.KmsKeyId = this.KmsKeyId; context.MasterUsername = this.MasterUsername; context.MasterUserPassword = this.MasterUserPassword; context.Port = this.Port; context.PreferredBackupWindow = this.PreferredBackupWindow; context.PreferredMaintenanceWindow = this.PreferredMaintenanceWindow; context.PreSignedUrl = this.PreSignedUrl; context.StorageEncrypted = this.StorageEncrypted; if (this.Tag != null) { context.Tag = new List(this.Tag); } if (this.VpcSecurityGroupId != null) { context.VpcSecurityGroupId = new List(this.VpcSecurityGroupId); } // 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.CreateDBClusterRequest(); if (cmdletContext.SourceRegion != null) { request.SourceRegion = cmdletContext.SourceRegion; } if (cmdletContext.AvailabilityZone != null) { request.AvailabilityZones = cmdletContext.AvailabilityZone; } if (cmdletContext.BackupRetentionPeriod != null) { request.BackupRetentionPeriod = cmdletContext.BackupRetentionPeriod.Value; } if (cmdletContext.DBClusterIdentifier != null) { request.DBClusterIdentifier = cmdletContext.DBClusterIdentifier; } if (cmdletContext.DBClusterParameterGroupName != null) { request.DBClusterParameterGroupName = cmdletContext.DBClusterParameterGroupName; } if (cmdletContext.DBSubnetGroupName != null) { request.DBSubnetGroupName = cmdletContext.DBSubnetGroupName; } if (cmdletContext.DeletionProtection != null) { request.DeletionProtection = cmdletContext.DeletionProtection.Value; } if (cmdletContext.EnableCloudwatchLogsExport != null) { request.EnableCloudwatchLogsExports = cmdletContext.EnableCloudwatchLogsExport; } if (cmdletContext.Engine != null) { request.Engine = cmdletContext.Engine; } if (cmdletContext.EngineVersion != null) { request.EngineVersion = cmdletContext.EngineVersion; } if (cmdletContext.GlobalClusterIdentifier != null) { request.GlobalClusterIdentifier = cmdletContext.GlobalClusterIdentifier; } if (cmdletContext.KmsKeyId != null) { request.KmsKeyId = cmdletContext.KmsKeyId; } if (cmdletContext.MasterUsername != null) { request.MasterUsername = cmdletContext.MasterUsername; } if (cmdletContext.MasterUserPassword != null) { request.MasterUserPassword = cmdletContext.MasterUserPassword; } if (cmdletContext.Port != null) { request.Port = cmdletContext.Port.Value; } if (cmdletContext.PreferredBackupWindow != null) { request.PreferredBackupWindow = cmdletContext.PreferredBackupWindow; } if (cmdletContext.PreferredMaintenanceWindow != null) { request.PreferredMaintenanceWindow = cmdletContext.PreferredMaintenanceWindow; } if (cmdletContext.PreSignedUrl != null) { request.PreSignedUrl = cmdletContext.PreSignedUrl; } if (cmdletContext.StorageEncrypted != null) { request.StorageEncrypted = cmdletContext.StorageEncrypted.Value; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.VpcSecurityGroupId != null) { request.VpcSecurityGroupIds = cmdletContext.VpcSecurityGroupId; } 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.CreateDBClusterResponse CallAWSServiceOperation(IAmazonDocDB client, Amazon.DocDB.Model.CreateDBClusterRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon DocumentDB (with MongoDB compatibility)", "CreateDBCluster"); try { #if DESKTOP return client.CreateDBCluster(request); #elif CORECLR return client.CreateDBClusterAsync(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 List AvailabilityZone { get; set; } public System.Int32? BackupRetentionPeriod { get; set; } public System.String DBClusterIdentifier { get; set; } public System.String DBClusterParameterGroupName { get; set; } public System.String DBSubnetGroupName { get; set; } public System.Boolean? DeletionProtection { get; set; } public List EnableCloudwatchLogsExport { get; set; } public System.String Engine { get; set; } public System.String EngineVersion { get; set; } public System.String GlobalClusterIdentifier { get; set; } public System.String KmsKeyId { get; set; } public System.String MasterUsername { get; set; } public System.String MasterUserPassword { get; set; } public System.Int32? Port { get; set; } public System.String PreferredBackupWindow { get; set; } public System.String PreferredMaintenanceWindow { get; set; } public System.String PreSignedUrl { get; set; } public System.Boolean? StorageEncrypted { get; set; } public List Tag { get; set; } public List VpcSecurityGroupId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.DBCluster; } } }