Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the boto3 responses #208

Open
swyckoff opened this issue Apr 6, 2023 · 1 comment
Open

Return the boto3 responses #208

swyckoff opened this issue Apr 6, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@swyckoff
Copy link

swyckoff commented Apr 6, 2023

Objective

I want to verify that a method call did what was expected.

How to accomplish it

Returning the underlying boto3 response from a method call would achieve this.

For example the init.py/initiate_forgot_password method could be

def initiate_forgot_password(self):
        """
        Sends a verification code to the user to use to change their password.
        """
        params = {"ClientId": self.client_id, "Username": self.username}
        self._add_secret_hash(params, "SecretHash")
        return self.client.forgot_password(**params) # Added return

Justification

Calling initiate_forgot_password when a user hasn't verified their signup information doesn't seem to send a password request. The type definitions for mypy_boto3 indicate that it could be useful to see the response information.

From mypy_boto3_congito_idp

def forgot_password(
        self,
        *,
        ClientId: str,
        Username: str,
        SecretHash: str = ...,
        UserContextData: UserContextDataTypeTypeDef = ...,
        AnalyticsMetadata: AnalyticsMetadataTypeTypeDef = ...,
        ClientMetadata: Mapping[str, str] = ...
    ) -> ForgotPasswordResponseTypeDef:
        """
        Calling this API causes a message to be sent to the end user with a confirmation
        code that is required to change the user's password.

        [Show boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.forgot_password)
        [Show boto3-stubs documentation](https://youtype.github.io/boto3_stubs_docs/mypy_boto3_cognito_idp/client/#forgot_password)
        """

So this:

resp = user.initiate_forgot_password()
print(resp) # empty

becomes:

resp = user.initiate_forgot_password()
print(resp)
{
    'CodeDeliveryDetails': {'Destination': 's***@y***', 'DeliveryMedium': 'EMAIL', 'AttributeName': 'email'},
    'ResponseMetadata': {
        ...,
        'HTTPStatusCode': 200,
        'HTTPHeaders': {
            ...
        },
        'RetryAttempts': 0
    }
}

which at least let's you see if the medium is near what was expected. In my case I noticed a user's email was wrong

@swyckoff
Copy link
Author

swyckoff commented Apr 6, 2023

Added a PR for this - PR#209

@ludeeus ludeeus added the enhancement New feature or request label May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants