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

feat(event_source): add AWS Transfer Family classes #5912

Merged
merged 7 commits into from
Jan 27, 2025

Conversation

leandrodamascena
Copy link
Contributor

@leandrodamascena leandrodamascena commented Jan 23, 2025

Issue number: #5904

Summary

Changes

This pull request introduces support for AWS Transfer Family custom identity providers, simplifying Lambda-based authorization workflows.

Keys features

  • New TransferFamilyAuthorizer and TransferFamilyAuthorizerResponse classes
  • Simplified authentication response builder for AWS Transfer Family
  • Support for home directory configurations
  • Enhanced type safety and error handling

User experience

from __future__ import annotations

from typing import Any

from aws_lambda_powertools import Logger
from aws_lambda_powertools.utilities import parameters
from aws_lambda_powertools.utilities.data_classes import (
    TransferFamilyAuthorizer,
    TransferFamilyAuthorizerResponse,
    event_source,
)
from aws_lambda_powertools.utilities.typing import LambdaContext

logger = Logger()

@event_source(data_class=TransferFamilyAuthorizer)
def lambda_handler(event: TransferFamilyAuthorizer, context: LambdaContext):

    username = event.username
    password = event.password or None

    response: dict[str, Any] = {}
    build_response = TransferFamilyAuthorizerResponse()

    try:
        user_data = parameters.get_secret(f"/sftp/{username}", transform="json")

        logger.info(f"Credentials found for user {username}")

        stored_username = user_data["username"]
        stored_secret = user_data["password"]
        stored_gid = user_data["gid"]
        stored_uid = user_data["uid"]
        stored_role = user_data["role"]
        stored_directory = user_data["efs-server"]
        stored_entry = user_data["entry"]
        stored_directory_type = user_data["directory-type"]
        home_directory_details = {"Entry": stored_entry, "Target": stored_directory}

        if username == stored_username and password == stored_secret:
            logger.info(f"User {username} informed a valid password")

            response = build_response.build_authentication_response_efs( # (1)!
                role_arn=stored_role,
                user_gid=stored_gid,
                user_uid=stored_uid,
                home_directory_type=stored_directory_type,
                home_directory_details=home_directory_details,
            )
        else:
            logger.info(f"User {username} informed a invalid password")

    except Exception as e:
        logger.exception(e)
        logger.info(f"Credentials not valid for user {username}")

    return response

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation tests labels Jan 23, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jan 23, 2025
@leandrodamascena leandrodamascena linked an issue Jan 23, 2025 that may be closed by this pull request
2 tasks
@github-actions github-actions bot added feature New feature or functionality and removed documentation Improvements or additions to documentation labels Jan 23, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 24, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 24, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 24, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 24, 2025
Copy link

codecov bot commented Jan 24, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.23%. Comparing base (4485ebd) to head (82e7d89).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5912      +/-   ##
===========================================
+ Coverage    96.22%   96.23%   +0.01%     
===========================================
  Files          233      234       +1     
  Lines        10965    11010      +45     
  Branches       790      797       +7     
===========================================
+ Hits         10551    10596      +45     
  Misses         327      327              
  Partials        87       87              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 24, 2025
@pull-request-size pull-request-size bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jan 24, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 24, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 24, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 24, 2025
@leandrodamascena leandrodamascena marked this pull request as ready for review January 24, 2025 15:51
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 24, 2025
@leandrodamascena leandrodamascena requested a review from a team as a code owner January 24, 2025 15:51
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 24, 2025
anafalcao
anafalcao previously approved these changes Jan 24, 2025
Copy link
Collaborator

@anafalcao anafalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing PR!! Thanks, @leandrodamascena, approved

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Jan 27, 2025
@pull-request-size pull-request-size bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 27, 2025
@leandrodamascena leandrodamascena force-pushed the datasource/transfer-family branch from 25a9846 to 99f484d Compare January 27, 2025 10:27
@pull-request-size pull-request-size bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 27, 2025
@leandrodamascena leandrodamascena merged commit b84a9b2 into develop Jan 27, 2025
12 checks passed
@leandrodamascena leandrodamascena deleted the datasource/transfer-family branch January 27, 2025 11:33
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Add AWS Transfer Family event source data class
2 participants