Skip to content
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 .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@ VEDA_CLOUDFRONT_OAC=[OPTIONAL, CONFIGURES ORIGIN ACCESS CONTROL, DEFAULTS TO TRU
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]
VEDA_STAC_ENABLE_STAC_AUTH_PROXY=
VEDA_TENANT_FILTER_FIELD=[OPTIONAL STRING, DEFAULTS TO "eic:tenant"]
2 changes: 1 addition & 1 deletion .github/workflows/data/barc-thomasfire.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@
],
"dashboard:is_periodic": false,
"dashboard:time_density": null,
"dashboard:tenant": "fire"
"eic:tenant": "fire"
}
2 changes: 1 addition & 1 deletion .github/workflows/data/caldor-fire-behavior.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@
],
"dashboard:is_periodic": false,
"dashboard:time_density": null,
"dashboard:tenant": "fire"
"eic:tenant": "fire"
}
2 changes: 1 addition & 1 deletion .github/workflows/data/noaa-emergency-response.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"interval": [["2005-01-01T00:00:00Z", null]]
}
},
"dashboard:tenant": "emergency"
"eic:tenant": "emergency"
}
5 changes: 4 additions & 1 deletion stac_api/runtime/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ async def lifespan(app: FastAPI):
openapi_spec_endpoint=api_settings.openapi_spec_endpoint,
root_path=api_settings.root_path,
collections_filter={
"cls": f"{CollectionFilter.__module__}:{CollectionFilter.__name__}"
"cls": f"{CollectionFilter.__module__}:{CollectionFilter.__name__}",
"kwargs": {
"tenant_filter_field": api_settings.tenant_filter_field,
},
},
items_filter={
"cls": f"{ItemFilter.__module__}:{ItemFilter.__name__}",
Expand Down
4 changes: 4 additions & 0 deletions stac_api/runtime/src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ class _ApiSettings(Settings):
"http://localhost:8081", description="Custom host URL"
)
git_sha: Optional[str] = None
tenant_filter_field: str = Field(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay! I am glad this is configurable

"eic:tenant",
description="The field name used for tenant filtering",
)

@field_validator("cors_origins")
@classmethod
Expand Down
4 changes: 3 additions & 1 deletion stac_api/runtime/src/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
class CollectionFilter:
"""Tooling to filter STAC Collections by tenant"""

tenant_filter_field: str

async def __call__(self, context: dict[str, Any]) -> str:
"""If tenant is present on request, filter Collections by that tenant"""
logger.debug("calling CollectionFilter with context %s", context)
tenant = context.get("tenant")
if tenant:
return f"dashboard:tenant = '{tenant}'"
return f"{self.tenant_filter_field} = '{tenant}'"
return "1=1"


Expand Down