/*******************************************************************************
* 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.StepFunctions;
using Amazon.StepFunctions.Model;
namespace Amazon.PowerShell.Cmdlets.SFN
{
///
/// Updates an existing state machine by modifying its definition
, roleArn
,
/// or loggingConfiguration
. Running executions will continue to use the
/// previous definition
and roleArn
. You must include at least
/// one of definition
or roleArn
or you will receive a MissingRequiredParameter
/// error.
///
///
///
/// A qualified state machine ARN refers to a Distributed Map state defined within
/// a state machine. For example, the qualified state machine ARN arn:partition:states:region:account-id:stateMachine:stateMachineName/mapStateLabel
/// refers to a Distributed Map state with a label mapStateLabel
in
/// the state machine named stateMachineName
.
///
/// A qualified state machine ARN can either refer to a Distributed Map state defined
/// within a state machine, a version ARN, or an alias ARN.
///
/// The following are some examples of qualified and unqualified state machine ARNs:
/// -
/// The following qualified state machine ARN refers to a Distributed Map state
/// with a label
mapStateLabel
in a state machine named myStateMachine
.
/// arn:partition:states:region:account-id:stateMachine:myStateMachine/mapStateLabel
/// If you provide a qualified state machine ARN that refers to a Distributed Map state,
/// the request fails with ValidationException
.
/// -
/// The following qualified state machine ARN refers to an alias named
PROD
.
/// arn:<partition>:states:<region>:<account-id>:stateMachine:<myStateMachine:PROD>
/// If you provide a qualified state machine ARN that refers to a version ARN or an alias
/// ARN, the request starts execution for that version or alias.
/// -
/// The following unqualified state machine ARN refers to a state machine named
myStateMachine
.
/// arn:<partition>:states:<region>:<account-id>:stateMachine:<myStateMachine>
/// After you update your state machine, you can set the publish
parameter
/// to true
in the same action to publish a new version.
/// This way, you can opt-in to strict versioning of your state machine.
///
/// Step Functions assigns monotonically increasing integers for state machine versions,
/// starting at version number 1.
///
/// All StartExecution
calls within a few seconds use the updated definition
/// and roleArn
. Executions started immediately after you call UpdateStateMachine
/// may use the previous state machine definition
and roleArn
.
///
///
///
[Cmdlet("Update", "SFNStateMachine", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("System.DateTime")]
[AWSCmdlet("Calls the AWS Step Functions UpdateStateMachine API operation.", Operation = new[] {"UpdateStateMachine"}, SelectReturnType = typeof(Amazon.StepFunctions.Model.UpdateStateMachineResponse))]
[AWSCmdletOutput("System.DateTime or Amazon.StepFunctions.Model.UpdateStateMachineResponse",
"This cmdlet returns a System.DateTime object.",
"The service call response (type Amazon.StepFunctions.Model.UpdateStateMachineResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateSFNStateMachineCmdlet : AmazonStepFunctionsClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
#region Parameter Definition
///
///
/// The Amazon States Language definition of the state machine. See Amazon
/// States Language.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Definition { get; set; }
#endregion
#region Parameter LoggingConfiguration_Destination
///
///
/// An array of objects that describes where your execution history events will be logged.
/// Limited to size 1. Required, if your log level is not set to OFF
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LoggingConfiguration_Destinations")]
public Amazon.StepFunctions.Model.LogDestination[] LoggingConfiguration_Destination { get; set; }
#endregion
#region Parameter TracingConfiguration_Enabled
///
///
/// When set to true
, X-Ray tracing is enabled.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? TracingConfiguration_Enabled { get; set; }
#endregion
#region Parameter LoggingConfiguration_IncludeExecutionData
///
///
/// Determines whether execution data is included in your log. When set to false
,
/// data is excluded.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? LoggingConfiguration_IncludeExecutionData { get; set; }
#endregion
#region Parameter LoggingConfiguration_Level
///
///
/// Defines which category of execution history events are logged.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.StepFunctions.LogLevel")]
public Amazon.StepFunctions.LogLevel LoggingConfiguration_Level { get; set; }
#endregion
#region Parameter Publish
///
///
/// Specifies whether the state machine version is published. The default is false
.
/// To publish a version after updating the state machine, set publish
to
/// true
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? Publish { get; set; }
#endregion
#region Parameter RoleArn
///
///
/// The Amazon Resource Name (ARN) of the IAM role of the state machine.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String RoleArn { get; set; }
#endregion
#region Parameter StateMachineArn
///
///
/// The Amazon Resource Name (ARN) of the state machine.
///
///
#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 StateMachineArn { get; set; }
#endregion
#region Parameter VersionDescription
///
///
/// An optional description of the state machine version to publish.You can only specify the versionDescription
parameter if you've set publish
/// to true
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String VersionDescription { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is 'UpdateDate'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.StepFunctions.Model.UpdateStateMachineResponse).
/// Specifying the name of a property of type Amazon.StepFunctions.Model.UpdateStateMachineResponse 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; } = "UpdateDate";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the StateMachineArn parameter.
/// The -PassThru parameter is deprecated, use -Select '^StateMachineArn' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^StateMachineArn' 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.StateMachineArn), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-SFNStateMachine (UpdateStateMachine)"))
{
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.StateMachineArn;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.Definition = this.Definition;
if (this.LoggingConfiguration_Destination != null)
{
context.LoggingConfiguration_Destination = new List(this.LoggingConfiguration_Destination);
}
context.LoggingConfiguration_IncludeExecutionData = this.LoggingConfiguration_IncludeExecutionData;
context.LoggingConfiguration_Level = this.LoggingConfiguration_Level;
context.Publish = this.Publish;
context.RoleArn = this.RoleArn;
context.StateMachineArn = this.StateMachineArn;
#if MODULAR
if (this.StateMachineArn == null && ParameterWasBound(nameof(this.StateMachineArn)))
{
WriteWarning("You are passing $null as a value for parameter StateMachineArn 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.TracingConfiguration_Enabled = this.TracingConfiguration_Enabled;
context.VersionDescription = this.VersionDescription;
// 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.StepFunctions.Model.UpdateStateMachineRequest();
if (cmdletContext.Definition != null)
{
request.Definition = cmdletContext.Definition;
}
// populate LoggingConfiguration
var requestLoggingConfigurationIsNull = true;
request.LoggingConfiguration = new Amazon.StepFunctions.Model.LoggingConfiguration();
List requestLoggingConfiguration_loggingConfiguration_Destination = null;
if (cmdletContext.LoggingConfiguration_Destination != null)
{
requestLoggingConfiguration_loggingConfiguration_Destination = cmdletContext.LoggingConfiguration_Destination;
}
if (requestLoggingConfiguration_loggingConfiguration_Destination != null)
{
request.LoggingConfiguration.Destinations = requestLoggingConfiguration_loggingConfiguration_Destination;
requestLoggingConfigurationIsNull = false;
}
System.Boolean? requestLoggingConfiguration_loggingConfiguration_IncludeExecutionData = null;
if (cmdletContext.LoggingConfiguration_IncludeExecutionData != null)
{
requestLoggingConfiguration_loggingConfiguration_IncludeExecutionData = cmdletContext.LoggingConfiguration_IncludeExecutionData.Value;
}
if (requestLoggingConfiguration_loggingConfiguration_IncludeExecutionData != null)
{
request.LoggingConfiguration.IncludeExecutionData = requestLoggingConfiguration_loggingConfiguration_IncludeExecutionData.Value;
requestLoggingConfigurationIsNull = false;
}
Amazon.StepFunctions.LogLevel requestLoggingConfiguration_loggingConfiguration_Level = null;
if (cmdletContext.LoggingConfiguration_Level != null)
{
requestLoggingConfiguration_loggingConfiguration_Level = cmdletContext.LoggingConfiguration_Level;
}
if (requestLoggingConfiguration_loggingConfiguration_Level != null)
{
request.LoggingConfiguration.Level = requestLoggingConfiguration_loggingConfiguration_Level;
requestLoggingConfigurationIsNull = false;
}
// determine if request.LoggingConfiguration should be set to null
if (requestLoggingConfigurationIsNull)
{
request.LoggingConfiguration = null;
}
if (cmdletContext.Publish != null)
{
request.Publish = cmdletContext.Publish.Value;
}
if (cmdletContext.RoleArn != null)
{
request.RoleArn = cmdletContext.RoleArn;
}
if (cmdletContext.StateMachineArn != null)
{
request.StateMachineArn = cmdletContext.StateMachineArn;
}
// populate TracingConfiguration
var requestTracingConfigurationIsNull = true;
request.TracingConfiguration = new Amazon.StepFunctions.Model.TracingConfiguration();
System.Boolean? requestTracingConfiguration_tracingConfiguration_Enabled = null;
if (cmdletContext.TracingConfiguration_Enabled != null)
{
requestTracingConfiguration_tracingConfiguration_Enabled = cmdletContext.TracingConfiguration_Enabled.Value;
}
if (requestTracingConfiguration_tracingConfiguration_Enabled != null)
{
request.TracingConfiguration.Enabled = requestTracingConfiguration_tracingConfiguration_Enabled.Value;
requestTracingConfigurationIsNull = false;
}
// determine if request.TracingConfiguration should be set to null
if (requestTracingConfigurationIsNull)
{
request.TracingConfiguration = null;
}
if (cmdletContext.VersionDescription != null)
{
request.VersionDescription = cmdletContext.VersionDescription;
}
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.StepFunctions.Model.UpdateStateMachineResponse CallAWSServiceOperation(IAmazonStepFunctions client, Amazon.StepFunctions.Model.UpdateStateMachineRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Step Functions", "UpdateStateMachine");
try
{
#if DESKTOP
return client.UpdateStateMachine(request);
#elif CORECLR
return client.UpdateStateMachineAsync(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 Definition { get; set; }
public List LoggingConfiguration_Destination { get; set; }
public System.Boolean? LoggingConfiguration_IncludeExecutionData { get; set; }
public Amazon.StepFunctions.LogLevel LoggingConfiguration_Level { get; set; }
public System.Boolean? Publish { get; set; }
public System.String RoleArn { get; set; }
public System.String StateMachineArn { get; set; }
public System.Boolean? TracingConfiguration_Enabled { get; set; }
public System.String VersionDescription { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.UpdateDate;
}
}
}