/******************************************************************************* * 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.KeyManagementService; using Amazon.KeyManagementService.Model; namespace Amazon.PowerShell.Cmdlets.KMS { /// /// Deletes a grant. Typically, you retire a grant when you no longer need its permissions. /// To identify the grant to retire, use a grant /// token, or both the grant ID and a key identifier (key ID or key ARN) of the KMS /// key. The CreateGrant operation returns both values. /// /// /// /// This operation can be called by the retiring principal for a grant, by the /// grantee principal if the grant allows the RetireGrant operation, /// and by the Amazon Web Services account in which the grant is created. It can also /// be called by principals to whom permission for retiring a grant is delegated. For /// details, see Retiring /// and revoking grants in the Key Management Service Developer Guide. /// /// For detailed information about grants, including grant terminology, see Grants /// in KMS in the Key Management Service Developer Guide. For examples /// of working with grants in several programming languages, see Programming /// grants. /// Cross-account use: Yes. You can retire a grant on a KMS key in a different /// Amazon Web Services account. /// Required permissions::Permission to retire a grant is determined primarily /// by the grant. For details, see Retiring /// and revoking grants in the Key Management Service Developer Guide. /// Related operations: /// [Cmdlet("Disable", "KMSGrant", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("None")] [AWSCmdlet("Calls the AWS Key Management Service RetireGrant API operation.", Operation = new[] {"RetireGrant"}, SelectReturnType = typeof(Amazon.KeyManagementService.Model.RetireGrantResponse))] [AWSCmdletOutput("None or Amazon.KeyManagementService.Model.RetireGrantResponse", "This cmdlet does not generate any output." + "The service response (type Amazon.KeyManagementService.Model.RetireGrantResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class DisableKMSGrantCmdlet : AmazonKeyManagementServiceClientCmdlet, IExecutor { #region Parameter DryRun /// /// /// Checks if your request will succeed. DryRun is an optional parameter. /// To learn more about how to use this parameter, see Testing /// your KMS API calls in the Key Management Service Developer Guide. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.Boolean? DryRun { get; set; } #endregion #region Parameter GrantId /// /// /// Identifies the grant to retire. To get the grant ID, use CreateGrant, ListGrants, /// or ListRetirableGrants. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String GrantId { get; set; } #endregion #region Parameter GrantToken /// /// /// Identifies the grant to be retired. You can use a grant token to identify a new grant /// even before it has achieved eventual consistency.Only the CreateGrant operation returns a grant token. For details, see Grant /// token and Eventual /// consistency in the Key Management Service Developer Guide. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String GrantToken { get; set; } #endregion #region Parameter KeyId /// /// /// The key ARN KMS key associated with the grant. To find the key ARN, use the ListKeys /// operation.For example: arn:aws:kms:us-east-2:444455556666:key/1234abcd-12ab-34cd-56ef-1234567890ab /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String KeyId { 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.KeyManagementService.Model.RetireGrantResponse). /// 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 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.GrantToken), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Disable-KMSGrant (RetireGrant)")) { return; } var context = new CmdletContext(); // allow for manipulation of parameters prior to loading into context PreExecutionContextLoad(context); if (ParameterWasBound(nameof(this.Select))) { context.Select = CreateSelectDelegate(Select) ?? throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); } context.DryRun = this.DryRun; context.GrantId = this.GrantId; context.GrantToken = this.GrantToken; context.KeyId = this.KeyId; // 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.KeyManagementService.Model.RetireGrantRequest(); if (cmdletContext.DryRun != null) { request.DryRun = cmdletContext.DryRun.Value; } if (cmdletContext.GrantId != null) { request.GrantId = cmdletContext.GrantId; } if (cmdletContext.GrantToken != null) { request.GrantToken = cmdletContext.GrantToken; } if (cmdletContext.KeyId != null) { request.KeyId = cmdletContext.KeyId; } 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.KeyManagementService.Model.RetireGrantResponse CallAWSServiceOperation(IAmazonKeyManagementService client, Amazon.KeyManagementService.Model.RetireGrantRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "AWS Key Management Service", "RetireGrant"); try { #if DESKTOP return client.RetireGrant(request); #elif CORECLR return client.RetireGrantAsync(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? DryRun { get; set; } public System.String GrantId { get; set; } public System.String GrantToken { get; set; } public System.String KeyId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => null; } } }