|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"). You may not use |
| 4 | + * this file except in compliance with the License. A copy of the License is located at |
| 5 | + * |
| 6 | + * http://aws.amazon.com/apache2.0 |
| 7 | + * |
| 8 | + * or in the "license" file accompanying this file. |
| 9 | + * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR |
| 10 | + * CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + * ***************************************************************************** |
| 13 | + * |
| 14 | + * AWS Tools for Windows (TM) PowerShell (TM) |
| 15 | + * |
| 16 | + */ |
| 17 | + |
| 18 | +using System; |
| 19 | +using System.Collections.Generic; |
| 20 | +using System.Linq; |
| 21 | +using System.Management.Automation; |
| 22 | +using System.Text; |
| 23 | +using Amazon.PowerShell.Common; |
| 24 | +using Amazon.Runtime; |
| 25 | +using Amazon.DSQL; |
| 26 | +using Amazon.DSQL.Model; |
| 27 | + |
| 28 | +namespace Amazon.PowerShell.Cmdlets.DSQL |
| 29 | +{ |
| 30 | + /// <summary> |
| 31 | + /// Retrieves the resource-based policy document attached to a cluster. This policy defines |
| 32 | + /// the access permissions and conditions for the cluster. |
| 33 | + /// </summary> |
| 34 | + [Cmdlet("Get", "DSQLClusterPolicy")] |
| 35 | + [OutputType("Amazon.DSQL.Model.GetClusterPolicyResponse")] |
| 36 | + [AWSCmdlet("Calls the Amazon Aurora DSQL GetClusterPolicy API operation.", Operation = new[] {"GetClusterPolicy"}, SelectReturnType = typeof(Amazon.DSQL.Model.GetClusterPolicyResponse))] |
| 37 | + [AWSCmdletOutput("Amazon.DSQL.Model.GetClusterPolicyResponse", |
| 38 | + "This cmdlet returns an Amazon.DSQL.Model.GetClusterPolicyResponse object containing multiple properties." |
| 39 | + )] |
| 40 | + public partial class GetDSQLClusterPolicyCmdlet : AmazonDSQLClientCmdlet, IExecutor |
| 41 | + { |
| 42 | + |
| 43 | + protected override bool IsGeneratedCmdlet { get; set; } = true; |
| 44 | + |
| 45 | + #region Parameter Identifier |
| 46 | + /// <summary> |
| 47 | + /// <para> |
| 48 | + /// <para>The ID of the cluster to retrieve the policy from.</para> |
| 49 | + /// </para> |
| 50 | + /// </summary> |
| 51 | + #if !MODULAR |
| 52 | + [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)] |
| 53 | + #else |
| 54 | + [System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)] |
| 55 | + [System.Management.Automation.AllowEmptyString] |
| 56 | + [System.Management.Automation.AllowNull] |
| 57 | + #endif |
| 58 | + [Amazon.PowerShell.Common.AWSRequiredParameter] |
| 59 | + public System.String Identifier { get; set; } |
| 60 | + #endregion |
| 61 | + |
| 62 | + #region Parameter Select |
| 63 | + /// <summary> |
| 64 | + /// Use the -Select parameter to control the cmdlet output. The default value is '*'. |
| 65 | + /// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.DSQL.Model.GetClusterPolicyResponse). |
| 66 | + /// Specifying the name of a property of type Amazon.DSQL.Model.GetClusterPolicyResponse will result in that property being returned. |
| 67 | + /// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value. |
| 68 | + /// </summary> |
| 69 | + [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] |
| 70 | + public string Select { get; set; } = "*"; |
| 71 | + #endregion |
| 72 | + |
| 73 | + #region Parameter PassThru |
| 74 | + /// <summary> |
| 75 | + /// Changes the cmdlet behavior to return the value passed to the Identifier parameter. |
| 76 | + /// The -PassThru parameter is deprecated, use -Select '^Identifier' instead. This parameter will be removed in a future version. |
| 77 | + /// </summary> |
| 78 | + [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^Identifier' instead. This parameter will be removed in a future version.")] |
| 79 | + [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] |
| 80 | + public SwitchParameter PassThru { get; set; } |
| 81 | + #endregion |
| 82 | + |
| 83 | + protected override void ProcessRecord() |
| 84 | + { |
| 85 | + this._AWSSignerType = "v4"; |
| 86 | + base.ProcessRecord(); |
| 87 | + |
| 88 | + var context = new CmdletContext(); |
| 89 | + |
| 90 | + // allow for manipulation of parameters prior to loading into context |
| 91 | + PreExecutionContextLoad(context); |
| 92 | + |
| 93 | + #pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute |
| 94 | + if (ParameterWasBound(nameof(this.Select))) |
| 95 | + { |
| 96 | + context.Select = CreateSelectDelegate<Amazon.DSQL.Model.GetClusterPolicyResponse, GetDSQLClusterPolicyCmdlet>(Select) ?? |
| 97 | + throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select)); |
| 98 | + if (this.PassThru.IsPresent) |
| 99 | + { |
| 100 | + throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select)); |
| 101 | + } |
| 102 | + } |
| 103 | + else if (this.PassThru.IsPresent) |
| 104 | + { |
| 105 | + context.Select = (response, cmdlet) => this.Identifier; |
| 106 | + } |
| 107 | + #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute |
| 108 | + context.Identifier = this.Identifier; |
| 109 | + #if MODULAR |
| 110 | + if (this.Identifier == null && ParameterWasBound(nameof(this.Identifier))) |
| 111 | + { |
| 112 | + WriteWarning("You are passing $null as a value for parameter Identifier 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."); |
| 113 | + } |
| 114 | + #endif |
| 115 | + |
| 116 | + // allow further manipulation of loaded context prior to processing |
| 117 | + PostExecutionContextLoad(context); |
| 118 | + |
| 119 | + var output = Execute(context) as CmdletOutput; |
| 120 | + ProcessOutput(output); |
| 121 | + } |
| 122 | + |
| 123 | + #region IExecutor Members |
| 124 | + |
| 125 | + public object Execute(ExecutorContext context) |
| 126 | + { |
| 127 | + var cmdletContext = context as CmdletContext; |
| 128 | + // create request |
| 129 | + var request = new Amazon.DSQL.Model.GetClusterPolicyRequest(); |
| 130 | + |
| 131 | + if (cmdletContext.Identifier != null) |
| 132 | + { |
| 133 | + request.Identifier = cmdletContext.Identifier; |
| 134 | + } |
| 135 | + |
| 136 | + CmdletOutput output; |
| 137 | + |
| 138 | + // issue call |
| 139 | + var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint); |
| 140 | + try |
| 141 | + { |
| 142 | + var response = CallAWSServiceOperation(client, request); |
| 143 | + object pipelineOutput = null; |
| 144 | + pipelineOutput = cmdletContext.Select(response, this); |
| 145 | + output = new CmdletOutput |
| 146 | + { |
| 147 | + PipelineOutput = pipelineOutput, |
| 148 | + ServiceResponse = response |
| 149 | + }; |
| 150 | + } |
| 151 | + catch (Exception e) |
| 152 | + { |
| 153 | + output = new CmdletOutput { ErrorResponse = e }; |
| 154 | + } |
| 155 | + |
| 156 | + return output; |
| 157 | + } |
| 158 | + |
| 159 | + public ExecutorContext CreateContext() |
| 160 | + { |
| 161 | + return new CmdletContext(); |
| 162 | + } |
| 163 | + |
| 164 | + #endregion |
| 165 | + |
| 166 | + #region AWS Service Operation Call |
| 167 | + |
| 168 | + private Amazon.DSQL.Model.GetClusterPolicyResponse CallAWSServiceOperation(IAmazonDSQL client, Amazon.DSQL.Model.GetClusterPolicyRequest request) |
| 169 | + { |
| 170 | + Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Aurora DSQL", "GetClusterPolicy"); |
| 171 | + try |
| 172 | + { |
| 173 | + #if DESKTOP |
| 174 | + return client.GetClusterPolicy(request); |
| 175 | + #elif CORECLR |
| 176 | + return client.GetClusterPolicyAsync(request).GetAwaiter().GetResult(); |
| 177 | + #else |
| 178 | + #error "Unknown build edition" |
| 179 | + #endif |
| 180 | + } |
| 181 | + catch (AmazonServiceException exc) |
| 182 | + { |
| 183 | + var webException = exc.InnerException as System.Net.WebException; |
| 184 | + if (webException != null) |
| 185 | + { |
| 186 | + throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException); |
| 187 | + } |
| 188 | + throw; |
| 189 | + } |
| 190 | + } |
| 191 | + |
| 192 | + #endregion |
| 193 | + |
| 194 | + internal partial class CmdletContext : ExecutorContext |
| 195 | + { |
| 196 | + public System.String Identifier { get; set; } |
| 197 | + public System.Func<Amazon.DSQL.Model.GetClusterPolicyResponse, GetDSQLClusterPolicyCmdlet, object> Select { get; set; } = |
| 198 | + (response, cmdlet) => response; |
| 199 | + } |
| 200 | + |
| 201 | + } |
| 202 | +} |
0 commit comments