/******************************************************************************* * 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 { /// /// Creates a new maintenance window. /// /// /// The value you specify for Duration determines the specific end time for /// the maintenance window based on the time it begins. No maintenance window tasks are /// permitted to start after the resulting endtime minus the number of hours you specify /// for Cutoff. For example, if the maintenance window starts at 3 PM, the /// duration is three hours, and the value you specify for Cutoff is one /// hour, no maintenance window tasks can start after 5 PM. /// /// [Cmdlet("New", "SSMMaintenanceWindow", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("System.String")] [AWSCmdlet("Calls the AWS Systems Manager CreateMaintenanceWindow API operation.", Operation = new[] {"CreateMaintenanceWindow"}, SelectReturnType = typeof(Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowResponse))] [AWSCmdletOutput("System.String or Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowResponse", "This cmdlet returns a System.String object.", "The service call response (type Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class NewSSMMaintenanceWindowCmdlet : AmazonSimpleSystemsManagementClientCmdlet, IExecutor { protected override bool IsSensitiveRequest { get; set; } = true; #region Parameter AllowUnassociatedTarget /// /// /// Enables a maintenance window task to run on managed nodes, even if you haven't registered /// those nodes as targets. If enabled, then you must specify the unregistered managed /// nodes (by node ID) when you register a task with the maintenance window.If you don't enable this option, then you must specify previously-registered targets /// when you register a task 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] [Alias("AllowUnassociatedTargets")] public System.Boolean? AllowUnassociatedTarget { get; set; } #endregion #region Parameter Cutoff /// /// /// The number of hours before the end of the maintenance window that Amazon Web Services /// Systems Manager stops scheduling new tasks for execution. /// /// #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] public System.Int32? Cutoff { get; set; } #endregion #region Parameter Description /// /// /// An optional description for the maintenance window. We recommend specifying a description /// to help you organize your maintenance windows. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String Description { get; set; } #endregion #region Parameter Duration /// /// /// The duration of the maintenance window in hours. /// /// #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] public System.Int32? Duration { get; set; } #endregion #region Parameter EndDate /// /// /// The date and time, in ISO-8601 Extended format, for when you want the maintenance /// window to become inactive. EndDate allows you to set a date and time /// in the future when the maintenance window will no longer run. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String EndDate { get; set; } #endregion #region Parameter Name /// /// /// The name of the maintenance window. /// /// #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 Name { get; set; } #endregion #region Parameter Schedule /// /// /// The schedule of the maintenance window in the form of a cron or rate expression. /// /// #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 Schedule { get; set; } #endregion #region Parameter ScheduleOffset /// /// /// The number of days to wait after the date and time specified by a cron expression /// before running the maintenance window.For example, the following cron expression schedules a maintenance window to run on /// the third Tuesday of every month at 11:30 PM.cron(30 23 ? * TUE#3 *)If the schedule offset is 2, the maintenance window won't run until two /// days later. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Int32? ScheduleOffset { get; set; } #endregion #region Parameter ScheduleTimezone /// /// /// The time zone that the scheduled maintenance window executions are based on, in Internet /// Assigned Numbers Authority (IANA) format. For example: "America/Los_Angeles", "UTC", /// or "Asia/Seoul". For more information, see the Time /// Zone Database on the IANA website. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ScheduleTimezone { get; set; } #endregion #region Parameter StartDate /// /// /// The date and time, in ISO-8601 Extended format, for when you want the maintenance /// window to become active. StartDate allows you to delay activation of /// the maintenance window until the specified future date. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String StartDate { get; set; } #endregion #region Parameter Tag /// /// /// Optional metadata that you assign to a resource. Tags enable you to categorize a resource /// in different ways, such as by purpose, owner, or environment. For example, you might /// want to tag a maintenance window to identify the type of tasks it will run, the types /// of targets, and the environment it will run in. In this case, you could specify the /// following key-value pairs:To add tags to an existing maintenance window, use the AddTagsToResource operation. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [Alias("Tags")] public Amazon.SimpleSystemsManagement.Model.Tag[] Tag { 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 'WindowId'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowResponse). /// Specifying the name of a property of type Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowResponse 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; } = "WindowId"; #endregion #region Parameter PassThru /// /// Changes the cmdlet behavior to return the value passed to the Name parameter. /// The -PassThru parameter is deprecated, use -Select '^Name' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Name' 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.Name), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "New-SSMMaintenanceWindow (CreateMaintenanceWindow)")) { 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.Name; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.AllowUnassociatedTarget = this.AllowUnassociatedTarget; #if MODULAR if (this.AllowUnassociatedTarget == null && ParameterWasBound(nameof(this.AllowUnassociatedTarget))) { WriteWarning("You are passing $null as a value for parameter AllowUnassociatedTarget 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.Cutoff = this.Cutoff; #if MODULAR if (this.Cutoff == null && ParameterWasBound(nameof(this.Cutoff))) { WriteWarning("You are passing $null as a value for parameter Cutoff 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.Duration = this.Duration; #if MODULAR if (this.Duration == null && ParameterWasBound(nameof(this.Duration))) { WriteWarning("You are passing $null as a value for parameter Duration 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.EndDate = this.EndDate; context.Name = this.Name; #if MODULAR if (this.Name == null && ParameterWasBound(nameof(this.Name))) { WriteWarning("You are passing $null as a value for parameter Name 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.Schedule = this.Schedule; #if MODULAR if (this.Schedule == null && ParameterWasBound(nameof(this.Schedule))) { WriteWarning("You are passing $null as a value for parameter Schedule 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.ScheduleOffset = this.ScheduleOffset; context.ScheduleTimezone = this.ScheduleTimezone; context.StartDate = this.StartDate; if (this.Tag != null) { context.Tag = new List(this.Tag); } // 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.CreateMaintenanceWindowRequest(); if (cmdletContext.AllowUnassociatedTarget != null) { request.AllowUnassociatedTargets = cmdletContext.AllowUnassociatedTarget.Value; } if (cmdletContext.ClientToken != null) { request.ClientToken = cmdletContext.ClientToken; } if (cmdletContext.Cutoff != null) { request.Cutoff = cmdletContext.Cutoff.Value; } if (cmdletContext.Description != null) { request.Description = cmdletContext.Description; } if (cmdletContext.Duration != null) { request.Duration = cmdletContext.Duration.Value; } if (cmdletContext.EndDate != null) { request.EndDate = cmdletContext.EndDate; } if (cmdletContext.Name != null) { request.Name = cmdletContext.Name; } if (cmdletContext.Schedule != null) { request.Schedule = cmdletContext.Schedule; } if (cmdletContext.ScheduleOffset != null) { request.ScheduleOffset = cmdletContext.ScheduleOffset.Value; } if (cmdletContext.ScheduleTimezone != null) { request.ScheduleTimezone = cmdletContext.ScheduleTimezone; } if (cmdletContext.StartDate != null) { request.StartDate = cmdletContext.StartDate; } if (cmdletContext.Tag != null) { request.Tags = cmdletContext.Tag; } 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.CreateMaintenanceWindowResponse CallAWSServiceOperation(IAmazonSimpleSystemsManagement client, Amazon.SimpleSystemsManagement.Model.CreateMaintenanceWindowRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Systems Manager", "CreateMaintenanceWindow"); try { #if DESKTOP return client.CreateMaintenanceWindow(request); #elif CORECLR return client.CreateMaintenanceWindowAsync(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.Boolean? AllowUnassociatedTarget { get; set; } public System.String ClientToken { get; set; } public System.Int32? Cutoff { get; set; } public System.String Description { get; set; } public System.Int32? Duration { get; set; } public System.String EndDate { get; set; } public System.String Name { get; set; } public System.String Schedule { get; set; } public System.Int32? ScheduleOffset { get; set; } public System.String ScheduleTimezone { get; set; } public System.String StartDate { get; set; } public List Tag { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response.WindowId; } } }