/******************************************************************************* * 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.CognitoIdentityProvider; using Amazon.CognitoIdentityProvider.Model; namespace Amazon.PowerShell.Cmdlets.CGIP { /// /// Sets the user pool multi-factor authentication (MFA) configuration. /// /// /// This action might generate an SMS text message. Starting June 1, 2021, US telecom /// carriers require you to register an origination phone number before you can send SMS /// messages to US phone numbers. If you use SMS text messages in Amazon Cognito, you /// must register a phone number with Amazon /// Pinpoint. Amazon Cognito uses the registered number automatically. Otherwise, /// Amazon Cognito users who must receive SMS messages might not be able to sign up, activate /// their accounts, or sign in. /// /// If you have never used SMS text messages with Amazon Cognito or any other Amazon Web /// Service, Amazon Simple Notification Service might place your account in the SMS sandbox. /// In sandbox /// mode, you can send messages only to verified phone numbers. After you test /// your app while in the sandbox environment, you can move out of the sandbox and into /// production. For more information, see /// SMS message settings for Amazon Cognito user pools in the Amazon Cognito Developer /// Guide. /// /// [Cmdlet("Set", "CGIPUserPoolMfaConfig", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)] [OutputType("Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse")] [AWSCmdlet("Calls the Amazon Cognito Identity Provider SetUserPoolMfaConfig API operation.", Operation = new[] {"SetUserPoolMfaConfig"}, SelectReturnType = typeof(Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse))] [AWSCmdletOutput("Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse", "This cmdlet returns an Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack." )] public partial class SetCGIPUserPoolMfaConfigCmdlet : AmazonCognitoIdentityProviderClientCmdlet, IExecutor { #region Parameter MfaConfiguration /// /// /// The MFA configuration. If you set the MfaConfiguration value to ‘ON’, only users who /// have set up an MFA factor can sign in. To learn more, see Adding /// Multi-Factor Authentication (MFA) to a user pool. Valid values include: /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] [AWSConstantClassSource("Amazon.CognitoIdentityProvider.UserPoolMfaType")] public Amazon.CognitoIdentityProvider.UserPoolMfaType MfaConfiguration { get; set; } #endregion #region Parameter SmsMfaConfiguration /// /// /// The SMS text message MFA configuration. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public Amazon.CognitoIdentityProvider.Model.SmsMfaConfigType SmsMfaConfiguration { get; set; } #endregion #region Parameter SoftwareTokenMfaConfiguration /// /// /// The software token MFA configuration. /// /// [System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)] public Amazon.CognitoIdentityProvider.Model.SoftwareTokenMfaConfigType SoftwareTokenMfaConfiguration { get; set; } #endregion #region Parameter UserPoolId /// /// /// The user pool 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 UserPoolId { 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.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse). /// Specifying the name of a property of type Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse 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 UserPoolId parameter. /// The -PassThru parameter is deprecated, use -Select '^UserPoolId' instead. This parameter will be removed in a future version. /// [System.Obsolete("The -PassThru parameter is deprecated, use -Select '^UserPoolId' 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.UserPoolId), MyInvocation.BoundParameters); if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Set-CGIPUserPoolMfaConfig (SetUserPoolMfaConfig)")) { 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.UserPoolId; } #pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute context.MfaConfiguration = this.MfaConfiguration; context.SmsMfaConfiguration = this.SmsMfaConfiguration; context.SoftwareTokenMfaConfiguration = this.SoftwareTokenMfaConfiguration; context.UserPoolId = this.UserPoolId; #if MODULAR if (this.UserPoolId == null && ParameterWasBound(nameof(this.UserPoolId))) { WriteWarning("You are passing $null as a value for parameter UserPoolId 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.CognitoIdentityProvider.Model.SetUserPoolMfaConfigRequest(); if (cmdletContext.MfaConfiguration != null) { request.MfaConfiguration = cmdletContext.MfaConfiguration; } if (cmdletContext.SmsMfaConfiguration != null) { request.SmsMfaConfiguration = cmdletContext.SmsMfaConfiguration; } if (cmdletContext.SoftwareTokenMfaConfiguration != null) { request.SoftwareTokenMfaConfiguration = cmdletContext.SoftwareTokenMfaConfiguration; } if (cmdletContext.UserPoolId != null) { request.UserPoolId = cmdletContext.UserPoolId; } 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.CognitoIdentityProvider.Model.SetUserPoolMfaConfigResponse CallAWSServiceOperation(IAmazonCognitoIdentityProvider client, Amazon.CognitoIdentityProvider.Model.SetUserPoolMfaConfigRequest request) { Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Cognito Identity Provider", "SetUserPoolMfaConfig"); try { #if DESKTOP return client.SetUserPoolMfaConfig(request); #elif CORECLR return client.SetUserPoolMfaConfigAsync(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 Amazon.CognitoIdentityProvider.UserPoolMfaType MfaConfiguration { get; set; } public Amazon.CognitoIdentityProvider.Model.SmsMfaConfigType SmsMfaConfiguration { get; set; } public Amazon.CognitoIdentityProvider.Model.SoftwareTokenMfaConfigType SoftwareTokenMfaConfiguration { get; set; } public System.String UserPoolId { get; set; } public System.Func Select { get; set; } = (response, cmdlet) => response; } } }