/******************************************************************************* * 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.SimpleSystemsManagement; using Amazon.SimpleSystemsManagement.Model; namespace Amazon.PowerShell.Cmdlets.SSM { /// /// Registers a target with a maintenance window. /// [Cmdlet("Register", "SSMTargetWithMaintenanceWindow", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS Systems Manager RegisterTargetWithMaintenanceWindow API operation.", Operation = new[] {"RegisterTargetWithMaintenanceWindow"}, SelectReturnType = typeof(Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse))] [AWSCmdletOutput("System.String or Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class RegisterSSMTargetWithMaintenanceWindowCmdlet : AmazonSimpleSystemsManagementClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; #region Parameter Description /// /// /// An optional description for the target. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter Name /// /// /// An optional name for the target. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Name { get; set; } #endregion #region Parameter OwnerInformation /// /// /// User-provided value that will be included in any Amazon CloudWatch Events events raised /// while running tasks for these targets in this maintenance window. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String OwnerInformation { get; set; } #endregion #region Parameter ResourceType /// /// /// The type of target being registered with the maintenance window. /// /// #if !MODULAR [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] #else [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)] [System.Management.Automation.AllowNull] #endif [Amazon.PowerShell.Common.AWSRequiredParameter] [AWSConstantClassSource("Amazon.SimpleSystemsManagement.MaintenanceWindowResourceType")] public Amazon.SimpleSystemsManagement.MaintenanceWindowResourceType ResourceType { get; set; } #endregion #region Parameter Target /// /// /// The targets to register with the maintenance window. In other words, the managed nodes /// to run commands on when the maintenance window runs.If a single maintenance window task is registered with multiple targets, its task /// invocations occur sequentially and not in parallel. If your task must run on multiple /// targets at the same time, register a task for each target individually and assign /// each task the same priority level.You can specify targets using managed node IDs, resource group names, or tags that /// have been applied to managed nodes.Example 1: Specify managed node IDsKey=InstanceIds,Values=<instance-id-1>,<instance-id-2>,<instance-id-3>Example 2: Use tag key-pairs applied to managed nodesKey=tag:<my-tag-key>,Values=<my-tag-value-1>,<my-tag-value-2>Example 3: Use tag-keys applied to managed nodesKey=tag-key,Values=<my-tag-key-1>,<my-tag-key-2>Example 4: Use resource group namesKey=resource-groups:Name,Values=<resource-group-name>Example 5: Use filters for resource group typesKey=resource-groups:ResourceTypeFilters,Values=<resource-type-1>,<resource-type-2>For Key=resource-groups:ResourceTypeFilters, specify resource types in /// the following formatKey=resource-groups:ResourceTypeFilters,Values=AWS::EC2::INSTANCE,AWS::EC2::VPCFor more information about these examples formats, including the best use case for /// each one, see Examples: /// Register targets with a maintenance window in the Amazon Web Services Systems /// Manager User Guide. /// /// #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("Targets")] public Amazon.SimpleSystemsManagement.Model.Target[] Target { get; set; } #endregion #region Parameter WindowId /// /// /// The ID of the maintenance window the target should be registered with. /// /// #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 WindowId { get; set; } #endregion #region Parameter ClientToken /// /// /// User-provided idempotency token. /// /// [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 'WindowTargetId'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse). /// Specifying the name of a property of type Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse 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; } = "WindowTargetId"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the WindowId parameter. /// The -PassThru parameter is deprecated, use -Select '^WindowId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^WindowId' 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.WindowId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Register-SSMTargetWithMaintenanceWindow (RegisterTargetWithMaintenanceWindow)")) { 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.WindowId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ClientToken = this.ClientToken; context.Description = this.Description; context.Name = this.Name; context.OwnerInformation = this.OwnerInformation; context.ResourceType = this.ResourceType; #if MODULAR if (this.ResourceType == null && ParameterWasBound(nameof(this.ResourceType))) { WriteWarning("You are passing $null as a value for parameter ResourceType 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.Target != null) { context.Target = new List(this.Target); } #if MODULAR if (this.Target == null && ParameterWasBound(nameof(this.Target))) { WriteWarning("You are passing $null as a value for parameter Target 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.WindowId = this.WindowId; #if MODULAR if (this.WindowId == null && ParameterWasBound(nameof(this.WindowId))) { WriteWarning("You are passing $null as a value for parameter WindowId 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.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowRequest(); if (cmdletContext.ClientToken != null) { request.ClientToken = cmdletContext.ClientToken; } if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.Name != null) { request.Name = cmdletContext.Name; } if (cmdletContext.OwnerInformation != null) { request.OwnerInformation = cmdletContext.OwnerInformation; } if (cmdletContext.ResourceType != null) { request.ResourceType = cmdletContext.ResourceType; } if (cmdletContext.Target != null) { request.Targets = cmdletContext.Target; } if (cmdletContext.WindowId != null) { request.WindowId = cmdletContext.WindowId; } 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.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowResponse CallAWSServiceOperation(IAmazonSimpleSystemsManagement client, Amazon.SimpleSystemsManagement.Model.RegisterTargetWithMaintenanceWindowRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Systems Manager", "RegisterTargetWithMaintenanceWindow"); try { #if DESKTOP return client.RegisterTargetWithMaintenanceWindow(request); #elif CORECLR return client.RegisterTargetWithMaintenanceWindowAsync(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 Name { get; set; } public System.String OwnerInformation { get; set; } public Amazon.SimpleSystemsManagement.MaintenanceWindowResourceType ResourceType { get; set; } public List Target { get; set; } public System.String WindowId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.WindowTargetId; } } }