/******************************************************************************* * 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.WorkSpaces; using Amazon.WorkSpaces.Model; namespace Amazon.PowerShell.Cmdlets.WKS { /// /// Modifies multiple properties related to SAML 2.0 authentication, including the enablement /// status, user access URL, and relay state parameter name that are used for configuring /// federation with an SAML 2.0 identity provider. /// [Cmdlet("Edit", "WKSSamlProperty", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("None")] [AWSCmdlet("Calls the Amazon WorkSpaces ModifySamlProperties API operation.", Operation = new[] {"ModifySamlProperties"}, SelectReturnType = typeof(Amazon.WorkSpaces.Model.ModifySamlPropertiesResponse))] [AWSCmdletOutput("None or Amazon.WorkSpaces.Model.ModifySamlPropertiesResponse", "This cmdlet does not generate any output." + "The service response (type Amazon.WorkSpaces.Model.ModifySamlPropertiesResponse) can be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class EditWKSSamlPropertyCmdlet : AmazonWorkSpacesClientCmdlet, IExecutor { #region Parameter PropertiesToDelete /// /// /// The SAML properties to delete as part of your request.Specify one of the following options: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String[] PropertiesToDelete { get; set; } #endregion #region Parameter SamlProperties_RelayStateParameterName /// /// /// The relay state parameter name supported by the SAML 2.0 identity provider (IdP). /// When the end user is redirected to the user access URL from the WorkSpaces client /// application, this relay state parameter name is appended as a query parameter to the /// URL along with the relay state endpoint to return the user to the client application /// session.To use SAML 2.0 authentication with WorkSpaces, the IdP must support IdP-initiated /// deep linking for the relay state URL. Consult your IdP documentation for more information. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SamlProperties_RelayStateParameterName { get; set; } #endregion #region Parameter ResourceId /// /// /// The directory identifier for which you want to configure SAML properties. /// /// #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 SamlProperties_Status /// /// /// Indicates the status of SAML 2.0 authentication. These statuses include the following. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.WorkSpaces.SamlStatusEnum")] public Amazon.WorkSpaces.SamlStatusEnum SamlProperties_Status { get; set; } #endregion #region Parameter SamlProperties_UserAccessUrl /// /// /// The SAML 2.0 identity provider (IdP) user access URL is the URL a user would navigate /// to in their web browser in order to federate from the IdP and directly access the /// application, without any SAML 2.0 service provider (SP) bindings. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public System.String SamlProperties_UserAccessUrl { 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.WorkSpaces.Model.ModifySamlPropertiesResponse). /// 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, "Edit-WKSSamlProperty (ModifySamlProperties)")) { 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 if (this.PropertiesToDelete != null) { context.PropertiesToDelete = new List(this.PropertiesToDelete); } 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.SamlProperties_RelayStateParameterName = this.SamlProperties_RelayStateParameterName; context.SamlProperties_Status = this.SamlProperties_Status; context.SamlProperties_UserAccessUrl = this.SamlProperties_UserAccessUrl; // 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.WorkSpaces.Model.ModifySamlPropertiesRequest(); if (cmdletContext.PropertiesToDelete != null) { request.PropertiesToDelete = cmdletContext.PropertiesToDelete; } if (cmdletContext.ResourceId != null) { request.ResourceId = cmdletContext.ResourceId; } // populate SamlProperties var requestSamlPropertiesIsNull = true; request.SamlProperties = new Amazon.WorkSpaces.Model.SamlProperties(); System.String requestSamlProperties_samlProperties_RelayStateParameterName = null; if (cmdletContext.SamlProperties_RelayStateParameterName != null) { requestSamlProperties_samlProperties_RelayStateParameterName = cmdletContext.SamlProperties_RelayStateParameterName; } if (requestSamlProperties_samlProperties_RelayStateParameterName != null) { request.SamlProperties.RelayStateParameterName = requestSamlProperties_samlProperties_RelayStateParameterName; requestSamlPropertiesIsNull = false; } Amazon.WorkSpaces.SamlStatusEnum requestSamlProperties_samlProperties_Status = null; if (cmdletContext.SamlProperties_Status != null) { requestSamlProperties_samlProperties_Status = cmdletContext.SamlProperties_Status; } if (requestSamlProperties_samlProperties_Status != null) { request.SamlProperties.Status = requestSamlProperties_samlProperties_Status; requestSamlPropertiesIsNull = false; } System.String requestSamlProperties_samlProperties_UserAccessUrl = null; if (cmdletContext.SamlProperties_UserAccessUrl != null) { requestSamlProperties_samlProperties_UserAccessUrl = cmdletContext.SamlProperties_UserAccessUrl; } if (requestSamlProperties_samlProperties_UserAccessUrl != null) { request.SamlProperties.UserAccessUrl = requestSamlProperties_samlProperties_UserAccessUrl; requestSamlPropertiesIsNull = false; } // determine if request.SamlProperties should be set to null if (requestSamlPropertiesIsNull) { request.SamlProperties = null; } 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.WorkSpaces.Model.ModifySamlPropertiesResponse CallAWSServiceOperation(IAmazonWorkSpaces client, Amazon.WorkSpaces.Model.ModifySamlPropertiesRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon WorkSpaces", "ModifySamlProperties"); try { #if DESKTOP return client.ModifySamlProperties(request); #elif CORECLR return client.ModifySamlPropertiesAsync(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 List PropertiesToDelete { get; set; } public System.String ResourceId { get; set; } public System.String SamlProperties_RelayStateParameterName { get; set; } public Amazon.WorkSpaces.SamlStatusEnum SamlProperties_Status { get; set; } public System.String SamlProperties_UserAccessUrl { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => null; } } }