Skip to content

Commit

Permalink
allow PROV endpoints to be disabled + fixes to parsing PROV format + …
Browse files Browse the repository at this point in the history
…more doc examples
  • Loading branch information
fmigneault committed Dec 14, 2024
1 parent a09d7af commit d3c1c52
Show file tree
Hide file tree
Showing 17 changed files with 1,143 additions and 220 deletions.
10 changes: 5 additions & 5 deletions tests/test_provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_provenance_formats():
result = ProvenanceFormat.formats
expect = [
ProvenanceFormat.PROV_JSON,
ProvenanceFormat.PROV_JSON_LD,
ProvenanceFormat.PROV_JSONLD,
ProvenanceFormat.PROV_TURTLE,
ProvenanceFormat.PROV_N,
ProvenanceFormat.PROV_XML,
Expand All @@ -50,7 +50,7 @@ def test_provenance_media_types():
result = ProvenanceFormat.media_types
expect = [
ContentType.APP_JSON,
ContentType.APP_JSON_LD,
ContentType.APP_JSONLD,
ContentType.TEXT_TURTLE,
ContentType.TEXT_PROVN,
ContentType.TEXT_XML,
Expand All @@ -67,7 +67,7 @@ def test_provenance_media_types():
(None, None),
("prov-json", ProvenanceFormat.PROV_JSON),
("PROV-JSON", ProvenanceFormat.PROV_JSON),
("PROV-JSON-LD", ProvenanceFormat.PROV_JSON_LD),
("PROV-JSON-LD", ProvenanceFormat.PROV_JSONLD),
]
)
def test_provenance_format(provenance, expect):
Expand All @@ -81,7 +81,7 @@ def test_provenance_format(provenance, expect):
[
(None, None),
(ProvenanceFormat.PROV_JSON, ContentType.APP_JSON),
(ProvenanceFormat.PROV_JSON_LD, ContentType.APP_JSON_LD),
(ProvenanceFormat.PROV_JSONLD, ContentType.APP_JSONLD),
(ProvenanceFormat.PROV_XML, ContentType.APP_XML),
(ProvenanceFormat.PROV_NT, ContentType.APP_NT),
(ProvenanceFormat.PROV_N, ContentType.TEXT_PROVN),
Expand All @@ -101,7 +101,7 @@ def test_provenance_as_media_type(provenance, expect):
# only main PROV path allow format variants
(ProvenancePathType.PROV, None, None, ProvenanceFormat.PROV_JSON, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_JSON, None, ProvenanceFormat.PROV_JSON, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_JSON_LD, None, ProvenanceFormat.PROV_JSON_LD, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_JSONLD, None, ProvenanceFormat.PROV_JSONLD, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_XML, None, ProvenanceFormat.PROV_XML, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_NT, None, ProvenanceFormat.PROV_NT, False),
(ProvenancePathType.PROV, ProvenanceFormat.PROV_N, None, ProvenanceFormat.PROV_N, False),
Expand Down
6 changes: 3 additions & 3 deletions weaver/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@ def add_timeout_param(parser):
def add_provenance_params(parser):
# type: (argparse.ArgumentParser) -> None
parser.add_argument(
"-pT", "--prov", "--prov-type", dest="prov", nargs=1,
"-pT", "--prov", "--prov-type", dest="prov",
choices=ProvenancePathType.types,
help=(
"Desired PROV metadata contents. "
Expand All @@ -2695,7 +2695,7 @@ def add_provenance_params(parser):
)
)
parser.add_argument(
"-pF", "--prov-format", dest="prov_format", nargs=1,
"-pF", "--prov-format", dest="prov_format",
choices=ProvenanceFormat.formats,
help=(
"Desired PROV metadata schema representation. "
Expand All @@ -2706,7 +2706,7 @@ def add_provenance_params(parser):
)
)
parser.add_argument(
"-pR", "--run", "--prov-run", dest="prov_run_id", nargs=1,
"-pR", "--run", "--prov-run", dest="prov_run_id",
choices=ProvenancePathType.types,
help=(
"Specific run (i.e.: a nested Workflow step) for which to retrieve Provenance metadata. "
Expand Down
4 changes: 2 additions & 2 deletions weaver/datatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -1491,7 +1491,7 @@ def prov_path(self, container=None, extra_path=None, prov_format=None):
(None, None): prov_path, # the directory itself with all metadata
("/prov", None): f"{prov_path}/metadata/provenance/primary.cwlprov.json",
("/prov", ProvenanceFormat.PROV_JSON): f"{prov_path}/metadata/provenance/primary.cwlprov.json",
("/prov", ProvenanceFormat.PROV_JSON_LD): f"{prov_path}/metadata/provenance/primary.cwlprov.jsonld",
("/prov", ProvenanceFormat.PROV_JSONLD): f"{prov_path}/metadata/provenance/primary.cwlprov.jsonld",
("/prov", ProvenanceFormat.PROV_TURTLE): f"{prov_path}/metadata/provenance/primary.cwlprov.ttl",
("/prov", ProvenanceFormat.PROV_XML): f"{prov_path}/metadata/provenance/primary.cwlprov.xml",
("/prov", ProvenanceFormat.PROV_N): f"{prov_path}/metadata/provenance/primary.cwlprov.provn",
Expand Down Expand Up @@ -1522,7 +1522,7 @@ def prov_data(
prov_path = self.prov_path(container=container)
if not prov_path or not os.path.isdir(prov_path):
return None, None
path = extra_path.split("/prov/", 1)[-1]
path = str(extra_path).split("/prov/", 1)[-1]
frag = path.strip("/").split("/")
oper, params = frag[0], frag[1:]
args = ["-d", prov_path, oper]
Expand Down
2 changes: 1 addition & 1 deletion weaver/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class ContentType(Constants):
APP_GZIP = "application/gzip"
APP_HDF5 = "application/x-hdf5"
APP_JSON = "application/json"
APP_JSON_LD = "application/ld+json"
APP_JSONLD = "application/ld+json"
APP_RAW_JSON = "application/raw+json"
APP_OAS_JSON = "application/vnd.oai.openapi+json; version=3.0"
APP_OGC_PKG_JSON = "application/ogcapppkg+json"
Expand Down
7 changes: 4 additions & 3 deletions weaver/provenance.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class ProvenancePathType(Constants):
PROV_INPUTS = "/prov/inputs"
PROV_OUTPUTS = "/prov/outputs"
PROV_RUN = "/prov/run"
PROV_RUNS = "/prov/runs"

@classmethod
@classproperty
Expand Down Expand Up @@ -78,15 +79,15 @@ def get( # pylint: disable=W0221,W0237 # arguments differ/renamed fo

class ProvenanceFormat(Constants):
PROV_JSON = "PROV-JSON"
PROV_JSON_LD = "PROV-JSON-LD"
PROV_JSONLD = "PROV-JSONLD"
PROV_XML = "PROV-XML"
PROV_TURTLE = "PROV-TURTLE"
PROV_N = "PROV-N"
PROV_NT = "PROV-NT"

_media_types = {
ContentType.APP_JSON: PROV_JSON,
ContentType.APP_JSON_LD: PROV_JSON_LD,
ContentType.APP_JSONLD: PROV_JSONLD,
ContentType.TEXT_TURTLE: PROV_TURTLE,
ContentType.TEXT_PROVN: PROV_N,
ContentType.TEXT_XML: PROV_XML,
Expand Down Expand Up @@ -171,7 +172,7 @@ def resolve_compatible_formats(
return err_mismatch

if out_fmt in [OutputFormat.JSON, OutputFormat.YAML, OutputFormat.YML]:
if prov_format not in [None, ProvenanceFormat.PROV_JSON, ProvenanceFormat.PROV_JSON_LD]:
if prov_format not in [None, ProvenanceFormat.PROV_JSON, ProvenanceFormat.PROV_JSONLD]:
return err_mismatch
if prov_format is None:
prov_format = ProvenanceFormat.PROV_JSON
Expand Down
20 changes: 17 additions & 3 deletions weaver/wps_restapi/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def get_conformance(category, settings):
# ogcapi_proc_part3 = "http://www.opengis.net/spec/ogcapi-processes-3/1.0"
ogcapi_proc_enabled = asbool(settings.get("weaver.wps_restapi", True))
ogcapi_proc_html = asbool(settings.get("weaver.wps_restapi_html", True))
ogcapi_proc_prov = asbool(settings.get("weaver.cwl_prov", True))
ogcapi_proc_conformance = ([
f"{ogcapi_common}/conf/core",
f"{ogcapi_common}/per/core/additional-link-relations",
Expand Down Expand Up @@ -553,12 +554,14 @@ def get_conformance(category, settings):
f"{ogcapi_proc_part4}/req/job-management/update-patch-op",
f"{ogcapi_proc_part4}/req/job-management/update-response",
f"{ogcapi_proc_part4}/req/job-management/update-response-locked",
] + ([
f"{ogcapi_proc_part4}/req/provenance",
f"{ogcapi_proc_part4}/req/provenance/prov-get-op",
f"{ogcapi_proc_part4}/req/provenance/prov-response",
f"{ogcapi_proc_part4}/req/provenance/prov-content-negotiation",
f"{ogcapi_proc_part4}/req/provenance/inputs-get-op",
f"{ogcapi_proc_part4}/req/provenance/inputs-response",
] if ogcapi_proc_prov else []) + [
# FIXME: employ 'weaver.wps_restapi.quotation.utils.check_quotation_supported' to add below conditionally
# FIXME: https://github.com/crim-ca/weaver/issues/156 (billing/quotation)
# https://github.com/opengeospatial/ogcapi-processes/tree/master/extensions/billing
Expand Down Expand Up @@ -667,6 +670,7 @@ def api_frontpage_body(settings):
weaver_url = get_weaver_url(settings)
weaver_config = get_weaver_configuration(settings)

weaver_rtd_url = "https://pavics-weaver.readthedocs.io/en/latest"
weaver_api = asbool(settings.get("weaver.wps_restapi", True))
weaver_api_url = get_wps_restapi_base_url(settings)
weaver_api_oas_ui = weaver_url + sd.api_openapi_ui_service.path if weaver_api else None
Expand All @@ -676,12 +680,19 @@ def api_frontpage_body(settings):
weaver_api_ref = settings.get("weaver.wps_restapi_ref", None) if weaver_api else None
weaver_api_html = asbool(settings.get("weaver.wps_restapi_html", True)) and weaver_api
weaver_api_html_url = f"{weaver_api_url}?f={OutputFormat.HTML}"
weaver_api_prov = asbool(settings.get("weaver.cwl_prov", True)) and weaver_api
weaver_api_prov_doc = f"{weaver_rtd_url}/processes.html#job-provenance"
weaver_api_prov_oas = f"{weaver_api_oas_ui}#/Provenance" if weaver_api_prov else None
weaver_wps = asbool(settings.get("weaver.wps"))
weaver_wps_url = get_wps_url(settings) if weaver_wps else None
weaver_wps_oas = f"{weaver_api_oas_ui}#/WPS" if weaver_wps else None
weaver_conform_url = weaver_url + sd.api_conformance_service.path
weaver_process_url = weaver_api_url + sd.processes_service.path
weaver_jobs_url = weaver_api_url + sd.jobs_service.path
weaver_vault = asbool(settings.get("weaver.vault"))
weaver_vault_url = f"{weaver_api_url}/vault" if weaver_vault else None
weaver_vault_api = f"{weaver_api_oas_ui}#/Vault" if weaver_vault else None
weaver_vault_doc = f"{weaver_rtd_url}/processes.html#vault-upload"
weaver_links = [
{"href": weaver_url, "rel": "self", "type": ContentType.APP_JSON, "title": "This landing page."},
{"href": weaver_conform_url, "rel": "http://www.opengis.net/def/rel/ogc/1.0/conformance",
Expand Down Expand Up @@ -785,10 +796,13 @@ def api_frontpage_body(settings):
"description": __meta__.__description__,
"attribution": __meta__.__author__,
"parameters": [
{"name": "api", "enabled": weaver_api, "url": weaver_api_url, "api": weaver_api_oas_ui},
{"name": "api", "enabled": weaver_api, "url": weaver_api_url,
"doc": weaver_rtd_url, "api": weaver_api_oas_ui},
{"name": "html", "enabled": weaver_api_html, "url": weaver_api_html_url, "api": weaver_api_oas_ui},
{"name": "vault", "enabled": weaver_vault},
{"name": "wps", "enabled": weaver_wps, "url": weaver_wps_url, "api": weaver_api_oas_ui},
{"name": "prov", "enabled": weaver_api_prov, "doc": weaver_api_prov_doc, "api": weaver_api_prov_oas},
{"name": "vault", "enabled": weaver_vault, "url": weaver_vault_url,
"doc": weaver_vault_doc, "api": weaver_vault_api},
{"name": "wps", "enabled": weaver_wps, "url": weaver_wps_url, "api": weaver_wps_oas},
],
"links": weaver_links,
}
Expand Down
Loading

0 comments on commit d3c1c52

Please sign in to comment.