/******************************************************************************* * 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.Imagebuilder; using Amazon.Imagebuilder.Model; namespace Amazon.PowerShell.Cmdlets.EC2IB { /// /// Updates a new infrastructure configuration. An infrastructure configuration defines /// the environment in which your image will be built and tested. /// [Cmdlet("Update", "EC2IBInfrastructureConfiguration", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the EC2 Image Builder UpdateInfrastructureConfiguration API operation.", Operation = new[] {"UpdateInfrastructureConfiguration"}, SelectReturnType = typeof(Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse))] [AWSCmdletOutput("System.String or Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class UpdateEC2IBInfrastructureConfigurationCmdlet : AmazonImagebuilderClientCmdlet, IExecutor { #region Parameter Description /// /// /// The description of the infrastructure configuration. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter InstanceMetadataOptions_HttpPutResponseHopLimit /// /// /// Limit the number of hops that an instance metadata request can traverse to reach its /// destination. The default is one hop. However, if HTTP tokens are required, container /// image builds need a minimum of two hops. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? InstanceMetadataOptions_HttpPutResponseHopLimit { get; set; } #endregion #region Parameter InstanceMetadataOptions_HttpToken /// /// /// Indicates whether a signed token header is required for instance metadata retrieval /// requests. The values affect the response as follows:The default setting is optional. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("InstanceMetadataOptions_HttpTokens")] public System.String InstanceMetadataOptions_HttpToken { get; set; } #endregion #region Parameter InfrastructureConfigurationArn /// /// /// The Amazon Resource Name (ARN) of the infrastructure configuration that you want to /// update. /// /// #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 InfrastructureConfigurationArn { get; set; } #endregion #region Parameter InstanceProfileName /// /// /// The instance profile to associate with the instance used to customize your Amazon /// EC2 AMI. /// /// #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 InstanceProfileName { get; set; } #endregion #region Parameter InstanceType /// /// /// The instance types of the infrastructure configuration. You can specify one or more /// instance types to use for this build. The service will pick one of these instance /// types based on availability. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("InstanceTypes")] public System.String[] InstanceType { get; set; } #endregion #region Parameter KeyPair /// /// /// The key pair of the infrastructure configuration. You can use this to log on to and /// debug the instance used to create your image. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KeyPair { get; set; } #endregion #region Parameter ResourceTag /// /// /// The tags attached to the resource created by Image Builder. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("ResourceTags")] public System.Collections.Hashtable ResourceTag { get; set; } #endregion #region Parameter S3Logs_S3BucketName /// /// /// The S3 bucket in which to store the logs. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Logging_S3Logs_S3BucketName")] public System.String S3Logs_S3BucketName { get; set; } #endregion #region Parameter S3Logs_S3KeyPrefix /// /// /// The Amazon S3 path to the bucket where the logs are stored. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Logging_S3Logs_S3KeyPrefix")] public System.String S3Logs_S3KeyPrefix { get; set; } #endregion #region Parameter SecurityGroupId /// /// /// The security group IDs to associate with the instance used to customize your Amazon /// EC2 AMI. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("SecurityGroupIds")] public System.String[] SecurityGroupId { get; set; } #endregion #region Parameter SnsTopicArn /// /// /// The Amazon Resource Name (ARN) for the SNS topic to which we send image build event /// notifications.EC2 Image Builder is unable to send notifications to SNS topics that are encrypted /// using keys from other accounts. The key that is used to encrypt the SNS topic must /// reside in the account that the Image Builder service runs under. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SnsTopicArn { get; set; } #endregion #region Parameter SubnetId /// /// /// The subnet ID to place the instance used to customize your Amazon EC2 AMI in. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SubnetId { get; set; } #endregion #region Parameter TerminateInstanceOnFailure /// /// /// The terminate instance on failure setting of the infrastructure configuration. Set /// to false if you want Image Builder to retain the instance used to configure your AMI /// if the build or test phase of your workflow fails. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? TerminateInstanceOnFailure { get; set; } #endregion #region Parameter ClientToken /// /// /// The idempotency token used to make this request idempotent. /// /// [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 'InfrastructureConfigurationArn'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse). /// Specifying the name of a property of type Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse 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; } = "InfrastructureConfigurationArn"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the InfrastructureConfigurationArn parameter. /// The -PassThru parameter is deprecated, use -Select '^InfrastructureConfigurationArn' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^InfrastructureConfigurationArn' 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.InfrastructureConfigurationArn), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Update-EC2IBInfrastructureConfiguration (UpdateInfrastructureConfiguration)")) { 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.InfrastructureConfigurationArn; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ClientToken = this.ClientToken; context.Description = this.Description; context.InfrastructureConfigurationArn = this.InfrastructureConfigurationArn; #if MODULAR if (this.InfrastructureConfigurationArn == null && ParameterWasBound(nameof(this.InfrastructureConfigurationArn))) { WriteWarning("You are passing $null as a value for parameter InfrastructureConfigurationArn 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.InstanceMetadataOptions_HttpPutResponseHopLimit = this.InstanceMetadataOptions_HttpPutResponseHopLimit; context.InstanceMetadataOptions_HttpToken = this.InstanceMetadataOptions_HttpToken; context.InstanceProfileName = this.InstanceProfileName; #if MODULAR if (this.InstanceProfileName == null && ParameterWasBound(nameof(this.InstanceProfileName))) { WriteWarning("You are passing $null as a value for parameter InstanceProfileName 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.InstanceType != null) { context.InstanceType = new List(this.InstanceType); } context.KeyPair = this.KeyPair; context.S3Logs_S3BucketName = this.S3Logs_S3BucketName; context.S3Logs_S3KeyPrefix = this.S3Logs_S3KeyPrefix; if (this.ResourceTag != null) { context.ResourceTag = new Dictionary(StringComparer.Ordinal); foreach (var hashKey in this.ResourceTag.Keys) { context.ResourceTag.Add((String)hashKey, (String)(this.ResourceTag[hashKey])); } } if (this.SecurityGroupId != null) { context.SecurityGroupId = new List(this.SecurityGroupId); } context.SnsTopicArn = this.SnsTopicArn; context.SubnetId = this.SubnetId; context.TerminateInstanceOnFailure = this.TerminateInstanceOnFailure; // 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.Imagebuilder.Model.UpdateInfrastructureConfigurationRequest(); if (cmdletContext.ClientToken != null) { request.ClientToken = cmdletContext.ClientToken; } if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.InfrastructureConfigurationArn != null) { request.InfrastructureConfigurationArn = cmdletContext.InfrastructureConfigurationArn; } // populate InstanceMetadataOptions var requestInstanceMetadataOptionsIsNull = true; request.InstanceMetadataOptions = new Amazon.Imagebuilder.Model.InstanceMetadataOptions(); System.Int32? requestInstanceMetadataOptions_instanceMetadataOptions_HttpPutResponseHopLimit = null; if (cmdletContext.InstanceMetadataOptions_HttpPutResponseHopLimit != null) { requestInstanceMetadataOptions_instanceMetadataOptions_HttpPutResponseHopLimit = cmdletContext.InstanceMetadataOptions_HttpPutResponseHopLimit.Value; } if (requestInstanceMetadataOptions_instanceMetadataOptions_HttpPutResponseHopLimit != null) { request.InstanceMetadataOptions.HttpPutResponseHopLimit = requestInstanceMetadataOptions_instanceMetadataOptions_HttpPutResponseHopLimit.Value; requestInstanceMetadataOptionsIsNull = false; } System.String requestInstanceMetadataOptions_instanceMetadataOptions_HttpToken = null; if (cmdletContext.InstanceMetadataOptions_HttpToken != null) { requestInstanceMetadataOptions_instanceMetadataOptions_HttpToken = cmdletContext.InstanceMetadataOptions_HttpToken; } if (requestInstanceMetadataOptions_instanceMetadataOptions_HttpToken != null) { request.InstanceMetadataOptions.HttpTokens = requestInstanceMetadataOptions_instanceMetadataOptions_HttpToken; requestInstanceMetadataOptionsIsNull = false; } // determine if request.InstanceMetadataOptions should be set to null if (requestInstanceMetadataOptionsIsNull) { request.InstanceMetadataOptions = null; } if (cmdletContext.InstanceProfileName != null) { request.InstanceProfileName = cmdletContext.InstanceProfileName; } if (cmdletContext.InstanceType != null) { request.InstanceTypes = cmdletContext.InstanceType; } if (cmdletContext.KeyPair != null) { request.KeyPair = cmdletContext.KeyPair; } // populate Logging var requestLoggingIsNull = true; request.Logging = new Amazon.Imagebuilder.Model.Logging(); Amazon.Imagebuilder.Model.S3Logs requestLogging_logging_S3Logs = null; // populate S3Logs var requestLogging_logging_S3LogsIsNull = true; requestLogging_logging_S3Logs = new Amazon.Imagebuilder.Model.S3Logs(); System.String requestLogging_logging_S3Logs_s3Logs_S3BucketName = null; if (cmdletContext.S3Logs_S3BucketName != null) { requestLogging_logging_S3Logs_s3Logs_S3BucketName = cmdletContext.S3Logs_S3BucketName; } if (requestLogging_logging_S3Logs_s3Logs_S3BucketName != null) { requestLogging_logging_S3Logs.S3BucketName = requestLogging_logging_S3Logs_s3Logs_S3BucketName; requestLogging_logging_S3LogsIsNull = false; } System.String requestLogging_logging_S3Logs_s3Logs_S3KeyPrefix = null; if (cmdletContext.S3Logs_S3KeyPrefix != null) { requestLogging_logging_S3Logs_s3Logs_S3KeyPrefix = cmdletContext.S3Logs_S3KeyPrefix; } if (requestLogging_logging_S3Logs_s3Logs_S3KeyPrefix != null) { requestLogging_logging_S3Logs.S3KeyPrefix = requestLogging_logging_S3Logs_s3Logs_S3KeyPrefix; requestLogging_logging_S3LogsIsNull = false; } // determine if requestLogging_logging_S3Logs should be set to null if (requestLogging_logging_S3LogsIsNull) { requestLogging_logging_S3Logs = null; } if (requestLogging_logging_S3Logs != null) { request.Logging.S3Logs = requestLogging_logging_S3Logs; requestLoggingIsNull = false; } // determine if request.Logging should be set to null if (requestLoggingIsNull) { request.Logging = null; } if (cmdletContext.ResourceTag != null) { request.ResourceTags = cmdletContext.ResourceTag; } if (cmdletContext.SecurityGroupId != null) { request.SecurityGroupIds = cmdletContext.SecurityGroupId; } if (cmdletContext.SnsTopicArn != null) { request.SnsTopicArn = cmdletContext.SnsTopicArn; } if (cmdletContext.SubnetId != null) { request.SubnetId = cmdletContext.SubnetId; } if (cmdletContext.TerminateInstanceOnFailure != null) { request.TerminateInstanceOnFailure = cmdletContext.TerminateInstanceOnFailure.Value; } 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.Imagebuilder.Model.UpdateInfrastructureConfigurationResponse CallAWSServiceOperation(IAmazonImagebuilder client, Amazon.Imagebuilder.Model.UpdateInfrastructureConfigurationRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "EC2 Image Builder", "UpdateInfrastructureConfiguration"); try { #if DESKTOP return client.UpdateInfrastructureConfiguration(request); #elif CORECLR return client.UpdateInfrastructureConfigurationAsync(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 ClientToken { get; set; } public System.String Description { get; set; } public System.String InfrastructureConfigurationArn { get; set; } public System.Int32? InstanceMetadataOptions_HttpPutResponseHopLimit { get; set; } public System.String InstanceMetadataOptions_HttpToken { get; set; } public System.String InstanceProfileName { get; set; } public List InstanceType { get; set; } public System.String KeyPair { get; set; } public System.String S3Logs_S3BucketName { get; set; } public System.String S3Logs_S3KeyPrefix { get; set; } public Dictionary ResourceTag { get; set; } public List SecurityGroupId { get; set; } public System.String SnsTopicArn { get; set; } public System.String SubnetId { get; set; } public System.Boolean? TerminateInstanceOnFailure { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.InfrastructureConfigurationArn; } } }