diff --git a/CHANGES.md b/CHANGES.md index a07f429e8..ddf5729b4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## 0.19.1 (2024-11-14) + +* Add `titiler` links in Map attributions + ## 0.19.0 (2024-11-07) ### Misc diff --git a/src/titiler/application/titiler/application/main.py b/src/titiler/application/titiler/application/main.py index 03bafbe79..0d3690d16 100644 --- a/src/titiler/application/titiler/application/main.py +++ b/src/titiler/application/titiler/application/main.py @@ -50,27 +50,27 @@ api_settings = ApiSettings() -############################################################################### -# Setup a global API access key, if configured -api_key_query = APIKeyQuery(name="access_token", auto_error=False) - +app_dependencies = [] +if api_settings.global_access_token: + ############################################################################### + # Setup a global API access key, if configured + api_key_query = APIKeyQuery(name="access_token", auto_error=False) + + def validate_access_token(access_token: str = Security(api_key_query)): + """Validates API key access token, set as the `api_settings.global_access_token` value. + Returns True if no access token is required, or if the access token is valid. + Raises an HTTPException (401) if the access token is required but invalid/missing. + """ + if not access_token: + raise HTTPException(status_code=401, detail="Missing `access_token`") + + # if access_token == `token` then OK + if access_token != api_settings.global_access_token: + raise HTTPException(status_code=401, detail="Invalid `access_token`") -def validate_access_token(access_token: str = Security(api_key_query)): - """Validates API key access token, set as the `api_settings.global_access_token` value. - Returns True if no access token is required, or if the access token is valid. - Raises an HTTPException (401) if the access token is required but invalid/missing. - """ - if api_settings.global_access_token is None: return True - if not access_token: - raise HTTPException(status_code=401, detail="Missing `access_token`") - - # if access_token == `token` then OK - if access_token != api_settings.global_access_token: - raise HTTPException(status_code=401, detail="Invalid `access_token`") - - return True + app_dependencies.append(Depends(validate_access_token)) ############################################################################### @@ -91,7 +91,7 @@ def validate_access_token(access_token: str = Security(api_key_query)): """, version=titiler_version, root_path=api_settings.root_path, - dependencies=[Depends(validate_access_token)], + dependencies=app_dependencies, ) ############################################################################### diff --git a/src/titiler/application/titiler/application/templates/index.html b/src/titiler/application/titiler/application/templates/index.html index d6c013a30..185a57389 100644 --- a/src/titiler/application/titiler/application/templates/index.html +++ b/src/titiler/application/titiler/application/templates/index.html @@ -82,10 +82,11 @@