/*******************************************************************************
* 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.ResilienceHub;
using Amazon.ResilienceHub.Model;
namespace Amazon.PowerShell.Cmdlets.RESH
{
///
/// Adds or updates the app template for an Resilience Hub application draft version.
///
[Cmdlet("Write", "RESHDraftAppVersionTemplate", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateResponse")]
[AWSCmdlet("Calls the AWS Resilience Hub PutDraftAppVersionTemplate API operation.", Operation = new[] {"PutDraftAppVersionTemplate"}, SelectReturnType = typeof(Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateResponse))]
[AWSCmdletOutput("Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateResponse",
"This cmdlet returns an Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class WriteRESHDraftAppVersionTemplateCmdlet : AmazonResilienceHubClientCmdlet, IExecutor
{
#region Parameter AppArn
///
///
/// The Amazon Resource Name (ARN) of the Resilience Hub application. The format for this
/// ARN is: arn:partition
:resiliencehub:region
:account
:app/app-id
.
/// For more information about ARNs, see
/// Amazon Resource Names (ARNs) in the AWS General Reference guide.
///
///
#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 AppArn { get; set; }
#endregion
#region Parameter AppTemplateBody
///
///
/// A JSON string that provides information about your application structure. To learn
/// more about the appTemplateBody
template, see the sample template provided
/// in the Examples section.The appTemplateBody
JSON string has the following structure:resources
The list of logical resources that must be included in the Resilience Hub application.Type: ArrayDon't add the resources that you want to exclude.Each resources
array item includes the following fields:logicalResourceId
The logical identifier of the resource.Type: ObjectEach logicalResourceId
object includes the following fields:identifier
The identifier of the resource.Type: StringlogicalStackName
The name of the CloudFormation stack this resource belongs to.Type: StringresourceGroupName
The name of the resource group this resource belongs to.Type: StringterraformSourceName
The name of the Terraform S3 state file this resource belongs to.Type: StringeksSourceName
The name of the Amazon Elastic Kubernetes Service cluster and namespace this resource
/// belongs to.This parameter accepts values in "eks-cluster/namespace" format.Type: String
type
The type of resource.Type: stringname
The name of the resource.Type: StringadditionalInfo
Additional configuration parameters for an Resilience Hub application. If you want
/// to implement additionalInfo
through the Resilience Hub console rather
/// than using an API call, see Configure
/// the application configuration parameters.Currently, this parameter accepts a key-value mapping (in a string format) of only
/// one failover region and one associated account.Key: "failover-regions"
Value: "[{"region":"<REGION>", "accounts":[{"id":"<ACCOUNT_ID>"}]}]"
appComponents
The list of Application Components that this resource belongs to. If an Application
/// Component is not part of the Resilience Hub application, it will be added.Type: ArrayEach appComponents
array item includes the following fields:name
The name of the Application Component.Type: Stringtype
The type of Application Component. For more information about the types of Application
/// Component, see Grouping
/// resources in an AppComponent.Type: StringresourceNames
The list of included resources that are assigned to the Application Component.Type: Array of stringsadditionalInfo
Additional configuration parameters for an Resilience Hub application. If you want
/// to implement additionalInfo
through the Resilience Hub console rather
/// than using an API call, see Configure
/// the application configuration parameters.Currently, this parameter accepts a key-value mapping (in a string format) of only
/// one failover region and one associated account.Key: "failover-regions"
Value: "[{"region":"<REGION>", "accounts":[{"id":"<ACCOUNT_ID>"}]}]"
excludedResources
The list of logical resource identifiers to be excluded from the application.Type: ArrayDon't add the resources that you want to include.Each excludedResources
array item includes the following fields:logicalResourceIds
The logical identifier of the resource.Type: ObjectYou can configure only one of the following fields:logicalStackName
resourceGroupName
terraformSourceName
eksSourceName
Each logicalResourceIds
object includes the following fields:identifier
The identifier of the resource.Type: StringlogicalStackName
The name of the CloudFormation stack this resource belongs to.Type: StringresourceGroupName
The name of the resource group this resource belongs to.Type: StringterraformSourceName
The name of the Terraform S3 state file this resource belongs to.Type: StringeksSourceName
The name of the Amazon Elastic Kubernetes Service cluster and namespace this resource
/// belongs to.This parameter accepts values in "eks-cluster/namespace" format.Type: String
version
The Resilience Hub application version.additionalInfo
Additional configuration parameters for an Resilience Hub application. If you want
/// to implement additionalInfo
through the Resilience Hub console rather
/// than using an API call, see Configure
/// the application configuration parameters.Currently, this parameter accepts a key-value mapping (in a string format) of only
/// one failover region and one associated account.Key: "failover-regions"
Value: "[{"region":"<REGION>", "accounts":[{"id":"<ACCOUNT_ID>"}]}]"
///
///
#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 AppTemplateBody { 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.ResilienceHub.Model.PutDraftAppVersionTemplateResponse).
/// Specifying the name of a property of type Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateResponse 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 AppArn parameter.
/// The -PassThru parameter is deprecated, use -Select '^AppArn' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^AppArn' 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.AppArn), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Write-RESHDraftAppVersionTemplate (PutDraftAppVersionTemplate)"))
{
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.AppArn;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
context.AppArn = this.AppArn;
#if MODULAR
if (this.AppArn == null && ParameterWasBound(nameof(this.AppArn)))
{
WriteWarning("You are passing $null as a value for parameter AppArn 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.AppTemplateBody = this.AppTemplateBody;
#if MODULAR
if (this.AppTemplateBody == null && ParameterWasBound(nameof(this.AppTemplateBody)))
{
WriteWarning("You are passing $null as a value for parameter AppTemplateBody 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
// 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.ResilienceHub.Model.PutDraftAppVersionTemplateRequest();
if (cmdletContext.AppArn != null)
{
request.AppArn = cmdletContext.AppArn;
}
if (cmdletContext.AppTemplateBody != null)
{
request.AppTemplateBody = cmdletContext.AppTemplateBody;
}
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.ResilienceHub.Model.PutDraftAppVersionTemplateResponse CallAWSServiceOperation(IAmazonResilienceHub client, Amazon.ResilienceHub.Model.PutDraftAppVersionTemplateRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Resilience Hub", "PutDraftAppVersionTemplate");
try
{
#if DESKTOP
return client.PutDraftAppVersionTemplate(request);
#elif CORECLR
return client.PutDraftAppVersionTemplateAsync(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 AppArn { get; set; }
public System.String AppTemplateBody { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}