Skip to content

Commit

Permalink
feat(release): Support disabling default API Gateway endpoints and ad…
Browse files Browse the repository at this point in the history
…d custom soil-texture colormap to raster-api (#445)

# Added in this release

- Adds a new custom colormap option to the raster-api because the source
parameter definitions for this colormap are too long for the production
firewall restrictions. Why: #441

- Add support to disable default API Gateway endpoints. Why: [Prevent
Users from Bypassing CloudFront to Invoke API Gateway
Directly](NASA-IMPACT/veda-architecture#452)
  • Loading branch information
anayeaye authored Oct 30, 2024
2 parents 5fcae8c + aa3292e commit 1d2d8fd
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 0 deletions.
1 change: 1 addition & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ VEDA_CLOUDFRONT=
VEDA_CLOUDFRONT_OAC=[OPTIONAL, CONFIGURES ORIGIN ACCESS CONTROL, DEFAULTS TO TRUE]
VEDA_CUSTOM_HOST=
VEDA_SHARED_WEB_ACL_ID=[OPTIONAL ID ARN for WEB ACL]
VEDA_DISABLE_DEFAULT_APIGW_ENDPOINT=[OPTIONAL BOOL TO DISABLE DEFAULT API GATEWAY ENDPOINTS]
5 changes: 5 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@ class vedaAppSettings(BaseSettings):
None, description="Custom domain name, i.e. veda-backend.xyz"
)

disable_default_apigw_endpoint: Optional[bool] = Field(
False,
description="Boolean to disable default API gateway endpoints for stac, raster, and ingest APIs. Defaults to false.",
)

def cdk_env(self) -> dict:
"""Load a cdk environment dict for stack"""

Expand Down
5 changes: 5 additions & 0 deletions ingest_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class IngestorConfig(BaseSettings):
description="Raster API root path. Used to infer url of raster-api before app synthesis.",
)

disable_default_apigw_endpoint: Optional[bool] = Field(
False,
description="Boolean to disable default API gateway endpoints for stac, raster, and ingest APIs. Defaults to false.",
)

class Config:
case_sensitive = False
env_file = ".env"
Expand Down
3 changes: 3 additions & 0 deletions ingest_api/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def __init__(
construct_id=construct_id,
handler=self.api_lambda,
custom_host=config.custom_host,
disable_default_apigw_endpoint=config.disable_default_apigw_endpoint,
)

stack_name = Stack.of(self).stack_name
Expand Down Expand Up @@ -188,6 +189,7 @@ def build_api(
construct_id: str,
handler: aws_lambda.IFunction,
custom_host: Optional[str],
disable_default_apigw_endpoint: Optional[bool],
) -> aws_apigatewayv2_alpha.HttpApi:
integration_kwargs = dict(handler=handler)
if custom_host:
Expand All @@ -211,6 +213,7 @@ def build_api(
self,
f"{stack_name}-{construct_id}",
default_integration=ingest_api_integration,
disable_execute_api_endpoint=disable_default_apigw_endpoint,
)

def build_jwks_url(self, userpool_id: str) -> str:
Expand Down
4 changes: 4 additions & 0 deletions raster_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ class vedaRasterSettings(BaseSettings):
"VEDA (Visualization, Exploration, and Data Analysis)",
description="Name of the STAC Catalog",
)
disable_default_apigw_endpoint: Optional[bool] = Field(
False,
description="Boolean to disable default API gateway endpoints for stac, raster, and ingest APIs. Defaults to false.",
)

class Config:
"""model config"""
Expand Down
1 change: 1 addition & 0 deletions raster_api/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def __init__(
self,
f"{stack_name}-{construct_id}",
default_integration=raster_api_integration,
disable_execute_api_endpoint=veda_raster_settings.disable_default_apigw_endpoint,
)

CfnOutput(
Expand Down
30 changes: 30 additions & 0 deletions raster_api/runtime/src/cmap_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,33 @@ for c, v in internal_colormap.items():

np.save("nlcd.npy", cmap)
```

##### Soil texture colormap

```python
from rio_tiler.colormap import parse_color
import numpy as np

# These categories are based on a USGS soil texture chart, not an official set of color mappings for soil texture categories
texture_categories = {
"1": "#F89E61",
"2": "#BA8560",
"3": "#D8D2B4",
"4": "#AE734C",
"5": "#9E8478",
"6": "#C6A365",
"7": "#B4A67D",
"8": "#E1D4C4",
"9": "#BEB56D",
"10": "#777C7A",
"11": "#A89B6F",
"12": "#E9E2AF"
}

cmap = np.zeros((256, 4), dtype=np.uint8)
cmap[:] = np.array([0, 0, 0, 255])
for k in texture_categories.keys():
cmap[int(k)] = np.array(parse_color(texture_categories[k]))

np.save("soil_texture.npy", cmap)
```
Binary file added raster_api/runtime/src/cmap_data/soil_texture.npy
Binary file not shown.
4 changes: 4 additions & 0 deletions stac_api/infrastructure/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class vedaSTACSettings(BaseSettings):
stac_enable_transactions: bool = Field(
False, description="Whether to enable transactions endpoints"
)
disable_default_apigw_endpoint: Optional[bool] = Field(
False,
description="Boolean to disable default API gateway endpoints for stac, raster, and ingest APIs. Defaults to false.",
)

@root_validator
def check_transaction_fields(cls, values):
Expand Down
1 change: 1 addition & 0 deletions stac_api/infrastructure/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def __init__(
self,
f"{stack_name}-{construct_id}",
default_integration=stac_api_integration,
disable_execute_api_endpoint=veda_stac_settings.disable_default_apigw_endpoint,
)

CfnOutput(
Expand Down

0 comments on commit 1d2d8fd

Please sign in to comment.