/*******************************************************************************
* 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.FIS;
using Amazon.FIS.Model;
namespace Amazon.PowerShell.Cmdlets.FIS
{
///
/// Creates an experiment template.
///
///
///
/// An experiment template includes the following components:
/// - Targets: A target can be a specific resource in your Amazon Web Services environment,
/// or one or more resources that match criteria that you specify, for example, resources
/// that have specific tags.
///
- Actions: The actions to carry out on the target. You can specify multiple
/// actions, the duration of each action, and when to start each action during an experiment.
///
- Stop conditions: If a stop condition is triggered while an experiment is running,
/// the experiment is automatically stopped. You can define a stop condition as a CloudWatch
/// alarm.
///
/// For more information, see Experiment
/// templates in the Fault Injection Simulator User Guide.
///
///
[Cmdlet("New", "FISExperimentTemplate", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.FIS.Model.ExperimentTemplate")]
[AWSCmdlet("Calls the AWS Fault Injection Simulator CreateExperimentTemplate API operation.", Operation = new[] {"CreateExperimentTemplate"}, SelectReturnType = typeof(Amazon.FIS.Model.CreateExperimentTemplateResponse))]
[AWSCmdletOutput("Amazon.FIS.Model.ExperimentTemplate or Amazon.FIS.Model.CreateExperimentTemplateResponse",
"This cmdlet returns an Amazon.FIS.Model.ExperimentTemplate object.",
"The service call response (type Amazon.FIS.Model.CreateExperimentTemplateResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class NewFISExperimentTemplateCmdlet : AmazonFISClientCmdlet, IExecutor
{
#region Parameter Action
///
///
/// The actions for the experiment.
///
///
#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("Actions")]
public System.Collections.Hashtable Action { get; set; }
#endregion
#region Parameter S3Configuration_BucketName
///
///
/// The name of the destination bucket.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LogConfiguration_S3Configuration_BucketName")]
public System.String S3Configuration_BucketName { get; set; }
#endregion
#region Parameter Description
///
///
/// A description for the experiment template.
///
///
#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 Description { get; set; }
#endregion
#region Parameter CloudWatchLogsConfiguration_LogGroupArn
///
///
/// The Amazon Resource Name (ARN) of the destination Amazon CloudWatch Logs log group.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LogConfiguration_CloudWatchLogsConfiguration_LogGroupArn")]
public System.String CloudWatchLogsConfiguration_LogGroupArn { get; set; }
#endregion
#region Parameter LogConfiguration_LogSchemaVersion
///
///
/// The schema version.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? LogConfiguration_LogSchemaVersion { get; set; }
#endregion
#region Parameter S3Configuration_Prefix
///
///
/// The bucket prefix.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("LogConfiguration_S3Configuration_Prefix")]
public System.String S3Configuration_Prefix { get; set; }
#endregion
#region Parameter RoleArn
///
///
/// The Amazon Resource Name (ARN) of an IAM role that grants the FIS service permission
/// to perform service actions on your behalf.
///
///
#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 RoleArn { get; set; }
#endregion
#region Parameter StopCondition
///
///
/// The stop conditions.
///
///
#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("StopConditions")]
public Amazon.FIS.Model.CreateExperimentTemplateStopConditionInput[] StopCondition { get; set; }
#endregion
#region Parameter Tag
///
///
/// The tags to apply to the experiment template.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Tags")]
public System.Collections.Hashtable Tag { get; set; }
#endregion
#region Parameter Target
///
///
/// The targets for the experiment.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Targets")]
public System.Collections.Hashtable Target { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// Unique, case-sensitive identifier that you provide to ensure the idempotency of the
/// request.
///
///
[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 'ExperimentTemplate'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.FIS.Model.CreateExperimentTemplateResponse).
/// Specifying the name of a property of type Amazon.FIS.Model.CreateExperimentTemplateResponse 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; } = "ExperimentTemplate";
#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.RoleArn), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-FISExperimentTemplate (CreateExperimentTemplate)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
}
if (this.Action != null)
{
context.Action = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.Action.Keys)
{
context.Action.Add((String)hashKey, (CreateExperimentTemplateActionInput)(this.Action[hashKey]));
}
}
#if MODULAR
if (this.Action == null && ParameterWasBound(nameof(this.Action)))
{
WriteWarning("You are passing $null as a value for parameter Action 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.ClientToken = this.ClientToken;
context.Description = this.Description;
#if MODULAR
if (this.Description == null && ParameterWasBound(nameof(this.Description)))
{
WriteWarning("You are passing $null as a value for parameter Description 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.CloudWatchLogsConfiguration_LogGroupArn = this.CloudWatchLogsConfiguration_LogGroupArn;
context.LogConfiguration_LogSchemaVersion = this.LogConfiguration_LogSchemaVersion;
context.S3Configuration_BucketName = this.S3Configuration_BucketName;
context.S3Configuration_Prefix = this.S3Configuration_Prefix;
context.RoleArn = this.RoleArn;
#if MODULAR
if (this.RoleArn == null && ParameterWasBound(nameof(this.RoleArn)))
{
WriteWarning("You are passing $null as a value for parameter RoleArn 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.StopCondition != null)
{
context.StopCondition = new List(this.StopCondition);
}
#if MODULAR
if (this.StopCondition == null && ParameterWasBound(nameof(this.StopCondition)))
{
WriteWarning("You are passing $null as a value for parameter StopCondition 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]));
}
}
if (this.Target != null)
{
context.Target = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.Target.Keys)
{
context.Target.Add((String)hashKey, (CreateExperimentTemplateTargetInput)(this.Target[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.FIS.Model.CreateExperimentTemplateRequest();
if (cmdletContext.Action != null)
{
request.Actions = cmdletContext.Action;
}
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
if (cmdletContext.Description != null)
{
request.Description = cmdletContext.Description;
}
// populate LogConfiguration
var requestLogConfigurationIsNull = true;
request.LogConfiguration = new Amazon.FIS.Model.CreateExperimentTemplateLogConfigurationInput();
System.Int32? requestLogConfiguration_logConfiguration_LogSchemaVersion = null;
if (cmdletContext.LogConfiguration_LogSchemaVersion != null)
{
requestLogConfiguration_logConfiguration_LogSchemaVersion = cmdletContext.LogConfiguration_LogSchemaVersion.Value;
}
if (requestLogConfiguration_logConfiguration_LogSchemaVersion != null)
{
request.LogConfiguration.LogSchemaVersion = requestLogConfiguration_logConfiguration_LogSchemaVersion.Value;
requestLogConfigurationIsNull = false;
}
Amazon.FIS.Model.ExperimentTemplateCloudWatchLogsLogConfigurationInput requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration = null;
// populate CloudWatchLogsConfiguration
var requestLogConfiguration_logConfiguration_CloudWatchLogsConfigurationIsNull = true;
requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration = new Amazon.FIS.Model.ExperimentTemplateCloudWatchLogsLogConfigurationInput();
System.String requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration_cloudWatchLogsConfiguration_LogGroupArn = null;
if (cmdletContext.CloudWatchLogsConfiguration_LogGroupArn != null)
{
requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration_cloudWatchLogsConfiguration_LogGroupArn = cmdletContext.CloudWatchLogsConfiguration_LogGroupArn;
}
if (requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration_cloudWatchLogsConfiguration_LogGroupArn != null)
{
requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration.LogGroupArn = requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration_cloudWatchLogsConfiguration_LogGroupArn;
requestLogConfiguration_logConfiguration_CloudWatchLogsConfigurationIsNull = false;
}
// determine if requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration should be set to null
if (requestLogConfiguration_logConfiguration_CloudWatchLogsConfigurationIsNull)
{
requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration = null;
}
if (requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration != null)
{
request.LogConfiguration.CloudWatchLogsConfiguration = requestLogConfiguration_logConfiguration_CloudWatchLogsConfiguration;
requestLogConfigurationIsNull = false;
}
Amazon.FIS.Model.ExperimentTemplateS3LogConfigurationInput requestLogConfiguration_logConfiguration_S3Configuration = null;
// populate S3Configuration
var requestLogConfiguration_logConfiguration_S3ConfigurationIsNull = true;
requestLogConfiguration_logConfiguration_S3Configuration = new Amazon.FIS.Model.ExperimentTemplateS3LogConfigurationInput();
System.String requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_BucketName = null;
if (cmdletContext.S3Configuration_BucketName != null)
{
requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_BucketName = cmdletContext.S3Configuration_BucketName;
}
if (requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_BucketName != null)
{
requestLogConfiguration_logConfiguration_S3Configuration.BucketName = requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_BucketName;
requestLogConfiguration_logConfiguration_S3ConfigurationIsNull = false;
}
System.String requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_Prefix = null;
if (cmdletContext.S3Configuration_Prefix != null)
{
requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_Prefix = cmdletContext.S3Configuration_Prefix;
}
if (requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_Prefix != null)
{
requestLogConfiguration_logConfiguration_S3Configuration.Prefix = requestLogConfiguration_logConfiguration_S3Configuration_s3Configuration_Prefix;
requestLogConfiguration_logConfiguration_S3ConfigurationIsNull = false;
}
// determine if requestLogConfiguration_logConfiguration_S3Configuration should be set to null
if (requestLogConfiguration_logConfiguration_S3ConfigurationIsNull)
{
requestLogConfiguration_logConfiguration_S3Configuration = null;
}
if (requestLogConfiguration_logConfiguration_S3Configuration != null)
{
request.LogConfiguration.S3Configuration = requestLogConfiguration_logConfiguration_S3Configuration;
requestLogConfigurationIsNull = false;
}
// determine if request.LogConfiguration should be set to null
if (requestLogConfigurationIsNull)
{
request.LogConfiguration = null;
}
if (cmdletContext.RoleArn != null)
{
request.RoleArn = cmdletContext.RoleArn;
}
if (cmdletContext.StopCondition != null)
{
request.StopConditions = cmdletContext.StopCondition;
}
if (cmdletContext.Tag != null)
{
request.Tags = cmdletContext.Tag;
}
if (cmdletContext.Target != null)
{
request.Targets = cmdletContext.Target;
}
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.FIS.Model.CreateExperimentTemplateResponse CallAWSServiceOperation(IAmazonFIS client, Amazon.FIS.Model.CreateExperimentTemplateRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Fault Injection Simulator", "CreateExperimentTemplate");
try
{
#if DESKTOP
return client.CreateExperimentTemplate(request);
#elif CORECLR
return client.CreateExperimentTemplateAsync(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 Dictionary Action { get; set; }
public System.String ClientToken { get; set; }
public System.String Description { get; set; }
public System.String CloudWatchLogsConfiguration_LogGroupArn { get; set; }
public System.Int32? LogConfiguration_LogSchemaVersion { get; set; }
public System.String S3Configuration_BucketName { get; set; }
public System.String S3Configuration_Prefix { get; set; }
public System.String RoleArn { get; set; }
public List StopCondition { get; set; }
public Dictionary Tag { get; set; }
public Dictionary Target { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response.ExperimentTemplate;
}
}
}