/*******************************************************************************
* 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.Lightsail;
using Amazon.Lightsail.Model;
namespace Amazon.PowerShell.Cmdlets.LS
{
///
/// Creates a new database in Amazon Lightsail.
///
///
///
/// The create relational database
operation supports tag-based access control
/// via request tags. For more information, see the Amazon
/// Lightsail Developer Guide.
///
///
[Cmdlet("New", "LSRelationalDatabase", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Lightsail.Model.Operation")]
[AWSCmdlet("Calls the Amazon Lightsail CreateRelationalDatabase API operation.", Operation = new[] {"CreateRelationalDatabase"}, SelectReturnType = typeof(Amazon.Lightsail.Model.CreateRelationalDatabaseResponse))]
[AWSCmdletOutput("Amazon.Lightsail.Model.Operation or Amazon.Lightsail.Model.CreateRelationalDatabaseResponse",
"This cmdlet returns a collection of Amazon.Lightsail.Model.Operation objects.",
"The service call response (type Amazon.Lightsail.Model.CreateRelationalDatabaseResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewLSRelationalDatabaseCmdlet : AmazonLightsailClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
#region Parameter AvailabilityZone
///
///
/// The Availability Zone in which to create your new database. Use the us-east-2a
/// case-sensitive format.You can get a list of Availability Zones by using the get regions
operation.
/// Be sure to add the include relational database Availability Zones
parameter
/// to your request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String AvailabilityZone { get; set; }
#endregion
#region Parameter MasterDatabaseName
///
///
/// The meaning of this parameter differs according to the database engine you use.MySQLThe name of the database to create when the Lightsail database resource is created.
/// If this parameter isn't specified, no database is created in the database resource.Constraints:- Must contain 1 to 64 letters or numbers.
- Must begin with a letter. Subsequent characters can be letters, underscores, or digits
/// (0- 9).
- Can't be a word reserved by the specified database engine.For more information about reserved words in MySQL, see the Keywords and Reserved
/// Words articles for MySQL
/// 5.6, MySQL 5.7,
/// and MySQL 8.0.
PostgreSQLThe name of the database to create when the Lightsail database resource is created.
/// If this parameter isn't specified, a database named postgres
is created
/// in the database resource.Constraints:- Must contain 1 to 63 letters or numbers.
- Must begin with a letter. Subsequent characters can be letters, underscores, or digits
/// (0- 9).
- Can't be a word reserved by the specified database engine.For more information about reserved words in PostgreSQL, see the SQL Key Words articles
/// for PostgreSQL
/// 9.6, PostgreSQL
/// 10, PostgreSQL
/// 11, and PostgreSQL
/// 12.
///
///
#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 MasterDatabaseName { get; set; }
#endregion
#region Parameter MasterUsername
///
///
/// The name for the master user.MySQLConstraints:- Required for MySQL.
- Must be 1 to 16 letters or numbers. Can contain underscores.
- First character must be a letter.
- Can't be a reserved word for the chosen database engine.For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and
/// Reserved Words articles for MySQL
/// 5.6, MySQL 5.7,
/// or MySQL 8.0.
PostgreSQLConstraints:- Required for PostgreSQL.
- Must be 1 to 63 letters or numbers. Can contain underscores.
- First character must be a letter.
- Can't be a reserved word for the chosen database engine.For more information about reserved words in MySQL 5.6 or 5.7, see the Keywords and
/// Reserved Words articles for PostgreSQL
/// 9.6, PostgreSQL
/// 10, PostgreSQL
/// 11, and PostgreSQL
/// 12.
///
///
#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 MasterUsername { get; set; }
#endregion
#region Parameter MasterUserPassword
///
///
/// The password for the master user. The password can include any printable ASCII character
/// except "/", """, or "@". It cannot contain spaces.MySQLConstraints: Must contain from 8 to 41 characters.PostgreSQLConstraints: Must contain from 8 to 128 characters.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String MasterUserPassword { get; set; }
#endregion
#region Parameter PreferredBackupWindow
///
///
/// The daily time range during which automated backups are created for your new database
/// if automated backups are enabled.The default is a 30-minute window selected at random from an 8-hour block of time
/// for each AWS Region. For more information about the preferred backup window time blocks
/// for each region, see the Working
/// With Backups guide in the Amazon Relational Database Service documentation.Constraints:- Must be in the
hh24:mi-hh24:mi
format.Example: 16:00-16:30
- Specified in Coordinated Universal Time (UTC).
- Must not conflict with the preferred maintenance window.
- Must be at least 30 minutes.
///
///
[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 on your new database.The default is a 30-minute window selected at random from an 8-hour block of time
/// for each AWS Region, occurring on a random day of the week.Constraints:- Must be in the
ddd:hh24:mi-ddd:hh24:mi
format. - Valid days: Mon, Tue, Wed, Thu, Fri, Sat, Sun.
- Must be at least 30 minutes.
- Specified in Coordinated Universal Time (UTC).
- Example:
Tue:17:00-Tue:17:30
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PreferredMaintenanceWindow { get; set; }
#endregion
#region Parameter PubliclyAccessible
///
///
/// Specifies the accessibility options for your new database. A value of true
/// specifies a database that is available to resources outside of your Lightsail account.
/// A value of false
specifies a database that is available only to your
/// Lightsail resources in the same region as your database.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? PubliclyAccessible { get; set; }
#endregion
#region Parameter RelationalDatabaseBlueprintId
///
///
/// The blueprint ID for your new database. A blueprint describes the major engine version
/// of a database.You can get a list of database blueprints IDs by using the get relational database
/// blueprints
operation.
///
///
#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 RelationalDatabaseBlueprintId { get; set; }
#endregion
#region Parameter RelationalDatabaseBundleId
///
///
/// The bundle ID for your new database. A bundle describes the performance specifications
/// for your database.You can get a list of database bundle IDs by using the get relational database
/// bundles
operation.
///
///
#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 RelationalDatabaseBundleId { get; set; }
#endregion
#region Parameter RelationalDatabaseName
///
///
/// The name to use for your new Lightsail database resource.Constraints:- Must contain from 2 to 255 alphanumeric characters, or hyphens.
- The first and last character must be a letter or number.
///
///
#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 RelationalDatabaseName { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tag keys and optional values to add to the resource during create.Use the TagResource
action to tag a resource after it's created.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.Lightsail.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'Operations'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Lightsail.Model.CreateRelationalDatabaseResponse).
/// Specifying the name of a property of type Amazon.Lightsail.Model.CreateRelationalDatabaseResponse 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; } = "Operations";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the RelationalDatabaseName parameter.
/// The -PassThru parameter is deprecated, use -Select '^RelationalDatabaseName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^RelationalDatabaseName' 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.RelationalDatabaseName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-LSRelationalDatabase (CreateRelationalDatabase)"))
{
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.RelationalDatabaseName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AvailabilityZone = this.AvailabilityZone;
context.MasterDatabaseName = this.MasterDatabaseName;
#if MODULAR
if (this.MasterDatabaseName == null && ParameterWasBound(nameof(this.MasterDatabaseName)))
{
WriteWarning("You are passing $null as a value for parameter MasterDatabaseName 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.MasterUsername = this.MasterUsername;
#if MODULAR
if (this.MasterUsername == null && ParameterWasBound(nameof(this.MasterUsername)))
{
WriteWarning("You are passing $null as a value for parameter MasterUsername 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.MasterUserPassword = this.MasterUserPassword;
context.PreferredBackupWindow = this.PreferredBackupWindow;
context.PreferredMaintenanceWindow = this.PreferredMaintenanceWindow;
context.PubliclyAccessible = this.PubliclyAccessible;
context.RelationalDatabaseBlueprintId = this.RelationalDatabaseBlueprintId;
#if MODULAR
if (this.RelationalDatabaseBlueprintId == null && ParameterWasBound(nameof(this.RelationalDatabaseBlueprintId)))
{
WriteWarning("You are passing $null as a value for parameter RelationalDatabaseBlueprintId 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.RelationalDatabaseBundleId = this.RelationalDatabaseBundleId;
#if MODULAR
if (this.RelationalDatabaseBundleId == null && ParameterWasBound(nameof(this.RelationalDatabaseBundleId)))
{
WriteWarning("You are passing $null as a value for parameter RelationalDatabaseBundleId 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.RelationalDatabaseName = this.RelationalDatabaseName;
#if MODULAR
if (this.RelationalDatabaseName == null && ParameterWasBound(nameof(this.RelationalDatabaseName)))
{
WriteWarning("You are passing $null as a value for parameter RelationalDatabaseName 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);
}
// 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.Lightsail.Model.CreateRelationalDatabaseRequest();
if (cmdletContext.AvailabilityZone != null)
{
request.AvailabilityZone = cmdletContext.AvailabilityZone;
}
if (cmdletContext.MasterDatabaseName != null)
{
request.MasterDatabaseName = cmdletContext.MasterDatabaseName;
}
if (cmdletContext.MasterUsername != null)
{
request.MasterUsername = cmdletContext.MasterUsername;
}
if (cmdletContext.MasterUserPassword != null)
{
request.MasterUserPassword = cmdletContext.MasterUserPassword;
}
if (cmdletContext.PreferredBackupWindow != null)
{
request.PreferredBackupWindow = cmdletContext.PreferredBackupWindow;
}
if (cmdletContext.PreferredMaintenanceWindow != null)
{
request.PreferredMaintenanceWindow = cmdletContext.PreferredMaintenanceWindow;
}
if (cmdletContext.PubliclyAccessible != null)
{
request.PubliclyAccessible = cmdletContext.PubliclyAccessible.Value;
}
if (cmdletContext.RelationalDatabaseBlueprintId != null)
{
request.RelationalDatabaseBlueprintId = cmdletContext.RelationalDatabaseBlueprintId;
}
if (cmdletContext.RelationalDatabaseBundleId != null)
{
request.RelationalDatabaseBundleId = cmdletContext.RelationalDatabaseBundleId;
}
if (cmdletContext.RelationalDatabaseName != null)
{
request.RelationalDatabaseName = cmdletContext.RelationalDatabaseName;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
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.Lightsail.Model.CreateRelationalDatabaseResponse CallAWSServiceOperation(IAmazonLightsail client, Amazon.Lightsail.Model.CreateRelationalDatabaseRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Lightsail", "CreateRelationalDatabase");
try
{
#if DESKTOP
return client.CreateRelationalDatabase(request);
#elif CORECLR
return client.CreateRelationalDatabaseAsync(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 AvailabilityZone { get; set; }
public System.String MasterDatabaseName { get; set; }
public System.String MasterUsername { get; set; }
public System.String MasterUserPassword { get; set; }
public System.String PreferredBackupWindow { get; set; }
public System.String PreferredMaintenanceWindow { get; set; }
public System.Boolean? PubliclyAccessible { get; set; }
public System.String RelationalDatabaseBlueprintId { get; set; }
public System.String RelationalDatabaseBundleId { get; set; }
public System.String RelationalDatabaseName { get; set; }
public List Tag { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.Operations;
}
}
}