/******************************************************************************* * 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.ElasticBeanstalk; using Amazon.ElasticBeanstalk.Model; namespace Amazon.PowerShell.Cmdlets.EB { /// /// Creates an AWS Elastic Beanstalk configuration template, associated with a specific /// Elastic Beanstalk application. You define application configuration settings in a /// configuration template. You can then use the configuration template to deploy different /// versions of the application with the same configuration settings. /// /// /// /// Templates aren't associated with any environment. The EnvironmentName /// response element is always null. /// /// Related Topics /// /// [Cmdlet("New", "EBConfigurationTemplate", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse")] [AWSCmdlet("Calls the AWS Elastic Beanstalk CreateConfigurationTemplate API operation.", Operation = new[] {"CreateConfigurationTemplate"}, SelectReturnType = typeof(Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse))] [AWSCmdletOutput("Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse", "This cmdlet returns an Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewEBConfigurationTemplateCmdlet : AmazonElasticBeanstalkClientCmdlet, IExecutor { #region Parameter ApplicationName /// /// /// The name of the Elastic Beanstalk application to associate with this configuration /// template. /// /// #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 ApplicationName { get; set; } #endregion #region Parameter SourceConfiguration_ApplicationName /// /// /// The name of the application associated with the configuration. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SourceConfiguration_ApplicationName { get; set; } #endregion #region Parameter Description /// /// /// An optional description for this configuration. /// /// [System.Management.Automation.Parameter(Position = 4, ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter EnvironmentId /// /// /// The ID of an environment whose settings you want to use to create the configuration /// template. You must specify EnvironmentId if you don't specify PlatformArn, /// SolutionStackName, or SourceConfiguration. /// /// [System.Management.Automation.Parameter(Position = 3, ValueFromPipelineByPropertyName = true)] public System.String EnvironmentId { get; set; } #endregion #region Parameter OptionSetting /// /// /// Option values for the Elastic Beanstalk configuration, such as the instance type. /// If specified, these values override the values obtained from the solution stack or /// the source configuration template. For a complete list of Elastic Beanstalk configuration /// options, see Option /// Values in the AWS Elastic Beanstalk Developer Guide. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("OptionSettings")] public Amazon.ElasticBeanstalk.Model.ConfigurationOptionSetting[] OptionSetting { get; set; } #endregion #region Parameter PlatformArn /// /// /// The Amazon Resource Name (ARN) of the custom platform. For more information, see /// Custom Platforms in the AWS Elastic Beanstalk Developer Guide.If you specify PlatformArn, then don't specify SolutionStackName. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String PlatformArn { get; set; } #endregion #region Parameter SolutionStackName /// /// /// The name of an Elastic Beanstalk solution stack (platform version) that this configuration /// uses. For example, 64bit Amazon Linux 2013.09 running Tomcat 7 Java 7. /// A solution stack specifies the operating system, runtime, and application server for /// a configuration template. It also determines the set of configuration options as well /// as the possible and default values. For more information, see Supported /// Platforms in the AWS Elastic Beanstalk Developer Guide.You must specify SolutionStackName if you don't specify PlatformArn, /// EnvironmentId, or SourceConfiguration.Use the ListAvailableSolutionStacks API to obtain a list of available solution /// stacks. /// /// [System.Management.Automation.Parameter(Position = 2, ValueFromPipelineByPropertyName = true)] public System.String SolutionStackName { get; set; } #endregion #region Parameter Tag /// /// /// Specifies the tags applied to the configuration template. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.ElasticBeanstalk.Model.Tag[] Tag { get; set; } #endregion #region Parameter SourceConfiguration_TemplateName /// /// /// The name of the configuration template. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SourceConfiguration_TemplateName { get; set; } #endregion #region Parameter TemplateName /// /// /// The name of the configuration template.Constraint: This name must be unique per application. /// /// #if !MODULAR [System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(Position = 1, ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowEmptyString] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] public System.String TemplateName { 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.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse). /// Specifying the name of a property of type Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse 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 ApplicationName parameter. /// The -PassThru parameter is deprecated, use -Select '^ApplicationName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ApplicationName' 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.ApplicationName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-EBConfigurationTemplate (CreateConfigurationTemplate)")) { 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.ApplicationName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ApplicationName = this.ApplicationName; #if MODULAR if (this.ApplicationName == null && ParameterWasBound(nameof(this.ApplicationName))) { WriteWarning("You are passing $null as a value for parameter ApplicationName 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.Description = this.Description; context.EnvironmentId = this.EnvironmentId; if (this.OptionSetting != null) { context.OptionSetting = new List(this.OptionSetting); } context.PlatformArn = this.PlatformArn; context.SolutionStackName = this.SolutionStackName; context.SourceConfiguration_ApplicationName = this.SourceConfiguration_ApplicationName; context.SourceConfiguration_TemplateName = this.SourceConfiguration_TemplateName; if (this.Tag != null) { context.Tag = new List(this.Tag); } context.TemplateName = this.TemplateName; #if MODULAR if (this.TemplateName == null && ParameterWasBound(nameof(this.TemplateName))) { WriteWarning("You are passing $null as a value for parameter TemplateName 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.ElasticBeanstalk.Model.CreateConfigurationTemplateRequest(); if (cmdletContext.ApplicationName != null) { request.ApplicationName = cmdletContext.ApplicationName; } if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.EnvironmentId != null) { request.EnvironmentId = cmdletContext.EnvironmentId; } if (cmdletContext.OptionSetting != null) { request.OptionSettings = cmdletContext.OptionSetting; } if (cmdletContext.PlatformArn != null) { request.PlatformArn = cmdletContext.PlatformArn; } if (cmdletContext.SolutionStackName != null) { request.SolutionStackName = cmdletContext.SolutionStackName; } // populate SourceConfiguration var requestSourceConfigurationIsNull = true; request.SourceConfiguration = new Amazon.ElasticBeanstalk.Model.SourceConfiguration(); System.String requestSourceConfiguration_sourceConfiguration_ApplicationName = null; if (cmdletContext.SourceConfiguration_ApplicationName != null) { requestSourceConfiguration_sourceConfiguration_ApplicationName = cmdletContext.SourceConfiguration_ApplicationName; } if (requestSourceConfiguration_sourceConfiguration_ApplicationName != null) { request.SourceConfiguration.ApplicationName = requestSourceConfiguration_sourceConfiguration_ApplicationName; requestSourceConfigurationIsNull = false; } System.String requestSourceConfiguration_sourceConfiguration_TemplateName = null; if (cmdletContext.SourceConfiguration_TemplateName != null) { requestSourceConfiguration_sourceConfiguration_TemplateName = cmdletContext.SourceConfiguration_TemplateName; } if (requestSourceConfiguration_sourceConfiguration_TemplateName != null) { request.SourceConfiguration.TemplateName = requestSourceConfiguration_sourceConfiguration_TemplateName; requestSourceConfigurationIsNull = false; } // determine if request.SourceConfiguration should be set to null if (requestSourceConfigurationIsNull) { request.SourceConfiguration = null; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } if (cmdletContext.TemplateName != null) { request.TemplateName = cmdletContext.TemplateName; } 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.ElasticBeanstalk.Model.CreateConfigurationTemplateResponse CallAWSServiceOperation(IAmazonElasticBeanstalk client, Amazon.ElasticBeanstalk.Model.CreateConfigurationTemplateRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Elastic Beanstalk", "CreateConfigurationTemplate"); try { #if DESKTOP return client.CreateConfigurationTemplate(request); #elif CORECLR return client.CreateConfigurationTemplateAsync(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 ApplicationName { get; set; } public System.String Description { get; set; } public System.String EnvironmentId { get; set; } public List OptionSetting { get; set; } public System.String PlatformArn { get; set; } public System.String SolutionStackName { get; set; } public System.String SourceConfiguration_ApplicationName { get; set; } public System.String SourceConfiguration_TemplateName { get; set; } public List Tag { get; set; } public System.String TemplateName { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }