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

Configure which OGC APIs are available #1917

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pygeoapi-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ server:
# output_dir: /tmp/
# ogc_schemas_location: /opt/schemas.opengis.net
admin: false # enable admin api
coverages: true # enable ogcapi-coverages
edr: true # enable ogcapi-edr
features: true # enable ogcapi-features
maps: true # enable ogcapi-maps
processes: true # enable ogcapi-processes
stac: true # enable ogcapi-stac
tiles: true # enable ogcapi-tiles

logging:
level: ERROR
Expand Down
107 changes: 69 additions & 38 deletions pygeoapi/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
DEFAULT_STORAGE_CRS = DEFAULT_CRS


def all_apis() -> dict:
def all_apis(server_cfg: dict = {}) -> dict:
"""
Return all supported API modules

Expand All @@ -131,18 +131,36 @@ def all_apis() -> dict:
:returns: `dict` of API provider type, API module
"""

from . import (coverages, environmental_data_retrieval, itemtypes, maps,
processes, tiles, stac)

return {
'coverage': coverages,
'edr': environmental_data_retrieval,
'itemtypes': itemtypes,
'map': maps,
'process': processes,
'tile': tiles,
'stac': stac
}
apis: dict = {}

from . import itemtypes
apis['itemtypes'] = itemtypes

if server_cfg.get('coverages', True):
from . import coverages
apis['coverage'] = coverages

if server_cfg.get('edr', True):
from . import environmental_data_retrieval
apis['edr'] = environmental_data_retrieval

if server_cfg.get('maps', True):
from . import maps
apis['map'] = maps

if server_cfg.get('processes', True):
from . import processes
apis['process'] = processes

if server_cfg.get('tiles', True):
from . import tiles
apis['tile'] = tiles

if server_cfg.get('stac', True):
from . import stac
apis['stac'] = stac

return apis


def apply_gzip(headers: dict, content: Union[str, bytes]) -> Union[str, bytes]:
Expand Down Expand Up @@ -742,6 +760,10 @@ def landing_page(api: API,
request.locale)
}

processes_enabled = api.config['server'].get('processes', True)
stac_enabled = api.config['server'].get('stac', True)
tiles_enabled = api.config['server'].get('tiles', True)

