Skip to content

Commit

Permalink
Moved PROTECTED_QUERY_DATASETS to globals.py
Browse files Browse the repository at this point in the history
Responding to PR comments.
  • Loading branch information
danscales committed Dec 20, 2023
1 parent 4a617dc commit 90bc813
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
6 changes: 1 addition & 5 deletions app/authentication/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
from ..routes import dataset_dependency

from ..utils.rw_api import who_am_i
from ..settings.globals import PROTECTED_QUERY_DATASETS

# token dependency where we immediately cause an exception if there is no auth token
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="/token")
# token dependency where we don't cause exception if there is no auth token
oauth2_scheme_no_auto = OAuth2PasswordBearer(tokenUrl="/token", auto_error=False)

# Datasets that require admin privileges to do a query. (Extra protection on
# commercial datasets which shouldn't be downloaded in any way.)
PROTECTED_QUERY_DATASETS = ["wdpa_licensed_protected_areas"]


async def is_service_account(token: str = Depends(oauth2_scheme)) -> bool:
"""Calls GFW API to authorize user.
Expand Down
4 changes: 4 additions & 0 deletions app/routes/datasets/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ async def query_dataset_json(
GeostoreOrigin.gfw, description="Service to search first for geostore."
),
is_authorized: bool = Depends(is_gfwpro_admin_for_query),
# api_key: APIKey = Depends(get_api_key),
):
"""Execute a READ-ONLY SQL query on the given dataset version (if
implemented) and return response in JSON format.
Expand Down Expand Up @@ -192,6 +193,7 @@ async def query_dataset_csv(
Delimiters.comma, description="Delimiter to use for CSV file."
),
is_authorized: bool = Depends(is_gfwpro_admin_for_query),
# api_key: APIKey = Depends(get_api_key),
):
"""Execute a READ-ONLY SQL query on the given dataset version (if
implemented) and return response in CSV format.
Expand Down Expand Up @@ -254,6 +256,7 @@ async def query_dataset_json_post(
dataset_version: Tuple[str, str] = Depends(dataset_version_dependency),
request: QueryRequestIn,
is_authorized: bool = Depends(is_gfwpro_admin_for_query),
# api_key: APIKey = Depends(get_api_key),
):
"""Execute a READ-ONLY SQL query on the given dataset version (if
implemented)."""
Expand Down Expand Up @@ -284,6 +287,7 @@ async def query_dataset_csv_post(
dataset_version: Tuple[str, str] = Depends(dataset_version_dependency),
request: CsvQueryRequestIn,
is_authorized: bool = Depends(is_gfwpro_admin_for_query),
# api_key: APIKey = Depends(get_api_key),
):
"""Execute a READ-ONLY SQL query on the given dataset version (if
implemented)."""
Expand Down
4 changes: 4 additions & 0 deletions app/settings/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,7 @@
GOOGLE_APPLICATION_CREDENTIALS = config(
"GOOGLE_APPLICATION_CREDENTIALS", cast=str, default="/root/.gcs/private_key.json"
)

# Datasets that require admin privileges to do a query. (Extra protection on
# commercial datasets which shouldn't be downloaded in any way.)
PROTECTED_QUERY_DATASETS = ["wdpa_licensed_protected_areas"]

0 comments on commit 90bc813

Please sign in to comment.