/******************************************************************************* * 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 { /// /// Delete a custom inventory type or the data associated with a custom Inventory type. /// Deleting a custom inventory type is also referred to as deleting a custom inventory /// schema. /// [Cmdlet("Remove", "SSMInventory", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.High)] [OutputType("Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse")] [AWSCmdlet("Calls the AWS Systems Manager DeleteInventory API operation.", Operation = new[] {"DeleteInventory"}, SelectReturnType = typeof(Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse))] [AWSCmdletOutput("Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse", "This cmdlet returns an Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class RemoveSSMInventoryCmdlet : AmazonSimpleSystemsManagementClientCmdlet, IExecutor { #region Parameter DryRun /// /// /// Use this option to view a summary of the deletion request without deleting any data /// or the data type. This option is useful when you only want to understand what will /// be deleted. Once you validate that the data to be deleted is what you intend to delete, /// you can run the same command without specifying the DryRun option. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? DryRun { get; set; } #endregion #region Parameter SchemaDeleteOption /// /// /// Use the SchemaDeleteOption to delete a custom inventory type (schema). /// If you don't choose this option, the system only deletes existing inventory data associated /// with the custom inventory type. Choose one of the following options:DisableSchema: If you choose this option, the system ignores all inventory data for /// the specified version, and any earlier versions. To enable this schema again, you /// must call the PutInventory operation for a version greater than the disabled /// version.DeleteSchema: This option deletes the specified custom type from the Inventory service. /// You can recreate the schema later, if you want. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.SimpleSystemsManagement.InventorySchemaDeleteOption")] public Amazon.SimpleSystemsManagement.InventorySchemaDeleteOption SchemaDeleteOption { get; set; } #endregion #region Parameter TypeName /// /// /// The name of the custom inventory type for which you want to delete either all previously /// collected data or the inventory type itself. /// /// #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 TypeName { 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 '*'. /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse). /// Specifying the name of a property of type Amazon.SimpleSystemsManagement.Model.DeleteInventoryResponse 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 TypeName parameter. /// The -PassThru parameter is deprecated, use -Select '^TypeName' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^TypeName' 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.TypeName), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Remove-SSMInventory (DeleteInventory)")) { 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.TypeName; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.ClientToken = this.ClientToken; context.DryRun = this.DryRun; context.SchemaDeleteOption = this.SchemaDeleteOption; context.TypeName = this.TypeName; #if MODULAR if (this.TypeName == null && ParameterWasBound(nameof(this.TypeName))) { WriteWarning("You are passing $null as a value for parameter TypeName 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.DeleteInventoryRequest(); if (cmdletContext.ClientToken != null) { request.ClientToken = cmdletContext.ClientToken; } if (cmdletContext.DryRun != null) { request.DryRun = cmdletContext.DryRun.Value; } if (cmdletContext.SchemaDeleteOption != null) { request.SchemaDeleteOption = cmdletContext.SchemaDeleteOption; } if (cmdletContext.TypeName != null) { request.TypeName = cmdletContext.TypeName; } 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.DeleteInventoryResponse CallAWSServiceOperation(IAmazonSimpleSystemsManagement client, Amazon.SimpleSystemsManagement.Model.DeleteInventoryRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Systems Manager", "DeleteInventory"); try { #if DESKTOP return client.DeleteInventory(request); #elif CORECLR return client.DeleteInventoryAsync(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.Boolean? DryRun { get; set; } public Amazon.SimpleSystemsManagement.InventorySchemaDeleteOption SchemaDeleteOption { get; set; } public System.String TypeName { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }