/******************************************************************************* * 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.LocationService; using Amazon.LocationService.Model; namespace Amazon.PowerShell.Cmdlets.LOC { /// /// Creates an API key resource in your Amazon Web Services account, which lets you grant /// actions for Amazon Location resources to the API key bearer. /// /// /// For more information, see Using /// API keys. /// /// [Cmdlet("New", "LOCKey", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.LocationService.Model.CreateKeyResponse")] [AWSCmdlet("Calls the Amazon Location Service CreateKey API operation.", Operation = new[] {"CreateKey"}, SelectReturnType = typeof(Amazon.LocationService.Model.CreateKeyResponse))] [AWSCmdletOutput("Amazon.LocationService.Model.CreateKeyResponse", "This cmdlet returns an Amazon.LocationService.Model.CreateKeyResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewLOCKeyCmdlet : AmazonLocationServiceClientCmdlet, IExecutor { protected override bool IsSensitiveResponse { get; set; } = true; #region Parameter Restrictions_AllowAction /// /// /// A list of allowed actions that an API key resource grants permissions to perform. /// You must have at least one action for each type of resource. For example, if you have /// a place resource, you must include at least one place action.The following are valid values for the actions.You must use these strings exactly. For example, to provide access to map rendering, /// the only valid action is geo:GetMap* as an input to the list. ["geo:GetMap*"] /// is valid but ["geo:GetMapTile"] is not. Similarly, you cannot use ["geo:SearchPlaceIndexFor*"] /// - you must list each of the Place actions separately. /// /// #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("Restrictions_AllowActions")] public System.String[] Restrictions_AllowAction { get; set; } #endregion #region Parameter Restrictions_AllowReferer /// /// /// An optional list of allowed HTTP referers for which requests must originate from. /// Requests using this API key from other domains will not be allowed.Requirements: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Restrictions_AllowReferers")] public System.String[] Restrictions_AllowReferer { get; set; } #endregion #region Parameter Restrictions_AllowResource /// /// /// A list of allowed resource ARNs that a API key bearer can perform actions on.For more information about ARN format, see Amazon /// Resource Names (ARNs). /// /// #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("Restrictions_AllowResources")] public System.String[] Restrictions_AllowResource { get; set; } #endregion #region Parameter Description /// /// /// An optional description for the API key resource. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter ExpireTime /// /// /// The optional timestamp for when the API key resource will expire in /// ISO 8601 format: YYYY-MM-DDThh:mm:ss.sssZ. One of NoExpiry /// or ExpireTime must be set. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.DateTime? ExpireTime { get; set; } #endregion #region Parameter KeyName /// /// /// A custom name for the API key resource.Requirements: /// /// #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 KeyName { get; set; } #endregion #region Parameter NoExpiry /// /// /// Optionally set to true to set no expiration time for the API key. One /// of NoExpiry or ExpireTime must be set. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? NoExpiry { get; set; } #endregion #region Parameter Tag /// /// /// Applies one or more tags to the map resource. A tag is a key-value pair that helps /// manage, identify, search, and filter your resources by labelling them.Format: "key" : "value"Restrictions: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public System.Collections.Hashtable Tag { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The default value is '*'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.LocationService.Model.CreateKeyResponse). /// Specifying the name of a property of type Amazon.LocationService.Model.CreateKeyResponse 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; } = "*"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the KeyName parameter. /// The -PassThru parameter is deprecated, use -Select '^KeyName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^KeyName' 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.KeyName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-LOCKey (CreateKey)")) { 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.KeyName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.Description = this.Description; context.ExpireTime = this.ExpireTime; context.KeyName = this.KeyName; #if MODULAR if (this.KeyName == null && ParameterWasBound(nameof(this.KeyName))) { WriteWarning("You are passing $null as a value for parameter KeyName 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.NoExpiry = this.NoExpiry; if (this.Restrictions_AllowAction != null) { context.Restrictions_AllowAction = new List(this.Restrictions_AllowAction); } #if MODULAR if (this.Restrictions_AllowAction == null && ParameterWasBound(nameof(this.Restrictions_AllowAction))) { WriteWarning("You are passing $null as a value for parameter Restrictions_AllowAction 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.Restrictions_AllowReferer != null) { context.Restrictions_AllowReferer = new List(this.Restrictions_AllowReferer); } if (this.Restrictions_AllowResource != null) { context.Restrictions_AllowResource = new List(this.Restrictions_AllowResource); } #if MODULAR if (this.Restrictions_AllowResource == null && ParameterWasBound(nameof(this.Restrictions_AllowResource))) { WriteWarning("You are passing $null as a value for parameter Restrictions_AllowResource 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 Dictionary(StringComparer.Ordinal); foreach (var hashKey in this.Tag.Keys) { context.Tag.Add((String)hashKey, (String)(this.Tag[hashKey])); } } // 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.LocationService.Model.CreateKeyRequest(); if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.ExpireTime != null) { request.ExpireTime = cmdletContext.ExpireTime.Value; } if (cmdletContext.KeyName != null) { request.KeyName = cmdletContext.KeyName; } if (cmdletContext.NoExpiry != null) { request.NoExpiry = cmdletContext.NoExpiry.Value; } // populate Restrictions var requestRestrictionsIsNull = true; request.Restrictions = new Amazon.LocationService.Model.ApiKeyRestrictions(); List requestRestrictions_restrictions_AllowAction = null; if (cmdletContext.Restrictions_AllowAction != null) { requestRestrictions_restrictions_AllowAction = cmdletContext.Restrictions_AllowAction; } if (requestRestrictions_restrictions_AllowAction != null) { request.Restrictions.AllowActions = requestRestrictions_restrictions_AllowAction; requestRestrictionsIsNull = false; } List requestRestrictions_restrictions_AllowReferer = null; if (cmdletContext.Restrictions_AllowReferer != null) { requestRestrictions_restrictions_AllowReferer = cmdletContext.Restrictions_AllowReferer; } if (requestRestrictions_restrictions_AllowReferer != null) { request.Restrictions.AllowReferers = requestRestrictions_restrictions_AllowReferer; requestRestrictionsIsNull = false; } List requestRestrictions_restrictions_AllowResource = null; if (cmdletContext.Restrictions_AllowResource != null) { requestRestrictions_restrictions_AllowResource = cmdletContext.Restrictions_AllowResource; } if (requestRestrictions_restrictions_AllowResource != null) { request.Restrictions.AllowResources = requestRestrictions_restrictions_AllowResource; requestRestrictionsIsNull = false; } // determine if request.Restrictions should be set to null if (requestRestrictionsIsNull) { request.Restrictions = null; } 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.LocationService.Model.CreateKeyResponse CallAWSServiceOperation(IAmazonLocationService client, Amazon.LocationService.Model.CreateKeyRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Location Service", "CreateKey"); try { #if DESKTOP return client.CreateKey(request); #elif CORECLR return client.CreateKeyAsync(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.DateTime? ExpireTime { get; set; } public System.String KeyName { get; set; } public System.Boolean? NoExpiry { get; set; } public List Restrictions_AllowAction { get; set; } public List Restrictions_AllowReferer { get; set; } public List Restrictions_AllowResource { get; set; } public Dictionary Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }