diff --git a/docs/source/configuration.rst b/docs/source/configuration.rst index 2ba33dc..70c7496 100644 --- a/docs/source/configuration.rst +++ b/docs/source/configuration.rst @@ -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 diff --git a/docs/source/data-publishing/index.rst b/docs/source/data-publishing/index.rst index c66aeed..87e8056 100644 --- a/docs/source/data-publishing/index.rst +++ b/docs/source/data-publishing/index.rst @@ -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. diff --git a/pygeoapi/api.py b/pygeoapi/api.py index fcb6f95..196c24e 100644 --- a/pygeoapi/api.py +++ b/pygeoapi/api.py @@ -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']) diff --git a/pygeoapi/openapi.py b/pygeoapi/openapi.py index ada462a..4eb756f 100644 --- a/pygeoapi/openapi.py +++ b/pygeoapi/openapi.py @@ -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_) diff --git a/pygeoapi/schemas/config/pygeoapi-config-0.x.yml b/pygeoapi/schemas/config/pygeoapi-config-0.x.yml index c0455bc..abcfcaa 100644 --- a/pygeoapi/schemas/config/pygeoapi-config-0.x.yml +++ b/pygeoapi/schemas/config/pygeoapi-config-0.x.yml @@ -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 diff --git a/tests/pygeoapi-test-config-non-advertised-resources.yml b/tests/pygeoapi-test-config-hidden-resources.yml similarity index 99% rename from tests/pygeoapi-test-config-non-advertised-resources.yml rename to tests/pygeoapi-test-config-hidden-resources.yml index 36cea64..eb44da5 100644 --- a/tests/pygeoapi-test-config-non-advertised-resources.yml +++ b/tests/pygeoapi-test-config-hidden-resources.yml @@ -98,8 +98,9 @@ metadata: role: pointOfContact resources: - _obs: + obs: type: collection + visibility: hidden title: en: Observations fr: Observations diff --git a/tests/test_api.py b/tests/test_api.py index 54ac2b2..fbb74e7 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -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_): diff --git a/tests/test_openapi.py b/tests/test_openapi.py index bbdb094..ed7df91 100644 --- a/tests/test_openapi.py +++ b/tests/test_openapi.py @@ -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']