/*******************************************************************************
* 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.ServerlessApplicationRepository;
using Amazon.ServerlessApplicationRepository.Model;
namespace Amazon.PowerShell.Cmdlets.SAR
{
///
/// Creates an AWS CloudFormation change set for the given application.
///
[Cmdlet("New", "SARCloudFormationChangeSet", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse")]
[AWSCmdlet("Calls the AWS Serverless Application Repository CreateCloudFormationChangeSet API operation.", Operation = new[] {"CreateCloudFormationChangeSet"}, SelectReturnType = typeof(Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse))]
[AWSCmdletOutput("Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse",
"This cmdlet returns an Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewSARCloudFormationChangeSetCmdlet : AmazonServerlessApplicationRepositoryClientCmdlet, IExecutor
{
#region Parameter ApplicationId
///
///
/// The Amazon Resource Name (ARN) of the application.
///
///
#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 ApplicationId { get; set; }
#endregion
#region Parameter Capability
///
///
/// A list of values that you must specify before you can deploy certain applications.
/// Some applications might include resources that can affect permissions in your AWS
/// account, for example, by creating new AWS Identity and Access Management (IAM) users.
/// For those applications, you must explicitly acknowledge their capabilities by specifying
/// this parameter.The only valid values are CAPABILITY_IAM, CAPABILITY_NAMED_IAM, CAPABILITY_RESOURCE_POLICY,
/// and CAPABILITY_AUTO_EXPAND.The following resources require you to specify CAPABILITY_IAM or CAPABILITY_NAMED_IAM:
/// AWS::IAM::Group,
/// AWS::IAM::InstanceProfile,
/// AWS::IAM::Policy,
/// and AWS::IAM::Role.
/// If the application contains IAM resources, you can specify either CAPABILITY_IAM or
/// CAPABILITY_NAMED_IAM. If the application contains IAM resources with custom names,
/// you must specify CAPABILITY_NAMED_IAM.The following resources require you to specify CAPABILITY_RESOURCE_POLICY: AWS::Lambda::Permission,
/// AWS::IAM:Policy,
/// AWS::ApplicationAutoScaling::ScalingPolicy,
/// AWS::S3::BucketPolicy,
/// AWS::SQS::QueuePolicy,
/// and AWS::SNS:TopicPolicy.Applications that contain one or more nested applications require you to specify CAPABILITY_AUTO_EXPAND.If your application template contains any of the above resources, we recommend that
/// you review all permissions associated with the application before deploying. If you
/// don't specify this parameter for an application that requires capabilities, the call
/// will fail.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Capabilities")]
public System.String[] Capability { get; set; }
#endregion
#region Parameter ChangeSetName
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ChangeSetName { get; set; }
#endregion
#region Parameter Description
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Description { get; set; }
#endregion
#region Parameter RollbackConfiguration_MonitoringTimeInMinute
///
///
/// This property corresponds to the content of the same name for the AWS CloudFormation
/// RollbackConfiguration Data Type.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("RollbackConfiguration_MonitoringTimeInMinutes")]
public System.Int32? RollbackConfiguration_MonitoringTimeInMinute { get; set; }
#endregion
#region Parameter NotificationArn
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("NotificationArns")]
public System.String[] NotificationArn { get; set; }
#endregion
#region Parameter ParameterOverride
///
///
/// A list of parameter values for the parameters of the application.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("ParameterOverrides")]
public Amazon.ServerlessApplicationRepository.Model.ParameterValue[] ParameterOverride { get; set; }
#endregion
#region Parameter ResourceType
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("ResourceTypes")]
public System.String[] ResourceType { get; set; }
#endregion
#region Parameter RollbackConfiguration_RollbackTrigger
///
///
/// This property corresponds to the content of the same name for the AWS CloudFormation
/// RollbackConfiguration Data Type.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("RollbackConfiguration_RollbackTriggers")]
public Amazon.ServerlessApplicationRepository.Model.RollbackTrigger[] RollbackConfiguration_RollbackTrigger { get; set; }
#endregion
#region Parameter SemanticVersion
///
///
/// The semantic version of the application:https://semver.org/
///
///
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
public System.String SemanticVersion { get; set; }
#endregion
#region Parameter StackName
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
#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 StackName { get; set; }
#endregion
#region Parameter Tag
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public Amazon.ServerlessApplicationRepository.Model.Tag[] Tag { get; set; }
#endregion
#region Parameter TemplateId
///
///
/// The UUID returned by CreateCloudFormationTemplate.Pattern: [0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String TemplateId { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// This property corresponds to the parameter of the same name for the AWS CloudFormation
/// CreateChangeSet API.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientToken { 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.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse).
/// Specifying the name of a property of type Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse 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 SemanticVersion parameter.
/// The -PassThru parameter is deprecated, use -Select '^SemanticVersion' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^SemanticVersion' 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.ApplicationId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-SARCloudFormationChangeSet (CreateCloudFormationChangeSet)"))
{
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.SemanticVersion;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.ApplicationId = this.ApplicationId;
#if MODULAR
if (this.ApplicationId == null && ParameterWasBound(nameof(this.ApplicationId)))
{
WriteWarning("You are passing $null as a value for parameter ApplicationId 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.Capability != null)
{
context.Capability = new List(this.Capability);
}
context.ChangeSetName = this.ChangeSetName;
context.ClientToken = this.ClientToken;
context.Description = this.Description;
if (this.NotificationArn != null)
{
context.NotificationArn = new List(this.NotificationArn);
}
if (this.ParameterOverride != null)
{
context.ParameterOverride = new List(this.ParameterOverride);
}
if (this.ResourceType != null)
{
context.ResourceType = new List(this.ResourceType);
}
context.RollbackConfiguration_MonitoringTimeInMinute = this.RollbackConfiguration_MonitoringTimeInMinute;
if (this.RollbackConfiguration_RollbackTrigger != null)
{
context.RollbackConfiguration_RollbackTrigger = new List(this.RollbackConfiguration_RollbackTrigger);
}
context.SemanticVersion = this.SemanticVersion;
context.StackName = this.StackName;
#if MODULAR
if (this.StackName == null && ParameterWasBound(nameof(this.StackName)))
{
WriteWarning("You are passing $null as a value for parameter StackName 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 List(this.Tag);
}
context.TemplateId = this.TemplateId;
// 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.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetRequest();
if (cmdletContext.ApplicationId != null)
{
request.ApplicationId = cmdletContext.ApplicationId;
}
if (cmdletContext.Capability != null)
{
request.Capabilities = cmdletContext.Capability;
}
if (cmdletContext.ChangeSetName != null)
{
request.ChangeSetName = cmdletContext.ChangeSetName;
}
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
if (cmdletContext.Description != null)
{
request.Description = cmdletContext.Description;
}
if (cmdletContext.NotificationArn != null)
{
request.NotificationArns = cmdletContext.NotificationArn;
}
if (cmdletContext.ParameterOverride != null)
{
request.ParameterOverrides = cmdletContext.ParameterOverride;
}
if (cmdletContext.ResourceType != null)
{
request.ResourceTypes = cmdletContext.ResourceType;
}
// populate RollbackConfiguration
var requestRollbackConfigurationIsNull = true;
request.RollbackConfiguration = new Amazon.ServerlessApplicationRepository.Model.RollbackConfiguration();
System.Int32? requestRollbackConfiguration_rollbackConfiguration_MonitoringTimeInMinute = null;
if (cmdletContext.RollbackConfiguration_MonitoringTimeInMinute != null)
{
requestRollbackConfiguration_rollbackConfiguration_MonitoringTimeInMinute = cmdletContext.RollbackConfiguration_MonitoringTimeInMinute.Value;
}
if (requestRollbackConfiguration_rollbackConfiguration_MonitoringTimeInMinute != null)
{
request.RollbackConfiguration.MonitoringTimeInMinutes = requestRollbackConfiguration_rollbackConfiguration_MonitoringTimeInMinute.Value;
requestRollbackConfigurationIsNull = false;
}
List requestRollbackConfiguration_rollbackConfiguration_RollbackTrigger = null;
if (cmdletContext.RollbackConfiguration_RollbackTrigger != null)
{
requestRollbackConfiguration_rollbackConfiguration_RollbackTrigger = cmdletContext.RollbackConfiguration_RollbackTrigger;
}
if (requestRollbackConfiguration_rollbackConfiguration_RollbackTrigger != null)
{
request.RollbackConfiguration.RollbackTriggers = requestRollbackConfiguration_rollbackConfiguration_RollbackTrigger;
requestRollbackConfigurationIsNull = false;
}
// determine if request.RollbackConfiguration should be set to null
if (requestRollbackConfigurationIsNull)
{
request.RollbackConfiguration = null;
}
if (cmdletContext.SemanticVersion != null)
{
request.SemanticVersion = cmdletContext.SemanticVersion;
}
if (cmdletContext.StackName != null)
{
request.StackName = cmdletContext.StackName;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.TemplateId != null)
{
request.TemplateId = cmdletContext.TemplateId;
}
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.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetResponse CallAWSServiceOperation(IAmazonServerlessApplicationRepository client, Amazon.ServerlessApplicationRepository.Model.CreateCloudFormationChangeSetRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Serverless Application Repository", "CreateCloudFormationChangeSet");
try
{
#if DESKTOP
return client.CreateCloudFormationChangeSet(request);
#elif CORECLR
return client.CreateCloudFormationChangeSetAsync(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 ApplicationId { get; set; }
public List Capability { get; set; }
public System.String ChangeSetName { get; set; }
public System.String ClientToken { get; set; }
public System.String Description { get; set; }
public List NotificationArn { get; set; }
public List ParameterOverride { get; set; }
public List ResourceType { get; set; }
public System.Int32? RollbackConfiguration_MonitoringTimeInMinute { get; set; }
public List RollbackConfiguration_RollbackTrigger { get; set; }
public System.String SemanticVersion { get; set; }
public System.String StackName { get; set; }
public List Tag { get; set; }
public System.String TemplateId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}