-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresourceconfig.py
96 lines (83 loc) · 3.44 KB
/
resourceconfig.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""Pydantic Resource Configuration Data Model."""
from __future__ import annotations
from typing import Annotated, Optional
from pydantic import Field, model_validator
from pydantic.networks import AnyUrl, UrlConstraints
from oteapi.models.genericconfig import GenericConfig
from oteapi.models.secretconfig import SecretConfig
HostlessAnyUrl = Annotated[AnyUrl, UrlConstraints(host_required=False)]
class ResourceConfig(GenericConfig, SecretConfig):
"""Resource Strategy Data Configuration.
Important:
Either of the pairs of attributes `downloadUrl`/`mediaType` or
`accessUrl`/`accessService` MUST be specified.
"""
resourceType: Optional[str] = Field(
None, description="Type of registered resource strategy."
)
downloadUrl: Optional[HostlessAnyUrl] = Field(
None,
description=(
"Definition: The URL of the downloadable file in a given format. E.g. CSV "
"file or RDF file.\n\nUsage: `downloadURL` *SHOULD* be used for the URL at"
" which this distribution is available directly, typically through a HTTPS"
" GET request or SFTP."
),
)
mediaType: Optional[str] = Field(
None,
description=(
"The media type of the distribution as defined by IANA "
"[[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)]"
".\n\nUsage: This property *SHOULD* be used when the media"
" type of the distribution is defined in IANA "
"[[IANA-MEDIA-TYPES](https://www.w3.org/TR/vocab-dcat-2/#bib-iana-media-types)]."
),
)
accessUrl: Optional[HostlessAnyUrl] = Field(
None,
description=(
"A URL of the resource that gives access to a distribution of "
"the dataset. E.g. landing page, feed, SPARQL endpoint.\n\nUsage: "
"`accessURL` *SHOULD* be used for the URL of a service or location that "
"can provide access to this distribution, typically through a Web form, "
"query or API call.\n`downloadURL` is preferred for direct links to "
"downloadable resources."
),
)
accessService: Optional[str] = Field(
None,
description=(
"A data service that gives access to the distribution of the dataset."
),
)
license: Optional[str] = Field(
None,
description=(
"A legal document under which the distribution is made available."
),
)
accessRights: Optional[str] = Field(
None,
description=(
"A rights statement that concerns how the distribution is accessed."
),
)
publisher: Optional[str] = Field(
None,
description="The entity responsible for making the resource/item available.",
)
@model_validator(mode="after")
def ensure_unique_url_pairs(self) -> ResourceConfig:
"""Ensure either downloadUrl/mediaType or accessUrl/accessService are defined.
It's fine to define them all, but at least one complete pair MUST be specified.
"""
if not (
all(getattr(self, _) for _ in ["downloadUrl", "mediaType"])
or all(getattr(self, _) for _ in ["accessUrl", "accessService"])
):
raise ValueError(
"Either of the pairs of attributes downloadUrl/mediaType or "
"accessUrl/accessService MUST be specified."
)
return self