/******************************************************************************* * 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 compliance type and other compliance details on a designated resource. /// This operation lets you register custom compliance details with a resource. This call /// overwrites existing compliance information on the resource, so you must provide a /// full list of compliance items each time that you send the request. /// /// /// /// ComplianceType can be one of the following: /// /// [Cmdlet("Write", "SSMComplianceItem", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("None")] [AWSCmdlet("Calls the AWS Systems Manager PutComplianceItems API operation.", Operation = new[] {"PutComplianceItems"}, SelectReturnType = typeof(Amazon.SimpleSystemsManagement.Model.PutComplianceItemsResponse))] [AWSCmdletOutput("None or Amazon.SimpleSystemsManagement.Model.PutComplianceItemsResponse", "This cmdlet does not generate any output." + "The service response (type Amazon.SimpleSystemsManagement.Model.PutComplianceItemsResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class WriteSSMComplianceItemCmdlet : AmazonSimpleSystemsManagementClientCmdlet, IExecutor { #region Parameter ComplianceType /// /// /// Specify the compliance type. For example, specify Association (for a State Manager /// association), Patch, or Custom:string. /// /// #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 ComplianceType { get; set; } #endregion #region Parameter ExecutionSummary_ExecutionId /// /// /// An ID created by the system when PutComplianceItems was called. For example, /// CommandID is a valid execution ID. You can use this ID in subsequent /// calls. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ExecutionSummary_ExecutionId { get; set; } #endregion #region Parameter ExecutionSummary_ExecutionTime /// /// /// The time the execution ran as a datetime object that is saved in the following format: /// yyyy-MM-dd'T'HH:mm:ss'Z'. /// /// #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.DateTime? ExecutionSummary_ExecutionTime { get; set; } #endregion #region Parameter ExecutionSummary_ExecutionType /// /// /// The type of execution. For example, Command is a valid execution type. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ExecutionSummary_ExecutionType { get; set; } #endregion #region Parameter ItemContentHash /// /// /// MD5 or SHA-256 content hash. The content hash is used to determine if existing information /// should be overwritten or ignored. If the content hashes match, the request to put /// compliance information is ignored. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String ItemContentHash { get; set; } #endregion #region Parameter Item /// /// /// Information about the compliance as defined by the resource type. For example, for /// a patch compliance type, Items includes information about the PatchSeverity, /// Classification, and so on. /// /// #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("Items")] public Amazon.SimpleSystemsManagement.Model.ComplianceItemEntry[] Item { get; set; } #endregion #region Parameter ResourceId /// /// /// Specify an ID for this resource. For a managed node, this is the node ID. /// /// #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 ResourceId { get; set; } #endregion #region Parameter ResourceType /// /// /// Specify the type of resource. ManagedInstance is currently the only supported /// resource type. /// /// #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 ResourceType { get; set; } #endregion #region Parameter UploadType /// /// /// The mode for uploading compliance items. You can specify COMPLETE or /// PARTIAL. In COMPLETE mode, the system overwrites all existing /// compliance information for the resource. You must provide a full list of compliance /// items each time you send the request.In PARTIAL mode, the system overwrites compliance information for a specific /// association. The association must be configured with SyncCompliance set /// to MANUAL. By default, all requests use COMPLETE mode.This attribute is only valid for association compliance. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.SimpleSystemsManagement.ComplianceUploadType")] public Amazon.SimpleSystemsManagement.ComplianceUploadType UploadType { get; set; } #endregion #region Parameter Select /// /// Use the -Select parameter to control the cmdlet output. The cmdlet doesn't have a return value by default. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.SimpleSystemsManagement.Model.PutComplianceItemsResponse). /// 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 ResourceId parameter. /// The -PassThru parameter is deprecated, use -Select '^ResourceId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ResourceId' 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.ResourceId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Write-SSMComplianceItem (PutComplianceItems)")) { 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.ResourceId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ComplianceType = this.ComplianceType; #if MODULAR if (this.ComplianceType == null && ParameterWasBound(nameof(this.ComplianceType))) { WriteWarning("You are passing $null as a value for parameter ComplianceType 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.ExecutionSummary_ExecutionId = this.ExecutionSummary_ExecutionId; context.ExecutionSummary_ExecutionTime = this.ExecutionSummary_ExecutionTime; #if MODULAR if (this.ExecutionSummary_ExecutionTime == null && ParameterWasBound(nameof(this.ExecutionSummary_ExecutionTime))) { WriteWarning("You are passing $null as a value for parameter ExecutionSummary_ExecutionTime 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.ExecutionSummary_ExecutionType = this.ExecutionSummary_ExecutionType; context.ItemContentHash = this.ItemContentHash; if (this.Item != null) { context.Item = new List(this.Item); } #if MODULAR if (this.Item == null && ParameterWasBound(nameof(this.Item))) { WriteWarning("You are passing $null as a value for parameter Item 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.ResourceId = this.ResourceId; #if MODULAR if (this.ResourceId == null && ParameterWasBound(nameof(this.ResourceId))) { WriteWarning("You are passing $null as a value for parameter ResourceId 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.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 context.UploadType = this.UploadType; // 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.PutComplianceItemsRequest(); if (cmdletContext.ComplianceType != null) { request.ComplianceType = cmdletContext.ComplianceType; } // populate ExecutionSummary var requestExecutionSummaryIsNull = true; request.ExecutionSummary = new Amazon.SimpleSystemsManagement.Model.ComplianceExecutionSummary(); System.String requestExecutionSummary_executionSummary_ExecutionId = null; if (cmdletContext.ExecutionSummary_ExecutionId != null) { requestExecutionSummary_executionSummary_ExecutionId = cmdletContext.ExecutionSummary_ExecutionId; } if (requestExecutionSummary_executionSummary_ExecutionId != null) { request.ExecutionSummary.ExecutionId = requestExecutionSummary_executionSummary_ExecutionId; requestExecutionSummaryIsNull = false; } System.DateTime? requestExecutionSummary_executionSummary_ExecutionTime = null; if (cmdletContext.ExecutionSummary_ExecutionTime != null) { requestExecutionSummary_executionSummary_ExecutionTime = cmdletContext.ExecutionSummary_ExecutionTime.Value; } if (requestExecutionSummary_executionSummary_ExecutionTime != null) { request.ExecutionSummary.ExecutionTime = requestExecutionSummary_executionSummary_ExecutionTime.Value; requestExecutionSummaryIsNull = false; } System.String requestExecutionSummary_executionSummary_ExecutionType = null; if (cmdletContext.ExecutionSummary_ExecutionType != null) { requestExecutionSummary_executionSummary_ExecutionType = cmdletContext.ExecutionSummary_ExecutionType; } if (requestExecutionSummary_executionSummary_ExecutionType != null) { request.ExecutionSummary.ExecutionType = requestExecutionSummary_executionSummary_ExecutionType; requestExecutionSummaryIsNull = false; } // determine if request.ExecutionSummary should be set to null if (requestExecutionSummaryIsNull) { request.ExecutionSummary = null; } if (cmdletContext.ItemContentHash != null) { request.ItemContentHash = cmdletContext.ItemContentHash; } if (cmdletContext.Item != null) { request.Items = cmdletContext.Item; } if (cmdletContext.ResourceId != null) { request.ResourceId = cmdletContext.ResourceId; } if (cmdletContext.ResourceType != null) { request.ResourceType = cmdletContext.ResourceType; } if (cmdletContext.UploadType != null) { request.UploadType = cmdletContext.UploadType; } 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.PutComplianceItemsResponse CallAWSServiceOperation(IAmazonSimpleSystemsManagement client, Amazon.SimpleSystemsManagement.Model.PutComplianceItemsRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Systems Manager", "PutComplianceItems"); try { #if DESKTOP return client.PutComplianceItems(request); #elif CORECLR return client.PutComplianceItemsAsync(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 ComplianceType { get; set; } public System.String ExecutionSummary_ExecutionId { get; set; } public System.DateTime? ExecutionSummary_ExecutionTime { get; set; } public System.String ExecutionSummary_ExecutionType { get; set; } public System.String ItemContentHash { get; set; } public List Item { get; set; } public System.String ResourceId { get; set; } public System.String ResourceType { get; set; } public Amazon.SimpleSystemsManagement.ComplianceUploadType UploadType { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => null; } } }