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(parser): add AWS Transfer Family model #5906

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions aws_lambda_powertools/utilities/parser/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
)
from .sns import SnsModel, SnsNotificationModel, SnsRecordModel
from .sqs import SqsAttributesModel, SqsModel, SqsMsgAttributeModel, SqsRecordModel
from .transfer_family import TransferFamily
from .vpc_lattice import VpcLatticeModel
from .vpc_latticev2 import VpcLatticeV2Model

Expand Down Expand Up @@ -179,6 +180,7 @@
"SqsAttributesModel",
"S3SqsEventNotificationModel",
"S3SqsEventNotificationRecordModel",
"TransferFamily",
"APIGatewayProxyEventModel",
"APIGatewayEventRequestContext",
"APIGatewayEventAuthorizer",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from typing import Literal, Optional

from pydantic import BaseModel, Field
from pydantic.networks import IPvAnyAddress


class TransferFamily(BaseModel):
username: str
password: Optional[str] = None
protocol: Literal["SFTP", "FTP", "FTPS"]
server_id: str = Field(..., alias="serverId")
source_ip: IPvAnyAddress = Field(..., alias="sourceIp")
5 changes: 3 additions & 2 deletions docs/utilities/parser.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ The example above uses `SqsModel`. Other built-in models can be found below.
| **ApiGatewayAuthorizerRequest** | Lambda Event Source payload for Amazon API Gateway Lambda Authorizer with Request |
| **APIGatewayProxyEventV2Model** | Lambda Event Source payload for Amazon API Gateway v2 payload |
| **ApiGatewayAuthorizerRequestV2** | Lambda Event Source payload for Amazon API Gateway v2 Lambda Authorizer |
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
| **APIGatewayWebSocketMessageEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API message body |
| **APIGatewayWebSocketConnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $connect message |
| **APIGatewayWebSocketDisconnectEventModel** | Lambda Event Source payload for Amazon API Gateway WebSocket API $disconnect message |
| **BedrockAgentEventModel** | Lambda Event Source payload for Bedrock Agents |
| **CloudFormationCustomResourceCreateModel** | Lambda Event Source payload for AWS CloudFormation `CREATE` operation |
Expand All @@ -132,6 +132,7 @@ The example above uses `SqsModel`. Other built-in models can be found below.
| **SesModel** | Lambda Event Source payload for Amazon Simple Email Service |
| **SnsModel** | Lambda Event Source payload for Amazon Simple Notification Service |
| **SqsModel** | Lambda Event Source payload for Amazon SQS |
| **TransferFamily** | Lambda Event Source payload for AWS Transfer Family custom identity provider |
| **VpcLatticeModel** | Lambda Event Source payload for Amazon VPC Lattice |
| **VpcLatticeV2Model** | Lambda Event Source payload for Amazon VPC Lattice v2 payload |

Expand Down
7 changes: 7 additions & 0 deletions tests/events/TransferFamily.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"username": "value",
"password": "value",
"protocol": "SFTP",
"serverId": "s-abcd123456",
"sourceIp": "192.168.0.100"
}
25 changes: 25 additions & 0 deletions tests/unit/parser/_pydantic/test_aws_transfer_family.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from aws_lambda_powertools.utilities.parser.models import TransferFamily
from tests.functional.utils import load_event


def test_aws_transfer_family_model():
raw_event = load_event("TransferFamily.json")
parsed_event = TransferFamily(**raw_event)

assert parsed_event.username == raw_event["username"]
assert parsed_event.password == raw_event["password"]
assert parsed_event.protocol == raw_event["protocol"]
assert parsed_event.server_id == raw_event["serverId"]
assert str(parsed_event.source_ip) == raw_event["sourceIp"]


def test_aws_transfer_family_model_without_password():
raw_event = load_event("TransferFamily.json")
del raw_event["password"]
parsed_event = TransferFamily(**raw_event)

assert parsed_event.username == raw_event["username"]
assert parsed_event.password is None
assert parsed_event.protocol == raw_event["protocol"]
assert parsed_event.server_id == raw_event["serverId"]
assert str(parsed_event.source_ip) == raw_event["sourceIp"]
Loading