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

fix(ingest): requester pays config in validation #388

Merged
merged 2 commits into from
Jun 4, 2024
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
5 changes: 5 additions & 0 deletions ingest_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class IngestorConfig(BaseSettings):
None, description="ARN of AWS Role used to validate access to S3 data"
)

raster_aws_request_payer: Optional[str] = Field(
None,
description="Set optional global parameter to 'requester' if the requester agrees to pay S3 transfer costs",
)

stac_api_url: str = Field(description="URL of STAC API used to serve STAC Items")

raster_api_url: str = Field(
Expand Down
4 changes: 4 additions & 0 deletions ingest_api/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def __init__(
build_api_lambda_params["data_access_role"] = iam.Role.from_role_arn(
self, "data-access-role", config.raster_data_access_role_arn
)

if config.raster_aws_request_payer:
lambda_env["AWS_REQUEST_PAYER"] = config.raster_aws_request_payer

build_api_lambda_params["env"] = lambda_env

# create lambda
Expand Down
1 change: 0 additions & 1 deletion ingest_api/runtime/src/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def validated_token(
required_scopes: security.SecurityScopes,
) -> Dict:
# Parse & validate token
logger.info(f"\nToken String {token_str}")
Copy link
Member

Choose a reason for hiding this comment

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

🙇

try:
token = jwt.decode(
token_str,
Expand Down
5 changes: 5 additions & 0 deletions ingest_api/runtime/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class Settings(BaseSettings):
description="ARN of AWS Role used to validate access to S3 data"
)

aws_request_payer: Optional[str] = Field(
None,
description="Set optional global parameter to 'requester' if the requester agrees to pay S3 transfer costs",
)

stac_url: AnyHttpUrl = Field(description="URL of STAC API")

userpool_id: str = Field(description="The Cognito Userpool used for authentication")
Expand Down
9 changes: 8 additions & 1 deletion ingest_api/runtime/src/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ def s3_object_is_accessible(bucket: str, key: str):
"""
Ensure we can send HEAD requests to S3 objects.
"""
from src.main import settings

client = boto3.client("s3", **get_s3_credentials())
try:
client.head_object(Bucket=bucket, Key=key)
if settings.aws_request_payer:
client.head_object(
Bucket=bucket, Key=key, RequestPayer=settings.aws_request_payer
)
else:
client.head_object(Bucket=bucket, Key=key)
except client.exceptions.ClientError as e:
raise ValueError(
f"Asset not accessible: {e.__dict__['response']['Error']['Message']}"
Expand Down