Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra params fixes #1667 #1673

Merged
merged 8 commits into from
Aug 19, 2024
Merged
16 changes: 12 additions & 4 deletions pygeoapi/api/itemtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def get_collection_items(
'properties', 'skipGeometry', 'q',
'filter', 'filter-lang', 'filter-crs']

extra_params = {}

collections = filter_dict_by_key_value(api.config['resources'],
'type', 'collection')

Expand Down Expand Up @@ -386,9 +388,13 @@ def get_collection_items(

LOGGER.debug('processing property parameters')
for k, v in request.params.items():
if k not in reserved_fieldnames and k in list(p.fields.keys()):
LOGGER.debug(f'Adding property filter {k}={v}')
properties.append((k, v))
if k not in reserved_fieldnames:
if k in list(p.fields.keys()):
LOGGER.debug(f'Adding property filter {k}={v}')
properties.append((k, v))
else:
LOGGER.debug(f'Adding extra filter {k}={v}')
extra_params[str(k).lower()] = v

LOGGER.debug('processing sort parameter')
val = request.params.get('sortby')
Expand Down Expand Up @@ -479,6 +485,7 @@ def get_collection_items(
LOGGER.debug(f'datetime: {datetime_}')
LOGGER.debug(f'properties: {properties}')
LOGGER.debug(f'select properties: {select_properties}')
LOGGER.debug(f'extra_params: {extra_params}')
LOGGER.debug(f'skipGeometry: {skip_geometry}')
LOGGER.debug(f'language: {prv_locale}')
LOGGER.debug(f'q: {q}')
Expand All @@ -494,7 +501,8 @@ def get_collection_items(
sortby=sortby, skip_geometry=skip_geometry,
select_properties=select_properties,
crs_transform_spec=crs_transform_spec,
q=q, language=prv_locale, filterq=filter_)
q=q, language=prv_locale, filterq=filter_,
extra_params=extra_params)
except ProviderGenericError as err:
return api.get_exception(
err.http_status_code, headers, request.format,
Expand Down
7 changes: 7 additions & 0 deletions pygeoapi/provider/oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ def query(
q=None,
language=None,
filterq=None,
extra_params={},
**kwargs,
):
"""
Expand All @@ -630,9 +631,14 @@ def query(
:param skip_geometry: bool of whether to skip geometry (default False)
:param q: full-text search term(s)
:param filterq: CQL query as text string
:param extra_params: Additional parameters added to the
query which are not in reserved
fieldnames or fields in the oracle table

:returns: GeoJSON FeaturesCollection
"""
LOGGER.debug(f"properties contains: {properties}")
LOGGER.debug(f"Extra Params contains: {extra_params}")

# Check mandatory filter properties
property_dict = dict(properties)
Expand Down Expand Up @@ -790,6 +796,7 @@ def query(
q,
language,
filterq,
extra_params=extra_params
)

# Clean up placeholders that aren't used by the
Expand Down
12 changes: 12 additions & 0 deletions tests/test_oracle_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ def process_query(
q,
language,
filterq,
extra_params,
):
sql = "ID = 10 AND :foo != :bar"
if extra_params.get("custom-auth") == "forbidden":
sql += " AND 'auth' = 'you arent allowed'"

if sql_query.find(" WHERE ") == -1:
sql_query = sql_query.replace("#WHERE#", f" WHERE {sql}")
Expand Down Expand Up @@ -632,6 +635,15 @@ def test_query_mandatory_properties_must_be_specified(config):
p.query(properties=[("id", "123")])


def test_extra_params_are_passed_to_sql_manipulator(config_manipulator):
extra_params = {"custom-auth": "forbidden"}

p = OracleProvider(config_manipulator)
response = p.query(extra_params=extra_params)

assert not response['features']


@pytest.fixture()
def database_connection_pool(config_db_conn):
os.environ["ORACLE_POOL_MIN"] = "2" # noqa: F841
Expand Down
Loading