/******************************************************************************* * 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.DataSync; using Amazon.DataSync.Model; namespace Amazon.PowerShell.Cmdlets.DSYN { /// /// Creates an endpoint for an object storage system that DataSync can access for a transfer. /// For more information, see Creating /// a location for object storage. /// [Cmdlet("New", "DSYNLocationObjectStorage", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS DataSync CreateLocationObjectStorage API operation.", Operation = new[] {"CreateLocationObjectStorage"}, SelectReturnType = typeof(Amazon.DataSync.Model.CreateLocationObjectStorageResponse))] [AWSCmdletOutput("System.String or Amazon.DataSync.Model.CreateLocationObjectStorageResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.DataSync.Model.CreateLocationObjectStorageResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewDSYNLocationObjectStorageCmdlet : AmazonDataSyncClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; #region Parameter BucketAccessKey /// /// /// Specifies the access key (for example, a user name) if credentials are required to /// authenticate with the object storage server. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String BucketAccessKey { get; set; } #endregion #region Parameter AgentArn /// /// /// Specifies the Amazon Resource Names (ARNs) of the DataSync agents that can securely /// connect with your location. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyCollection] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [Alias("AgentArns")] public System.String[] AgentArn { get; set; } #endregion #region Parameter BucketName /// /// /// Specifies the name of the object storage bucket involved in the transfer. /// /// #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 BucketName { get; set; } #endregion #region Parameter BucketSecretKey /// /// /// Specifies the secret key (for example, a password) if credentials are required to /// authenticate with the object storage server. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String BucketSecretKey { get; set; } #endregion #region Parameter ServerCertificate /// /// /// Specifies a file with the certificates that are used to sign the object storage server's /// certificate (for example, file:///home/user/.ssh/storage_sys_certificate.pem). /// The file you specify must include the following:The file can be up to 32768 bytes (before base64 encoding).To use this parameter, configure ServerProtocol to HTTPS. /// /// The cmdlet will automatically convert the supplied parameter of type string, string[], System.IO.FileInfo or System.IO.Stream to byte[] before supplying it to the service. /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Amazon.PowerShell.Common.MemoryStreamParameterConverter] public byte[] ServerCertificate { get; set; } #endregion #region Parameter ServerHostname /// /// /// Specifies the domain name or IP address of the object storage server. A DataSync agent /// uses this hostname to mount the object storage server in a network. /// /// #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 ServerHostname { get; set; } #endregion #region Parameter ServerPort /// /// /// Specifies the port that your object storage server accepts inbound network traffic /// on (for example, port 443). /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ServerPort { get; set; } #endregion #region Parameter ServerProtocol /// /// /// Specifies the protocol that your object storage server uses to communicate. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.DataSync.ObjectStorageServerProtocol")] public Amazon.DataSync.ObjectStorageServerProtocol ServerProtocol { get; set; } #endregion #region Parameter Subdirectory /// /// /// Specifies the object prefix for your object storage server. If this is a source location, /// DataSync only copies objects with this prefix. If this is a destination location, /// DataSync writes all objects with this prefix. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Subdirectory { get; set; } #endregion #region Parameter Tag /// /// /// Specifies the key-value pair that represents a tag that you want to add to the resource. /// Tags can help you manage, filter, and search for your resources. We recommend creating /// a name tag for your location. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DataSync.Model.TagListEntry[] Tag { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is 'LocationArn'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DataSync.Model.CreateLocationObjectStorageResponse). /// Specifying the name of a property of type Amazon.DataSync.Model.CreateLocationObjectStorageResponse 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; } = "LocationArn"; #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.BucketName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DSYNLocationObjectStorage (CreateLocationObjectStorage)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); } context.BucketAccessKey = this.BucketAccessKey; if (this.AgentArn != null) { context.AgentArn = new List(this.AgentArn); } #if MODULAR if (this.AgentArn == null && ParameterWasBound(nameof(this.AgentArn))) { WriteWarning("You are passing $null as a value for parameter AgentArn 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.BucketName = this.BucketName; #if MODULAR if (this.BucketName == null && ParameterWasBound(nameof(this.BucketName))) { WriteWarning("You are passing $null as a value for parameter BucketName 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.BucketSecretKey = this.BucketSecretKey; context.ServerCertificate = this.ServerCertificate; context.ServerHostname = this.ServerHostname; #if MODULAR if (this.ServerHostname == null && ParameterWasBound(nameof(this.ServerHostname))) { WriteWarning("You are passing $null as a value for parameter ServerHostname 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.ServerPort = this.ServerPort; context.ServerProtocol = this.ServerProtocol; context.Subdirectory = this.Subdirectory; 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) { System.IO.MemoryStream _ServerCertificateStream = null; try { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.DataSync.Model.CreateLocationObjectStorageRequest(); if (cmdletContext.BucketAccessKey != null) { request.AccessKey = cmdletContext.BucketAccessKey; } if (cmdletContext.AgentArn != null) { request.AgentArns = cmdletContext.AgentArn; } if (cmdletContext.BucketName != null) { request.BucketName = cmdletContext.BucketName; } if (cmdletContext.BucketSecretKey != null) { request.SecretKey = cmdletContext.BucketSecretKey; } if (cmdletContext.ServerCertificate != null) { _ServerCertificateStream = new System.IO.MemoryStream(cmdletContext.ServerCertificate); request.ServerCertificate = _ServerCertificateStream; } if (cmdletContext.ServerHostname != null) { request.ServerHostname = cmdletContext.ServerHostname; } if (cmdletContext.ServerPort != null) { request.ServerPort = cmdletContext.ServerPort.Value; } if (cmdletContext.ServerProtocol != null) { request.ServerProtocol = cmdletContext.ServerProtocol; } if (cmdletContext.Subdirectory != null) { request.Subdirectory = cmdletContext.Subdirectory; } 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; } finally { if( _ServerCertificateStream != null) { _ServerCertificateStream.Dispose(); } } } public ExecutorContext CreateContext() { return new CmdletContext(); } #endregion #region AWS Service Operation Call private Amazon.DataSync.Model.CreateLocationObjectStorageResponse CallAWSServiceOperation(IAmazonDataSync client, Amazon.DataSync.Model.CreateLocationObjectStorageRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS DataSync", "CreateLocationObjectStorage"); try { #if DESKTOP return client.CreateLocationObjectStorage(request); #elif CORECLR return client.CreateLocationObjectStorageAsync(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 BucketAccessKey { get; set; } public List AgentArn { get; set; } public System.String BucketName { get; set; } public System.String BucketSecretKey { get; set; } public byte[] ServerCertificate { get; set; } public System.String ServerHostname { get; set; } public System.Int32? ServerPort { get; set; } public Amazon.DataSync.ObjectStorageServerProtocol ServerProtocol { get; set; } public System.String Subdirectory { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.LocationArn; } } }