LOGGER.debug('Creating links')
# TODO: put title text in config or translatable files?
fcm['links'] = [{
Expand Down Expand Up @@ -788,42 +810,48 @@ def landing_page(api: API,
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('Collections', request.locale),
'href': api.get_collections_url()
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/processes',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('Processes', request.locale),
'href': f"{api.base_url}/processes"
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('Jobs', request.locale),
'href': f"{api.base_url}/jobs"
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('The list of supported tiling schemes as JSON', request.locale), # noqa
'href': f"{api.base_url}/TileMatrixSets?f=json"
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes',
'type': FORMAT_TYPES[F_HTML],
'title': l10n.translate('The list of supported tiling schemes as HTML', request.locale), # noqa
'href': f"{api.base_url}/TileMatrixSets?f=html"
}]

if processes_enabled:
fcm['links'].extend([{
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/processes',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('Processes', request.locale),
'href': f"{api.base_url}/processes"
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/job-list',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('Jobs', request.locale),
'href': f"{api.base_url}/jobs"
}])
if tiles_enabled:
fcm['links'].extend([{
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes',
'type': FORMAT_TYPES[F_JSON],
'title': l10n.translate('The list of supported tiling schemes as JSON', request.locale), # noqa
'href': f"{api.base_url}/TileMatrixSets?f=json"
}, {
'rel': 'http://www.opengis.net/def/rel/ogc/1.0/tiling-schemes',
'type': FORMAT_TYPES[F_HTML],
'title': l10n.translate('The list of supported tiling schemes as HTML', request.locale), # noqa
'href': f"{api.base_url}/TileMatrixSets?f=html"
}])

headers = request.get_response_headers(**api.api_headers)
if request.format == F_HTML: # render

fcm['processes'] = False
fcm['stac'] = False
fcm['collection'] = False
fcm['tiles'] = tiles_enabled

if filter_dict_by_key_value(api.config['resources'],
'type', 'process'):
fcm['processes'] = True
fcm['processes'] = processes_enabled

if filter_dict_by_key_value(api.config['resources'],
'type', 'stac-collection'):
fcm['stac'] = True
fcm['stac'] = stac_enabled

if filter_dict_by_key_value(api.config['resources'],
'type', 'collection'):
Expand Down Expand Up @@ -882,14 +910,17 @@ def conformance(api, request: APIRequest) -> Tuple[dict, int, str]:
:returns: tuple of headers, status code, content
"""

apis_dict = all_apis()
apis_dict = all_apis(api.config['server'])

processes_enabled = api.config['server'].get('processes', True)

conformance_list = CONFORMANCE_CLASSES

for key, value in api.config['resources'].items():
if value['type'] == 'process':
conformance_list.extend(
apis_dict['process'].CONFORMANCE_CLASSES)
if processes_enabled:
conformance_list.extend(
apis_dict['process'].CONFORMANCE_CLASSES)
else:
for provider in value['providers']:
if provider['type'] in apis_dict:
Expand Down
105 changes: 73 additions & 32 deletions pygeoapi/django_/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@

from . import views

coverages_enabled = settings.PYGEOAPI_CONFIG['server'].get('coverages', True)
edr_enabled = settings.PYGEOAPI_CONFIG['server'].get('edr', True)
features_enabled = settings.PYGEOAPI_CONFIG['server'].get('features', True)
maps_enabled = settings.PYGEOAPI_CONFIG['server'].get('maps', True)
processes_enabled = settings.PYGEOAPI_CONFIG['server'].get('processes', True)
stac_enabled = settings.PYGEOAPI_CONFIG['server'].get('stac', True)
tiles_enabled = settings.PYGEOAPI_CONFIG['server'].get('tiles', True)
admin_enabled = settings.PYGEOAPI_CONFIG['server'].get('admin', False)


def apply_slash_rule(url: str):
""" Strip trailing slashes if the API rules are strict about it.
Expand All @@ -76,16 +85,6 @@ def apply_slash_rule(url: str):
views.conformance,
name='conformance'
),
path(
apply_slash_rule('TileMatrixSets/'),
views.tilematrixsets,
name='tilematrixsets'
),
path(
apply_slash_rule('TileMatrixSets/<str:tilematrixset_id>'),
views.tilematrixsets,
name='tilematrixset'
),
path(
apply_slash_rule('collections/'),
views.collections,
Expand All @@ -106,6 +105,9 @@ def apply_slash_rule(url: str):
views.collection_queryables,
name='collection-queryables',
),
]

features_urlpatterns = [
path(
apply_slash_rule('collections/<str:collection_id>/items/'),
views.collection_items,
Expand All @@ -116,30 +118,21 @@ def apply_slash_rule(url: str):
views.collection_item,
name='collection-item',
),
]

if features_enabled:
urlpatterns.extend(features_urlpatterns)

tiles_urlpatterns = [
path(
apply_slash_rule('collections/<str:collection_id>/coverage/'),
views.collection_coverage,
name='collection-coverage',
),
path(
'collections/<str:collection_id>/map',
views.collection_map,
name='collection-map',
),
path(
'collections/<str:collection_id>/styles/<str:style_id>/map',
views.collection_style_map,
name='collection-style-map',
),
path(
apply_slash_rule('collections/<str:collection_id>/tiles/'),
views.collection_tiles,
name='collection-tiles',
apply_slash_rule('TileMatrixSets/'),
views.tilematrixsets,
name='tilematrixsets'
),
path(
'collections/<str:collection_id>/tiles/<str:tileMatrixSetId>',
views.collection_tiles_metadata,
name='collection-tiles-metadata',
apply_slash_rule('TileMatrixSets/<str:tilematrixset_id>'),
views.tilematrixsets,
name='tilematrixset'
),
path(
'collections/<str:collection_id>/tiles/<str:tileMatrixSetId>/metadata',
Expand All @@ -152,6 +145,39 @@ def apply_slash_rule(url: str):
views.collection_item_tiles,
name='collection-item-tiles',
),
]

