/*******************************************************************************
* 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.DirectoryService;
using Amazon.DirectoryService.Model;
namespace Amazon.PowerShell.Cmdlets.DS
{
///
/// Creates a Simple AD directory. For more information, see Simple
/// Active Directory in the Directory Service Admin Guide.
///
///
///
/// Before you call CreateDirectory
, ensure that all of the required permissions
/// have been explicitly granted through a policy. For details about what permissions
/// are required to run the CreateDirectory
operation, see Directory
/// Service API Permissions: Actions, Resources, and Conditions Reference.
///
///
[Cmdlet("New", "DSDirectory", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.String")]
[AWSCmdlet("Calls the AWS Directory Service CreateDirectory API operation.", Operation = new[] {"CreateDirectory"}, SelectReturnType = typeof(Amazon.DirectoryService.Model.CreateDirectoryResponse))]
[AWSCmdletOutput("System.String or Amazon.DirectoryService.Model.CreateDirectoryResponse",
"This cmdlet returns a System.String object.",
"The service call response (type Amazon.DirectoryService.Model.CreateDirectoryResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewDSDirectoryCmdlet : AmazonDirectoryServiceClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
#region Parameter Description
///
///
/// A description for the directory.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Description { get; set; }
#endregion
#region Parameter Name
///
///
/// The fully qualified name for the directory, such as corp.example.com
.
///
///
#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 Name { get; set; }
#endregion
#region Parameter Password
///
///
/// The password for the directory administrator. The directory creation process creates
/// a directory administrator account with the user name Administrator
and
/// this password.If you need to change the password for the administrator account, you can use the
/// ResetUserPassword API call.The regex pattern for this string is made up of the following conditions:- Length (?=^.{8,64}$) – Must be between 8 and 64 characters
AND any 3 of the following password complexity rules required by Active Directory:- Numbers and upper case and lowercase (?=.*\d)(?=.*[A-Z])(?=.*[a-z])
- Numbers and special characters and lower case (?=.*\d)(?=.*[^A-Za-z0-9\s])(?=.*[a-z])
- Special characters and upper case and lower case (?=.*[^A-Za-z0-9\s])(?=.*[A-Z])(?=.*[a-z])
- Numbers and upper case and special characters (?=.*\d)(?=.*[A-Z])(?=.*[^A-Za-z0-9\s])
For additional information about how Active Directory passwords are enforced, see
/// Password
/// must meet complexity requirements on the Microsoft website.
///
///
#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 Password { get; set; }
#endregion
#region Parameter ShortName
///
///
/// The NetBIOS name of the directory, such as CORP
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ShortName { get; set; }
#endregion
#region Parameter Size
///
///
/// The size of the directory.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
[AWSConstantClassSource("Amazon.DirectoryService.DirectorySize")]
public Amazon.DirectoryService.DirectorySize Size { get; set; }
#endregion
#region Parameter VpcSettings_SubnetId
///
///
/// The identifiers of the subnets for the directory servers. The two subnets must be
/// in different Availability Zones. Directory Service creates a directory server and
/// a DNS server in each of these subnets.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("VpcSettings_SubnetIds")]
public System.String[] VpcSettings_SubnetId { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tags to be assigned to the Simple AD directory.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.DirectoryService.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter VpcSettings_VpcId
///
///
/// The identifier of the VPC in which to create the directory.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String VpcSettings_VpcId { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'DirectoryId'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DirectoryService.Model.CreateDirectoryResponse).
/// Specifying the name of a property of type Amazon.DirectoryService.Model.CreateDirectoryResponse 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; } = "DirectoryId";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the Name parameter.
/// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' 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.Name), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DSDirectory (CreateDirectory)"))
{
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.Name;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Description = this.Description;
context.Name = this.Name;
#if MODULAR
if (this.Name == null && ParameterWasBound(nameof(this.Name)))
{
WriteWarning("You are passing $null as a value for parameter Name 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.Password = this.Password;
#if MODULAR
if (this.Password == null && ParameterWasBound(nameof(this.Password)))
{
WriteWarning("You are passing $null as a value for parameter Password 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.ShortName = this.ShortName;
context.Size = this.Size;
#if MODULAR
if (this.Size == null && ParameterWasBound(nameof(this.Size)))
{
WriteWarning("You are passing $null as a value for parameter Size 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);
}
if (this.VpcSettings_SubnetId != null)
{
context.VpcSettings_SubnetId = new List(this.VpcSettings_SubnetId);
}
context.VpcSettings_VpcId = this.VpcSettings_VpcId;
// 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.DirectoryService.Model.CreateDirectoryRequest();
if (cmdletContext.Description != null)
{
request.Description = cmdletContext.Description;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
if (cmdletContext.Password != null)
{
request.Password = cmdletContext.Password;
}
if (cmdletContext.ShortName != null)
{
request.ShortName = cmdletContext.ShortName;
}
if (cmdletContext.Size != null)
{
request.Size = cmdletContext.Size;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
// populate VpcSettings
var requestVpcSettingsIsNull = true;
request.VpcSettings = new Amazon.DirectoryService.Model.DirectoryVpcSettings();
List requestVpcSettings_vpcSettings_SubnetId = null;
if (cmdletContext.VpcSettings_SubnetId != null)
{
requestVpcSettings_vpcSettings_SubnetId = cmdletContext.VpcSettings_SubnetId;
}
if (requestVpcSettings_vpcSettings_SubnetId != null)
{
request.VpcSettings.SubnetIds = requestVpcSettings_vpcSettings_SubnetId;
requestVpcSettingsIsNull = false;
}
System.String requestVpcSettings_vpcSettings_VpcId = null;
if (cmdletContext.VpcSettings_VpcId != null)
{
requestVpcSettings_vpcSettings_VpcId = cmdletContext.VpcSettings_VpcId;
}
if (requestVpcSettings_vpcSettings_VpcId != null)
{
request.VpcSettings.VpcId = requestVpcSettings_vpcSettings_VpcId;
requestVpcSettingsIsNull = false;
}
// determine if request.VpcSettings should be set to null
if (requestVpcSettingsIsNull)
{
request.VpcSettings = null;
}
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.DirectoryService.Model.CreateDirectoryResponse CallAWSServiceOperation(IAmazonDirectoryService client, Amazon.DirectoryService.Model.CreateDirectoryRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Directory Service", "CreateDirectory");
try
{
#if DESKTOP
return client.CreateDirectory(request);
#elif CORECLR
return client.CreateDirectoryAsync(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 Description { get; set; }
public System.String Name { get; set; }
public System.String Password { get; set; }
public System.String ShortName { get; set; }
public Amazon.DirectoryService.DirectorySize Size { get; set; }
public List Tag { get; set; }
public List VpcSettings_SubnetId { get; set; }
public System.String VpcSettings_VpcId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.DirectoryId;
}
}
}