/******************************************************************************* * 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 a Microsoft Azure Blob Storage container that DataSync can /// use as a transfer source or destination. /// /// /// /// Before you begin, make sure you know how /// DataSync accesses Azure Blob Storage and works with access /// tiers and blob /// types. You also need a DataSync /// agent that can connect to your container. /// /// [Cmdlet("New", "DSYNLocationAzureBlob", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS DataSync CreateLocationAzureBlob API operation.", Operation = new[] {"CreateLocationAzureBlob"}, SelectReturnType = typeof(Amazon.DataSync.Model.CreateLocationAzureBlobResponse))] [AWSCmdletOutput("System.String or Amazon.DataSync.Model.CreateLocationAzureBlobResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.DataSync.Model.CreateLocationAzureBlobResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewDSYNLocationAzureBlobCmdlet : AmazonDataSyncClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; #region Parameter AccessTier /// /// /// Specifies the access tier that you want your objects or files transferred into. This /// only applies when using the location as a transfer destination. For more information, /// see Access /// tiers. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.DataSync.AzureAccessTier")] public Amazon.DataSync.AzureAccessTier AccessTier { get; set; } #endregion #region Parameter AgentArn /// /// /// Specifies the Amazon Resource Name (ARN) of the DataSync agent that can connect with /// your Azure Blob Storage container.You can specify more than one agent. For more information, see Using /// multiple agents for your transfer. /// /// #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 AuthenticationType /// /// /// Specifies the authentication method DataSync uses to access your Azure Blob Storage. /// DataSync can access blob storage using a shared access signature (SAS). /// /// #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.DataSync.AzureBlobAuthenticationType")] public Amazon.DataSync.AzureBlobAuthenticationType AuthenticationType { get; set; } #endregion #region Parameter BlobType /// /// /// Specifies the type of blob that you want your objects or files to be when transferring /// them into Azure Blob Storage. Currently, DataSync only supports moving data into Azure /// Blob Storage as block blobs. For more information on blob types, see the Azure /// Blob Storage documentation. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.DataSync.AzureBlobType")] public Amazon.DataSync.AzureBlobType BlobType { get; set; } #endregion #region Parameter ContainerUrl /// /// /// Specifies the URL of the Azure Blob Storage container involved in your transfer. /// /// #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 ContainerUrl { get; set; } #endregion #region Parameter Subdirectory /// /// /// Specifies path segments if you want to limit your transfer to a virtual directory /// in your container (for example, /my/images). /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Subdirectory { get; set; } #endregion #region Parameter Tag /// /// /// Specifies labels that help you categorize, filter, and search for your Amazon Web /// Services resources. We recommend creating at least a name tag for your transfer location. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.DataSync.Model.TagListEntry[] Tag { get; set; } #endregion #region Parameter SasConfiguration_Token /// /// /// Specifies a SAS token that provides permissions at the Azure storage account, container, /// or folder level.The token is part of the SAS URI string that comes after the storage resource URI /// and a question mark. A token looks something like this:sp=r&st=2023-12-20T14:54:52Z&se=2023-12-20T22:54:52Z&spr=https&sv=2021-06-08&sr=c&sig=aBBKDWQvyuVcTPH9EBp%2FXTI9E%2F%2Fmq171%2BZU178wcwqU%3D /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SasConfiguration_Token { 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.CreateLocationAzureBlobResponse). /// Specifying the name of a property of type Amazon.DataSync.Model.CreateLocationAzureBlobResponse 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 PassThru /// /// Changes the cmdlet behavior to return the value passed to the ContainerUrl parameter. /// The -PassThru parameter is deprecated, use -Select '^ContainerUrl' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ContainerUrl' 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.ContainerUrl), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-DSYNLocationAzureBlob (CreateLocationAzureBlob)")) { 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.ContainerUrl; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.AccessTier = this.AccessTier; 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.AuthenticationType = this.AuthenticationType; #if MODULAR if (this.AuthenticationType == null && ParameterWasBound(nameof(this.AuthenticationType))) { WriteWarning("You are passing $null as a value for parameter AuthenticationType 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.BlobType = this.BlobType; context.ContainerUrl = this.ContainerUrl; #if MODULAR if (this.ContainerUrl == null && ParameterWasBound(nameof(this.ContainerUrl))) { WriteWarning("You are passing $null as a value for parameter ContainerUrl 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.SasConfiguration_Token = this.SasConfiguration_Token; 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) { var cmdletContext = context as CmdletContext; // create request var request = new Amazon.DataSync.Model.CreateLocationAzureBlobRequest(); if (cmdletContext.AccessTier != null) { request.AccessTier = cmdletContext.AccessTier; } if (cmdletContext.AgentArn != null) { request.AgentArns = cmdletContext.AgentArn; } if (cmdletContext.AuthenticationType != null) { request.AuthenticationType = cmdletContext.AuthenticationType; } if (cmdletContext.BlobType != null) { request.BlobType = cmdletContext.BlobType; } if (cmdletContext.ContainerUrl != null) { request.ContainerUrl = cmdletContext.ContainerUrl; } // populate SasConfiguration var requestSasConfigurationIsNull = true; request.SasConfiguration = new Amazon.DataSync.Model.AzureBlobSasConfiguration(); System.String requestSasConfiguration_sasConfiguration_Token = null; if (cmdletContext.SasConfiguration_Token != null) { requestSasConfiguration_sasConfiguration_Token = cmdletContext.SasConfiguration_Token; } if (requestSasConfiguration_sasConfiguration_Token != null) { request.SasConfiguration.Token = requestSasConfiguration_sasConfiguration_Token; requestSasConfigurationIsNull = false; } // determine if request.SasConfiguration should be set to null if (requestSasConfigurationIsNull) { request.SasConfiguration = null; } 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; } public ExecutorContext CreateContext() { return new CmdletContext(); } #endregion #region AWS Service Operation Call private Amazon.DataSync.Model.CreateLocationAzureBlobResponse CallAWSServiceOperation(IAmazonDataSync client, Amazon.DataSync.Model.CreateLocationAzureBlobRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS DataSync", "CreateLocationAzureBlob"); try { #if DESKTOP return client.CreateLocationAzureBlob(request); #elif CORECLR return client.CreateLocationAzureBlobAsync(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 Amazon.DataSync.AzureAccessTier AccessTier { get; set; } public List AgentArn { get; set; } public Amazon.DataSync.AzureBlobAuthenticationType AuthenticationType { get; set; } public Amazon.DataSync.AzureBlobType BlobType { get; set; } public System.String ContainerUrl { get; set; } public System.String SasConfiguration_Token { get; set; } public System.String Subdirectory { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.LocationArn; } } }