if tiles_enabled:
urlpatterns.extend(tiles_urlpatterns)

coverages_urlpatterns = [
path(
apply_slash_rule('collections/<str:collection_id>/coverage/'),
views.collection_coverage,
name='collection-coverage',
),
]

if coverages_enabled:
urlpatterns.extend(coverages_urlpatterns)

maps_urlpatterns = [
path(
'collections/<str:collection_id>/map',
views.collection_map,
name='collection-map',
),
path(
'collections/<str:collection_id>/styles/<str:style_id>/map',
views.collection_style_map,
name='collection-style-map',
),
]

if maps_enabled:
urlpatterns.extend(maps_urlpatterns)

edr_urlpatterns = [
path(
'collections/<str:collection_id>/position',
views.get_collection_edr_query,
Expand Down Expand Up @@ -242,6 +268,12 @@ def apply_slash_rule(url: str):
views.get_collection_edr_query,
name='collection-edr-corridor',
),
]

if edr_enabled:
urlpatterns.extend(edr_urlpatterns)

processes_urlpatterns = [
path(apply_slash_rule('processes/'), views.processes, name='processes'),
path('processes/<str:process_id>', views.processes, name='process-detail'),
path('processes/<str:process_id>/execution', views.process_execution,
Expand All @@ -258,21 +290,30 @@ def apply_slash_rule(url: str):
views.job_results_resource,
name='job-results-resource',
),
]

if processes_enabled:
urlpatterns.extend(processes_urlpatterns)

stac_urlpatterns = [
path(
apply_slash_rule('stac/'),
views.stac_catalog_root,
name='stac-catalog-root'
)
]

if stac_enabled:
urlpatterns.extend(stac_urlpatterns)

url_route_prefix = settings.API_RULES.get_url_prefix('django')
if url_route_prefix:
# Add a URL prefix to all routes if configured
urlpatterns = [
path(url_route_prefix, include(urlpatterns))
]

if settings.PYGEOAPI_CONFIG['server'].get('admin', False):
if admin_enabled:
admin_urlpatterns = [
path(
apply_slash_rule('admin/config'),
Expand Down
35 changes: 28 additions & 7 deletions pygeoapi/django_/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,36 @@

from pygeoapi.api import API, APIRequest, apply_gzip
import pygeoapi.api as core_api
import pygeoapi.api.coverages as coverages_api
import pygeoapi.api.environmental_data_retrieval as edr_api
import pygeoapi.api.itemtypes as itemtypes_api
import pygeoapi.api.maps as maps_api
import pygeoapi.api.processes as processes_api
import pygeoapi.api.stac as stac_api
import pygeoapi.api.tiles as tiles_api

if settings.PYGEOAPI_CONFIG['server'].get('admin'):
coverages_enabled = settings.PYGEOAPI_CONFIG['server'].get('coverages', True)
edr_enabled = settings.PYGEOAPI_CONFIG['server'].get('edr', True)
features_enabled = settings.PYGEOAPI_CONFIG['server'].get('features', True)
maps_enabled = settings.PYGEOAPI_CONFIG['server'].get('maps', True)
processes_enabled = settings.PYGEOAPI_CONFIG['server'].get('processes', True)
stac_enabled = settings.PYGEOAPI_CONFIG['server'].get('stac', True)
tiles_enabled = settings.PYGEOAPI_CONFIG['server'].get('tiles', True)
admin_enabled = settings.PYGEOAPI_CONFIG['server'].get('admin', False)

if coverages_enabled:
import pygeoapi.api.coverages as coverages_api

if edr_enabled:
import pygeoapi.api.environmental_data_retrieval as edr_api

if maps_enabled:
import pygeoapi.api.maps as maps_api

if processes_enabled:
import pygeoapi.api.processes as processes_api

if stac_enabled:
import pygeoapi.api.stac as stac_api

if tiles_enabled:
import pygeoapi.api.tiles as tiles_api

if admin_enabled:
import pygeoapi.admin as admin_api


Expand Down
Loading