/*******************************************************************************
* 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
{
///
/// Updates an existing maintenance window. Only specified parameters are modified.
///
///
/// 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("Update", "SSMMaintenanceWindow", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse")]
[AWSCmdlet("Calls the AWS Systems Manager UpdateMaintenanceWindow API operation.", Operation = new[] {"UpdateMaintenanceWindow"}, SelectReturnType = typeof(Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse))]
[AWSCmdletOutput("Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse",
"This cmdlet returns an Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class UpdateSSMMaintenanceWindowCmdlet : AmazonSimpleSystemsManagementClientCmdlet, IExecutor
{
protected override bool IsSensitiveRequest { get; set; } = true;
protected override bool IsSensitiveResponse { get; set; } = true;
#region Parameter AllowUnassociatedTarget
///
///
/// Whether targets must be registered with the maintenance window before tasks can be
/// defined for those targets.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[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.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? Cutoff { get; set; }
#endregion
#region Parameter Description
///
///
/// An optional description for the update request.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Description { get; set; }
#endregion
#region Parameter Duration
///
///
/// The duration of the maintenance window in hours.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Int32? Duration { get; set; }
#endregion
#region Parameter Enabled
///
///
/// Whether the maintenance window is enabled.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? Enabled { 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.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String Name { get; set; }
#endregion
#region Parameter Replace
///
///
/// If True
, then all fields that are required by the CreateMaintenanceWindow
/// operation are also required for this API request. Optional fields that aren't specified
/// are set to null.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.Boolean? Replace { get; set; }
#endregion
#region Parameter Schedule
///
///
/// The schedule of the maintenance window in the form of a cron or rate expression.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
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 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 WindowId
///
///
/// The ID of the maintenance window 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 WindowId { 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.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse).
/// Specifying the name of a property of type Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowResponse 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 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, "Update-SSMMaintenanceWindow (UpdateMaintenanceWindow)"))
{
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.AllowUnassociatedTarget = this.AllowUnassociatedTarget;
context.Cutoff = this.Cutoff;
context.Description = this.Description;
context.Duration = this.Duration;
context.Enabled = this.Enabled;
context.EndDate = this.EndDate;
context.Name = this.Name;
context.Replace = this.Replace;
context.Schedule = this.Schedule;
context.ScheduleOffset = this.ScheduleOffset;
context.ScheduleTimezone = this.ScheduleTimezone;
context.StartDate = this.StartDate;
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.UpdateMaintenanceWindowRequest();
if (cmdletContext.AllowUnassociatedTarget != null)
{
request.AllowUnassociatedTargets = cmdletContext.AllowUnassociatedTarget.Value;
}
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.Enabled != null)
{
request.Enabled = cmdletContext.Enabled.Value;
}
if (cmdletContext.EndDate != null)
{
request.EndDate = cmdletContext.EndDate;
}
if (cmdletContext.Name != null)
{
request.Name = cmdletContext.Name;
}
if (cmdletContext.Replace != null)
{
request.Replace = cmdletContext.Replace.Value;
}
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.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.UpdateMaintenanceWindowResponse CallAWSServiceOperation(IAmazonSimpleSystemsManagement client, Amazon.SimpleSystemsManagement.Model.UpdateMaintenanceWindowRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Systems Manager", "UpdateMaintenanceWindow");
try
{
#if DESKTOP
return client.UpdateMaintenanceWindow(request);
#elif CORECLR
return client.UpdateMaintenanceWindowAsync(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.Int32? Cutoff { get; set; }
public System.String Description { get; set; }
public System.Int32? Duration { get; set; }
public System.Boolean? Enabled { get; set; }
public System.String EndDate { get; set; }
public System.String Name { get; set; }
public System.Boolean? Replace { 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 System.String WindowId { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}