Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Header host override for stac and raster apis (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
slesaad authored Oct 9, 2023
1 parent 3a03ff9 commit 2e6aa12
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
4 changes: 1 addition & 3 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ VEDA_DOMAIN_ALT_HOSTED_ZONE_NAME=[OPTIONAL SECOND DOMAIN]
VEDA_RASTER_ENABLE_MOSAIC_SEARCH=TRUE
VEDA_RASTER_DATA_ACCESS_ROLE_ARN=[OPTIONAL ARN OF IAM ROLE TO BE ASSUMED BY RASTER API]


VEDA_RASTER_PATH_PREFIX=[OPTIONAL PATH PREFIX TO ADD TO TITILER ENDPOINTS]
VEDA_STAC_PATH_PREFIX=[OPTIONAL PATH PREFIX TO ADD TO TITILER ENDPOINTS]
VEDA_STAC_HOST=[OPTIONAL HOST FOR THE STAC API]

VEDA_DB_RDS_TYPE=[OPTIONAL RDS DATABASE TYPE, ex. t3.small, r5.16xlarge, etc]
VEDA_HOST=[OPTIONAL HOST/DOMAIN_NAME TO PROPAGATE TO STAC AND RASTER APIS]
30 changes: 27 additions & 3 deletions raster_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
from pydantic import BaseSettings, Field


class MyConfig(BaseSettings.Config):
"""Custom config class that support multiple env_prefixes"""

@classmethod
def prepare_field(cls, field) -> None:
"""Workaround to not overwrite ENV_PREFIX"""
if "env_names" in field.field_info.extra:
return
return super().prepare_field(field)


class vedaRasterSettings(BaseSettings):
"""Application settings"""
"""Raster settings"""

# Default options are optimized for CloudOptimized GeoTIFF
# For more information on GDAL env see: https://gdal.org/user/configoptions.html
Expand Down Expand Up @@ -68,11 +79,24 @@ class vedaRasterSettings(BaseSettings):
description="Optional path prefix to add to all api endpoints",
)

class Config:
class Config(MyConfig):
"""model config"""

env_file = ".env"
env_prefix = "VEDA_RASTER_"


veda_raster_settings = vedaRasterSettings()
class Settings(vedaRasterSettings):
"""Application Settings"""

host: Optional[str] = Field(
"",
description="Optional host to send to raster api", # propagate cf url to raster api
)

class Config(MyConfig):
"Model config"
env_prefix = "VEDA_"


veda_raster_settings = Settings()
11 changes: 8 additions & 3 deletions raster_api/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,15 @@ def __init__(
"AWS_REQUEST_PAYER", veda_raster_settings.aws_request_payer
)

raster_api_integration = (
aws_apigatewayv2_integrations_alpha.HttpLambdaIntegration(
construct_id, veda_raster_function
raster_api_integration = aws_apigatewayv2_integrations_alpha.HttpLambdaIntegration(
construct_id,
handler=veda_raster_function,
parameter_mapping=aws_apigatewayv2_alpha.ParameterMapping().overwrite_header(
"host",
aws_apigatewayv2_alpha.MappingValue.custom(veda_raster_settings.host),
)
if veda_raster_settings.host
else None,
)

domain_mapping = None
Expand Down
34 changes: 27 additions & 7 deletions stac_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,19 @@
from pydantic import BaseSettings, Field


class MyConfig(BaseSettings.Config):
"""Custom config class that support multiple env_prefixes"""

@classmethod
def prepare_field(cls, field) -> None:
"""Workaround to not overwrite ENV_PREFIX"""
if "env_names" in field.field_info.extra:
return
return super().prepare_field(field)


class vedaSTACSettings(BaseSettings):
"""Application settings"""
"""STAC settings"""

env: Dict = {}

Expand All @@ -23,16 +34,25 @@ class vedaSTACSettings(BaseSettings):
description="Optional path prefix to add to all api endpoints",
)

class Config(MyConfig):
"""model config"""

env_file = ".env"
env_prefix = "VEDA_STAC_"


class Settings(vedaSTACSettings):
"""Application Settings"""

host: Optional[str] = Field(
"",
description="Optional host to send to stac api", # stac api populates the urls in the catalog based on this
)

class Config:
"""model config"""

env_file = ".env"
env_prefix = "VEDA_STAC_"
class Config(MyConfig):
"Model config"
env_prefix = "VEDA_"


veda_stac_settings = vedaSTACSettings()
veda_stac_settings = Settings()
print(veda_stac_settings)

0 comments on commit 2e6aa12

Please sign in to comment.