/******************************************************************************* * 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.StorageGateway; using Amazon.StorageGateway.Model; namespace Amazon.PowerShell.Cmdlets.SG { /// /// Adds a file gateway to an Active Directory domain. This operation is only supported /// for file gateways that support the SMB file protocol. /// [Cmdlet("Join", "SGDomain", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS Storage Gateway JoinDomain API operation.", Operation = new[] {"JoinDomain"}, SelectReturnType = typeof(Amazon.StorageGateway.Model.JoinDomainResponse))] [AWSCmdletOutput("System.String or Amazon.StorageGateway.Model.JoinDomainResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.StorageGateway.Model.JoinDomainResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class JoinSGDomainCmdlet : AmazonStorageGatewayClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; #region Parameter DomainController /// /// /// List of IPv4 addresses, NetBIOS names, or host names of your domain server. If you /// need to specify the port number include it after the colon (“:”). For example, mydc.mydomain.com:389. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("DomainControllers")] public System.String[] DomainController { get; set; } #endregion #region Parameter DomainName /// /// /// The name of the domain that you want the gateway to join. /// /// #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 DomainName { get; set; } #endregion #region Parameter GatewayARN /// /// /// The Amazon Resource Name (ARN) of the gateway. Use the ListGateways operation /// to return a list of gateways for your account and Amazon Web Services Region. /// /// #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 GatewayARN { get; set; } #endregion #region Parameter OrganizationalUnit /// /// /// The organizational unit (OU) is a container in an Active Directory that can hold users, /// groups, computers, and other OUs and this parameter specifies the OU that the gateway /// will join within the AD domain. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String OrganizationalUnit { get; set; } #endregion #region Parameter Password /// /// /// Sets the password of the user who has permission to add the gateway to the Active /// Directory domain. /// /// #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 Password { get; set; } #endregion #region Parameter TimeoutInSecond /// /// /// Specifies the time in seconds, in which the JoinDomain operation must /// complete. The default is 20 seconds. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("TimeoutInSeconds")] public System.Int32? TimeoutInSecond { get; set; } #endregion #region Parameter UserName /// /// /// Sets the user name of user who has permission to add the gateway to the Active Directory /// domain. The domain user account should be enabled to join computers to the domain. /// For example, you can use the domain administrator account or an account with delegated /// permissions to join computers to the domain. /// /// #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 UserName { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'GatewayARN'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.StorageGateway.Model.JoinDomainResponse). /// Specifying the name of a property of type Amazon.StorageGateway.Model.JoinDomainResponse 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; } = "GatewayARN"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the DomainName parameter. /// The -PassThru parameter is deprecated, use -Select '^DomainName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^DomainName' 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.DomainName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Join-SGDomain (JoinDomain)")) { 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.DomainName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute if (this.DomainController != null) { context.DomainController = new List(this.DomainController); } context.DomainName = this.DomainName; #if MODULAR if (this.DomainName == null && ParameterWasBound(nameof(this.DomainName))) { WriteWarning("You are passing $null as a value for parameter DomainName 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.GatewayARN = this.GatewayARN; #if MODULAR if (this.GatewayARN == null && ParameterWasBound(nameof(this.GatewayARN))) { WriteWarning("You are passing $null as a value for parameter GatewayARN 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.OrganizationalUnit = this.OrganizationalUnit; 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.TimeoutInSecond = this.TimeoutInSecond; context.UserName = this.UserName; #if MODULAR if (this.UserName == null && ParameterWasBound(nameof(this.UserName))) { WriteWarning("You are passing $null as a value for parameter UserName 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.StorageGateway.Model.JoinDomainRequest(); if (cmdletContext.DomainController != null) { request.DomainControllers = cmdletContext.DomainController; } if (cmdletContext.DomainName != null) { request.DomainName = cmdletContext.DomainName; } if (cmdletContext.GatewayARN != null) { request.GatewayARN = cmdletContext.GatewayARN; } if (cmdletContext.OrganizationalUnit != null) { request.OrganizationalUnit = cmdletContext.OrganizationalUnit; } if (cmdletContext.Password != null) { request.Password = cmdletContext.Password; } if (cmdletContext.TimeoutInSecond != null) { request.TimeoutInSeconds = cmdletContext.TimeoutInSecond.Value; } if (cmdletContext.UserName != null) { request.UserName = cmdletContext.UserName; } 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.StorageGateway.Model.JoinDomainResponse CallAWSServiceOperation(IAmazonStorageGateway client, Amazon.StorageGateway.Model.JoinDomainRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Storage Gateway", "JoinDomain"); try { #if DESKTOP return client.JoinDomain(request); #elif CORECLR return client.JoinDomainAsync(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 List DomainController { get; set; } public System.String DomainName { get; set; } public System.String GatewayARN { get; set; } public System.String OrganizationalUnit { get; set; } public System.String Password { get; set; } public System.Int32? TimeoutInSecond { get; set; } public System.String UserName { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.GatewayARN; } } }