update hidden resources concept (#934)
This commit is contained in:
@@ -144,6 +144,7 @@ default.
|
||||
resources:
|
||||
obs:
|
||||
type: collection # REQUIRED (collection, process, or stac-collection)
|
||||
visibility: default # OPTIONAL
|
||||
title: Observations # title of dataset
|
||||
description: My cool observations # abstract of dataset
|
||||
keywords: # list of related keywords
|
||||
@@ -202,29 +203,30 @@ default.
|
||||
:ref:`plugins` for more information on plugins
|
||||
|
||||
|
||||
Publishing non-advertised resources
|
||||
-----------------------------------
|
||||
Publishing hidden resources
|
||||
---------------------------
|
||||
|
||||
pygeoapi allows for publishing resources without advertising them explicitly
|
||||
via its collections and OpenAPI endpoints. The resource is available if the
|
||||
client knows the name of the resource apriori.
|
||||
|
||||
To provide non-advertised resources, the resource name must start with ``_``. For
|
||||
example, considering the following resource:
|
||||
To provide hidden resources, the resource must provide a ``visibility: hidden``
|
||||
property. For example, considering the following resource:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
resources:
|
||||
_foo:
|
||||
title: my non-advertised resource
|
||||
foo:
|
||||
title: my hidden resource
|
||||
visibility: hidden
|
||||
|
||||
Examples:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
curl https://example.org/collections # resource _foo is not advertised
|
||||
curl https://example.org/openapi # resource _foo is not advertised
|
||||
curl https://example.org/collections/_foo # user can access resource normally
|
||||
curl https://example.org/collections # resource foo is not advertised
|
||||
curl https://example.org/openapi # resource foo is not advertised
|
||||
curl https://example.org/collections/foo # user can access resource normally
|
||||
|
||||
|
||||
Validating the configuration
|
||||
|
||||
@@ -28,4 +28,4 @@ return back data to the pygeoapi API framework in a plug and play fashion.
|
||||
|
||||
|
||||
.. seealso::
|
||||
:ref:`configuration` for more information on publishing any resource as non-advertised.
|
||||
:ref:`configuration` for more information on publishing hidden resources.
|
||||
|
||||
+1
-1
@@ -844,7 +844,7 @@ class API:
|
||||
|
||||
LOGGER.debug('Creating collections')
|
||||
for k, v in collections_dict.items():
|
||||
if k.startswith('_'):
|
||||
if v.get('visibility', 'default') == 'hidden':
|
||||
LOGGER.debug('Skipping hidden layer: {}'.format(k))
|
||||
continue
|
||||
collection_data = get_provider_default(v['providers'])
|
||||
|
||||
+1
-1
@@ -421,7 +421,7 @@ def get_oas_30(cfg):
|
||||
'type', 'collection')
|
||||
|
||||
for k, v in collections.items():
|
||||
if k.startswith('_'):
|
||||
if v.get('visibility', 'default') == 'hidden':
|
||||
LOGGER.debug('Skipping hidden layer: {}'.format(k))
|
||||
continue
|
||||
name = l10n.translate(k, locale_)
|
||||
|
||||
@@ -248,6 +248,13 @@ properties:
|
||||
enum:
|
||||
- collection
|
||||
- stac-collection
|
||||
visibility:
|
||||
type: string
|
||||
description: visibility state of the resource
|
||||
enum:
|
||||
- default
|
||||
- hidden
|
||||
default: default
|
||||
title:
|
||||
$ref: '#/definitions/i18n_string'
|
||||
description: the title of the service
|
||||
|
||||
+2
-1
@@ -98,8 +98,9 @@ metadata:
|
||||
role: pointOfContact
|
||||
|
||||
resources:
|
||||
_obs:
|
||||
obs:
|
||||
type: collection
|
||||
visibility: hidden
|
||||
title:
|
||||
en: Observations
|
||||
fr: Observations
|
||||
+11
-8
@@ -52,8 +52,8 @@ def config():
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def config_non_advertised_resources():
|
||||
filename = 'pygeoapi-test-config-non-advertised-resources.yml'
|
||||
def config_hidden_resources():
|
||||
filename = 'pygeoapi-test-config-hidden-resources.yml'
|
||||
with open(get_test_file_path(filename)) as fh:
|
||||
return yaml_load(fh)
|
||||
|
||||
@@ -70,8 +70,8 @@ def api_(config):
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def api_non_advertised_resources(config_non_advertised_resources):
|
||||
return API(config_non_advertised_resources)
|
||||
def api_hidden_resources(config_hidden_resources):
|
||||
return API(config_hidden_resources)
|
||||
|
||||
|
||||
def test_apirequest(api_):
|
||||
@@ -512,13 +512,16 @@ def test_describe_collections(config, api_):
|
||||
assert collection['id'] == 'naturalearth/lakes'
|
||||
|
||||
|
||||
def test_describe_collections_non_advertised_resources(
|
||||
config_non_advertised_resources, api_non_advertised_resources):
|
||||
def test_describe_collections_hidden_resources(
|
||||
config_hidden_resources, api_hidden_resources):
|
||||
req = mock_request({})
|
||||
rsp_headers, code, response = api_non_advertised_resources.describe_collections(req) # noqa
|
||||
rsp_headers, code, response = api_hidden_resources.describe_collections(req) # noqa
|
||||
assert code == 200
|
||||
|
||||
print(response)
|
||||
assert len(config_hidden_resources['resources']) == 3
|
||||
|
||||
collections = json.loads(response)
|
||||
assert len(collections['collections']) == 1
|
||||
|
||||
|
||||
def test_get_collection_queryables(config, api_):
|
||||
|
||||
@@ -45,8 +45,8 @@ def config():
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def config_non_advertised_resources():
|
||||
filename = 'pygeoapi-test-config-non-advertised-resources.yml'
|
||||
def config_hidden_resources():
|
||||
filename = 'pygeoapi-test-config-hidden-resources.yml'
|
||||
with open(get_test_file_path(filename)) as fh:
|
||||
return yaml_load(fh)
|
||||
|
||||
@@ -92,8 +92,8 @@ def test_validate_openapi_document(openapi):
|
||||
is_valid = validate_openapi_document({'foo': 'bar'})
|
||||
|
||||
|
||||
def test_non_advertised_resources(config_non_advertised_resources):
|
||||
openapi_doc = get_oas(config_non_advertised_resources)
|
||||
def test_hidden_resources(config_hidden_resources):
|
||||
openapi_doc = get_oas(config_hidden_resources)
|
||||
|
||||
assert '/collections/_obs' not in openapi_doc['paths']
|
||||
assert '/collections/_obs/items' not in openapi_doc['paths']
|
||||
assert '/collections/obs' not in openapi_doc['paths']
|
||||
assert '/collections/obs/items' not in openapi_doc['paths']
|
||||
|
||||
Reference in New Issue
Block a user