|
1 | 1 | from datetime import datetime |
2 | 2 | from typing import Any, Dict, List, Literal, Optional, Type, Union |
3 | 3 |
|
4 | | -from pydantic import BaseModel, model_validator |
| 4 | +from pydantic import BaseModel, field_validator, model_validator |
5 | 5 | from pydantic.networks import IPvAnyNetwork |
6 | 6 |
|
| 7 | +from aws_lambda_powertools.utilities.parser.functions import _validate_source_ip |
| 8 | + |
7 | 9 |
|
8 | 10 | class ApiGatewayUserCertValidity(BaseModel): |
9 | 11 | notBefore: str |
@@ -31,12 +33,17 @@ class APIGatewayEventIdentity(BaseModel): |
31 | 33 | principalOrgId: Optional[str] = None |
32 | 34 | # see #1562, temp workaround until API Gateway fixes it the Test button payload |
33 | 35 | # removing it will not be considered a regression in the future |
34 | | - sourceIp: Union[IPvAnyNetwork, Literal["test-invoke-source-ip"]] |
| 36 | + sourceIp: Union[IPvAnyNetwork, str] |
35 | 37 | user: Optional[str] = None |
36 | 38 | userAgent: Optional[str] = None |
37 | 39 | userArn: Optional[str] = None |
38 | 40 | clientCert: Optional[ApiGatewayUserCert] = None |
39 | 41 |
|
| 42 | + @field_validator("sourceIp", mode="before") |
| 43 | + @classmethod |
| 44 | + def _validate_source_ip(cls, value): |
| 45 | + return _validate_source_ip(value=value) |
| 46 | + |
40 | 47 |
|
41 | 48 | class APIGatewayEventAuthorizer(BaseModel): |
42 | 49 | claims: Optional[Dict[str, Any]] = None |
|
0 commit comments