/*******************************************************************************
* 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.Lambda;
using Amazon.Lambda.Model;
namespace Amazon.PowerShell.Cmdlets.LM
{
///
/// Updates the configuration for a Lambda function URL.
///
[Cmdlet("Update", "LMFunctionUrlConfig", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Lambda.Model.UpdateFunctionUrlConfigResponse")]
[AWSCmdlet("Calls the AWS Lambda UpdateFunctionUrlConfig API operation.", Operation = new[] {"UpdateFunctionUrlConfig"}, SelectReturnType = typeof(Amazon.Lambda.Model.UpdateFunctionUrlConfigResponse))]
[AWSCmdletOutput("Amazon.Lambda.Model.UpdateFunctionUrlConfigResponse",
"This cmdlet returns an Amazon.Lambda.Model.UpdateFunctionUrlConfigResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateLMFunctionUrlConfigCmdlet : AmazonLambdaClientCmdlet, IExecutor
{
#region Parameter Cors_AllowCredential
///
///
/// Whether to allow cookies or other credentials in requests to your function URL. The
/// default is false
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Cors_AllowCredentials")]
public System.Boolean? Cors_AllowCredential { get; set; }
#endregion
#region Parameter Cors_AllowHeader
///
///
/// The HTTP headers that origins can include in requests to your function URL. For example:
/// Date
, Keep-Alive
, X-Custom-Header
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Cors_AllowHeaders")]
public System.String[] Cors_AllowHeader { get; set; }
#endregion
#region Parameter Cors_AllowMethod
///
///
/// The HTTP methods that are allowed when calling your function URL. For example: GET
,
/// POST
, DELETE
, or the wildcard character (*
).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Cors_AllowMethods")]
public System.String[] Cors_AllowMethod { get; set; }
#endregion
#region Parameter Cors_AllowOrigin
///
///
/// The origins that can access your function URL. You can list any number of specific
/// origins, separated by a comma. For example: https://www.example.com
,
/// http://localhost:60905
.Alternatively, you can grant access to all origins using the wildcard character (*
).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Cors_AllowOrigins")]
public System.String[] Cors_AllowOrigin { get; set; }
#endregion
#region Parameter AuthType
///
///
/// The type of authentication that your function URL uses. Set to AWS_IAM
/// if you want to restrict access to authenticated users only. Set to NONE
/// if you want to bypass IAM authentication to create a public endpoint. For more information,
/// see Security
/// and auth model for Lambda function URLs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Lambda.FunctionUrlAuthType")]
public Amazon.Lambda.FunctionUrlAuthType AuthType { get; set; }
#endregion
#region Parameter Cors_ExposeHeader
///
///
/// The HTTP headers in your function response that you want to expose to origins that
/// call your function URL. For example: Date
, Keep-Alive
, X-Custom-Header
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Cors_ExposeHeaders")]
public System.String[] Cors_ExposeHeader { get; set; }
#endregion
#region Parameter FunctionName
///
///
/// Amazon.Lambda.Model.UpdateFunctionUrlConfigRequest.FunctionName
///
///
#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 FunctionName { get; set; }
#endregion
#region Parameter InvokeMode
///
///
/// Use one of the following options:BUFFERED
– This is the default option. Lambda invokes your function
/// using the Invoke
API operation. Invocation results are available when
/// the payload is complete. The maximum payload size is 6 MB.RESPONSE_STREAM
– Your function streams payload results as they become
/// available. Lambda invokes your function using the InvokeWithResponseStream
/// API operation. The maximum response payload size is 20 MB, however, you can request
/// a quota increase.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Lambda.InvokeMode")]
public Amazon.Lambda.InvokeMode InvokeMode { get; set; }
#endregion
#region Parameter Cors_MaxAge
///
///
/// The maximum amount of time, in seconds, that web browsers can cache results of a preflight
/// request. By default, this is set to 0
, which means that the browser doesn't
/// cache results.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? Cors_MaxAge { get; set; }
#endregion
#region Parameter Qualifier
///
///
/// The alias name.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Qualifier { 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.Lambda.Model.UpdateFunctionUrlConfigResponse).
/// Specifying the name of a property of type Amazon.Lambda.Model.UpdateFunctionUrlConfigResponse 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 FunctionName parameter.
/// The -PassThru parameter is deprecated, use -Select '^FunctionName' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^FunctionName' 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.FunctionName), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-LMFunctionUrlConfig (UpdateFunctionUrlConfig)"))
{
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.FunctionName;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AuthType = this.AuthType;
context.Cors_AllowCredential = this.Cors_AllowCredential;
if (this.Cors_AllowHeader != null)
{
context.Cors_AllowHeader = new List(this.Cors_AllowHeader);
}
if (this.Cors_AllowMethod != null)
{
context.Cors_AllowMethod = new List(this.Cors_AllowMethod);
}
if (this.Cors_AllowOrigin != null)
{
context.Cors_AllowOrigin = new List(this.Cors_AllowOrigin);
}
if (this.Cors_ExposeHeader != null)
{
context.Cors_ExposeHeader = new List(this.Cors_ExposeHeader);
}
context.Cors_MaxAge = this.Cors_MaxAge;
context.FunctionName = this.FunctionName;
#if MODULAR
if (this.FunctionName == null && ParameterWasBound(nameof(this.FunctionName)))
{
WriteWarning("You are passing $null as a value for parameter FunctionName 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.InvokeMode = this.InvokeMode;
context.Qualifier = this.Qualifier;
// 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.Lambda.Model.UpdateFunctionUrlConfigRequest();
if (cmdletContext.AuthType != null)
{
request.AuthType = cmdletContext.AuthType;
}
// populate Cors
var requestCorsIsNull = true;
request.Cors = new Amazon.Lambda.Model.Cors();
System.Boolean? requestCors_cors_AllowCredential = null;
if (cmdletContext.Cors_AllowCredential != null)
{
requestCors_cors_AllowCredential = cmdletContext.Cors_AllowCredential.Value;
}
if (requestCors_cors_AllowCredential != null)
{
request.Cors.AllowCredentials = requestCors_cors_AllowCredential.Value;
requestCorsIsNull = false;
}
List requestCors_cors_AllowHeader = null;
if (cmdletContext.Cors_AllowHeader != null)
{
requestCors_cors_AllowHeader = cmdletContext.Cors_AllowHeader;
}
if (requestCors_cors_AllowHeader != null)
{
request.Cors.AllowHeaders = requestCors_cors_AllowHeader;
requestCorsIsNull = false;
}
List requestCors_cors_AllowMethod = null;
if (cmdletContext.Cors_AllowMethod != null)
{
requestCors_cors_AllowMethod = cmdletContext.Cors_AllowMethod;
}
if (requestCors_cors_AllowMethod != null)
{
request.Cors.AllowMethods = requestCors_cors_AllowMethod;
requestCorsIsNull = false;
}
List requestCors_cors_AllowOrigin = null;
if (cmdletContext.Cors_AllowOrigin != null)
{
requestCors_cors_AllowOrigin = cmdletContext.Cors_AllowOrigin;
}
if (requestCors_cors_AllowOrigin != null)
{
request.Cors.AllowOrigins = requestCors_cors_AllowOrigin;
requestCorsIsNull = false;
}
List requestCors_cors_ExposeHeader = null;
if (cmdletContext.Cors_ExposeHeader != null)
{
requestCors_cors_ExposeHeader = cmdletContext.Cors_ExposeHeader;
}
if (requestCors_cors_ExposeHeader != null)
{
request.Cors.ExposeHeaders = requestCors_cors_ExposeHeader;
requestCorsIsNull = false;
}
System.Int32? requestCors_cors_MaxAge = null;
if (cmdletContext.Cors_MaxAge != null)
{
requestCors_cors_MaxAge = cmdletContext.Cors_MaxAge.Value;
}
if (requestCors_cors_MaxAge != null)
{
request.Cors.MaxAge = requestCors_cors_MaxAge.Value;
requestCorsIsNull = false;
}
// determine if request.Cors should be set to null
if (requestCorsIsNull)
{
request.Cors = null;
}
if (cmdletContext.FunctionName != null)
{
request.FunctionName = cmdletContext.FunctionName;
}
if (cmdletContext.InvokeMode != null)
{
request.InvokeMode = cmdletContext.InvokeMode;
}
if (cmdletContext.Qualifier != null)
{
request.Qualifier = cmdletContext.Qualifier;
}
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.Lambda.Model.UpdateFunctionUrlConfigResponse CallAWSServiceOperation(IAmazonLambda client, Amazon.Lambda.Model.UpdateFunctionUrlConfigRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Lambda", "UpdateFunctionUrlConfig");
try
{
#if DESKTOP
return client.UpdateFunctionUrlConfig(request);
#elif CORECLR
return client.UpdateFunctionUrlConfigAsync(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.Lambda.FunctionUrlAuthType AuthType { get; set; }
public System.Boolean? Cors_AllowCredential { get; set; }
public List Cors_AllowHeader { get; set; }
public List Cors_AllowMethod { get; set; }
public List Cors_AllowOrigin { get; set; }
public List Cors_ExposeHeader { get; set; }
public System.Int32? Cors_MaxAge { get; set; }
public System.String FunctionName { get; set; }
public Amazon.Lambda.InvokeMode InvokeMode { get; set; }
public System.String Qualifier { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}