dapla-toolbelt-metadata 0.3.0__py3-none-any.whl → 0.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dapla-toolbelt-metadata might be problematic. Click here for more details.
- dapla_metadata/__init__.py +1 -0
- dapla_metadata/_shared/__init__.py +1 -0
- dapla_metadata/{datasets → _shared}/config.py +39 -13
- dapla_metadata/_shared/enums.py +28 -0
- dapla_metadata/{datasets → _shared}/user_info.py +4 -4
- dapla_metadata/datasets/core.py +6 -3
- dapla_metadata/datasets/utility/enums.py +0 -19
- dapla_metadata/datasets/utility/utils.py +1 -1
- dapla_metadata/variable_definitions/__init__.py +7 -0
- dapla_metadata/variable_definitions/_client.py +30 -0
- dapla_metadata/variable_definitions/config.py +49 -0
- dapla_metadata/variable_definitions/exceptions.py +66 -0
- dapla_metadata/variable_definitions/generated/.openapi-generator/FILES +22 -0
- dapla_metadata/variable_definitions/generated/.openapi-generator/VERSION +1 -0
- dapla_metadata/variable_definitions/generated/.openapi-generator-ignore +6 -0
- dapla_metadata/variable_definitions/generated/README.md +148 -0
- dapla_metadata/variable_definitions/generated/__init__.py +0 -0
- dapla_metadata/variable_definitions/generated/vardef_client/__init__.py +52 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/__init__.py +9 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/data_migration_api.py +313 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/draft_variable_definitions_api.py +919 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/patches_api.py +919 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/public_api.py +915 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/validity_periods_api.py +876 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api/variable_definitions_api.py +1205 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api_client.py +779 -0
- dapla_metadata/variable_definitions/generated/vardef_client/api_response.py +27 -0
- dapla_metadata/variable_definitions/generated/vardef_client/configuration.py +474 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/CompleteResponse.md +51 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/Contact.md +30 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/DataMigrationApi.md +90 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/Draft.md +42 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/LanguageStringType.md +31 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/Owner.md +31 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/Patch.md +43 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/PatchesApi.md +249 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/PublicApi.md +218 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/SupportedLanguages.md +15 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/UpdateDraft.md +44 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriod.md +42 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
- dapla_metadata/variable_definitions/generated/vardef_client/docs/VariableStatus.md +17 -0
- dapla_metadata/variable_definitions/generated/vardef_client/exceptions.py +193 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/__init__.py +30 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/complete_response.py +284 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/contact.py +94 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/draft.py +243 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/klass_reference.py +99 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/language_string_type.py +104 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/owner.py +90 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/patch.py +289 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/problem.py +118 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_contact.py +92 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/rendered_variable_definition.py +235 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/supported_languages.py +33 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/update_draft.py +307 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/validity_period.py +259 -0
- dapla_metadata/variable_definitions/generated/vardef_client/models/variable_status.py +33 -0
- dapla_metadata/variable_definitions/generated/vardef_client/py.typed +0 -0
- dapla_metadata/variable_definitions/generated/vardef_client/rest.py +249 -0
- dapla_metadata/variable_definitions/vardef.py +173 -0
- dapla_metadata/variable_definitions/variable_definition.py +212 -0
- {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/METADATA +1 -1
- dapla_toolbelt_metadata-0.4.1.dist-info/RECORD +80 -0
- dapla_toolbelt_metadata-0.3.0.dist-info/RECORD +0 -22
- {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/LICENSE +0 -0
- {dapla_toolbelt_metadata-0.3.0.dist-info → dapla_toolbelt_metadata-0.4.1.dist-info}/WHEEL +0 -0
dapla_metadata/__init__.py
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Utility code intended to be used by multiple packages within this project, but not by end users."""
|
|
@@ -10,11 +10,12 @@ from pprint import pformat
|
|
|
10
10
|
from dotenv import dotenv_values
|
|
11
11
|
from dotenv import load_dotenv
|
|
12
12
|
|
|
13
|
+
from dapla_metadata._shared.enums import DaplaEnvironment
|
|
14
|
+
from dapla_metadata._shared.enums import DaplaRegion
|
|
15
|
+
from dapla_metadata._shared.enums import DaplaService
|
|
13
16
|
from dapla_metadata.datasets.utility.constants import (
|
|
14
17
|
DATADOC_STATISTICAL_SUBJECT_SOURCE_URL,
|
|
15
18
|
)
|
|
16
|
-
from dapla_metadata.datasets.utility.enums import DaplaRegion
|
|
17
|
-
from dapla_metadata.datasets.utility.enums import DaplaService
|
|
18
19
|
|
|
19
20
|
logger = logging.getLogger(__name__)
|
|
20
21
|
|
|
@@ -22,7 +23,10 @@ DOT_ENV_FILE_PATH = Path(__file__).parent.joinpath(".env")
|
|
|
22
23
|
|
|
23
24
|
JUPYTERHUB_USER = "JUPYTERHUB_USER"
|
|
24
25
|
DAPLA_REGION = "DAPLA_REGION"
|
|
26
|
+
DAPLA_ENVIRONMENT = "DAPLA_ENVIRONMENT"
|
|
25
27
|
DAPLA_SERVICE = "DAPLA_SERVICE"
|
|
28
|
+
DAPLA_GROUP_CONTEXT = "DAPLA_GROUP_CONTEXT"
|
|
29
|
+
OIDC_TOKEN = "OIDC_TOKEN" # noqa: S105
|
|
26
30
|
|
|
27
31
|
env_loaded = False
|
|
28
32
|
|
|
@@ -38,48 +42,70 @@ def _load_dotenv_file() -> None:
|
|
|
38
42
|
)
|
|
39
43
|
|
|
40
44
|
|
|
41
|
-
def
|
|
42
|
-
"""Get a config item. Makes sure all access is logged.
|
|
45
|
+
def get_config_item(item: str, *, raising: bool = False) -> str | None:
|
|
46
|
+
"""Get a config item. Makes sure all access is logged.
|
|
47
|
+
|
|
48
|
+
Args:
|
|
49
|
+
item: The name of the environment variable to obtain.
|
|
50
|
+
raising: `True` if an exception should be raised when the item isn't present.
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
The set value or `None`
|
|
54
|
+
|
|
55
|
+
Raises:
|
|
56
|
+
OSError: Only if `raising` is True and the item is not found.
|
|
57
|
+
"""
|
|
43
58
|
_load_dotenv_file()
|
|
44
59
|
value = os.environ.get(item)
|
|
60
|
+
if raising and not value:
|
|
61
|
+
msg = f"Environment variable {item} not defined."
|
|
62
|
+
raise OSError(msg)
|
|
45
63
|
logger.debug("Config accessed. %s", item)
|
|
46
64
|
return value
|
|
47
65
|
|
|
48
66
|
|
|
49
67
|
def get_jupyterhub_user() -> str | None:
|
|
50
68
|
"""Get the JupyterHub user name."""
|
|
51
|
-
return
|
|
69
|
+
return get_config_item(JUPYTERHUB_USER)
|
|
52
70
|
|
|
53
71
|
|
|
54
72
|
def get_statistical_subject_source_url() -> str | None:
|
|
55
73
|
"""Get the URL to the statistical subject source."""
|
|
56
74
|
return (
|
|
57
|
-
|
|
75
|
+
get_config_item("DATADOC_STATISTICAL_SUBJECT_SOURCE_URL")
|
|
58
76
|
or DATADOC_STATISTICAL_SUBJECT_SOURCE_URL
|
|
59
77
|
)
|
|
60
78
|
|
|
61
79
|
|
|
62
80
|
def get_dapla_region() -> DaplaRegion | None:
|
|
63
81
|
"""Get the Dapla region we're running on."""
|
|
64
|
-
if region :=
|
|
82
|
+
if region := get_config_item(DAPLA_REGION):
|
|
65
83
|
return DaplaRegion(region)
|
|
66
84
|
|
|
67
85
|
return None
|
|
68
86
|
|
|
69
87
|
|
|
88
|
+
def get_dapla_environment() -> DaplaEnvironment | None:
|
|
89
|
+
"""Get the Dapla environment we're running on."""
|
|
90
|
+
if env := get_config_item(DAPLA_ENVIRONMENT):
|
|
91
|
+
return DaplaEnvironment(env)
|
|
92
|
+
|
|
93
|
+
return None
|
|
94
|
+
|
|
95
|
+
|
|
70
96
|
def get_dapla_service() -> DaplaService | None:
|
|
71
97
|
"""Get the Dapla service we're running on."""
|
|
72
|
-
if service :=
|
|
98
|
+
if service := get_config_item(DAPLA_SERVICE):
|
|
73
99
|
return DaplaService(service)
|
|
74
100
|
|
|
75
101
|
return None
|
|
76
102
|
|
|
77
103
|
|
|
78
|
-
def get_oidc_token() -> str | None:
|
|
104
|
+
def get_oidc_token(*, raising: bool = False) -> str | None:
|
|
79
105
|
"""Get the JWT token from the environment."""
|
|
80
|
-
return
|
|
106
|
+
return get_config_item(OIDC_TOKEN, raising=raising)
|
|
81
107
|
|
|
82
108
|
|
|
83
|
-
def
|
|
84
|
-
"""Get the
|
|
85
|
-
return
|
|
109
|
+
def get_dapla_group_context(*, raising: bool = False) -> str | None:
|
|
110
|
+
"""Get the group which the user has chosen to represent."""
|
|
111
|
+
return get_config_item(DAPLA_GROUP_CONTEXT, raising=raising)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class DaplaRegion(str, Enum):
|
|
5
|
+
"""Dapla platforms/regions."""
|
|
6
|
+
|
|
7
|
+
DAPLA_LAB = "DAPLA_LAB"
|
|
8
|
+
BIP = "BIP"
|
|
9
|
+
ON_PREM = "ON_PREM"
|
|
10
|
+
CLOUD_RUN = "CLOUD_RUN"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DaplaEnvironment(str, Enum):
|
|
14
|
+
"""Dapla lifecycle environment."""
|
|
15
|
+
|
|
16
|
+
PROD = "PROD"
|
|
17
|
+
TEST = "TEST"
|
|
18
|
+
DEV = "DEV"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DaplaService(str, Enum):
|
|
22
|
+
"""Dapla services."""
|
|
23
|
+
|
|
24
|
+
DATADOC = "DATADOC"
|
|
25
|
+
JUPYTERLAB = "JUPYTERLAB"
|
|
26
|
+
VS_CODE = "VS_CODE"
|
|
27
|
+
R_STUDIO = "R_STUDIO"
|
|
28
|
+
KILDOMATEN = "KILDOMATEN"
|
|
@@ -6,9 +6,9 @@ from typing import Protocol
|
|
|
6
6
|
|
|
7
7
|
import jwt
|
|
8
8
|
|
|
9
|
-
from dapla_metadata.
|
|
10
|
-
from dapla_metadata.
|
|
11
|
-
from dapla_metadata.
|
|
9
|
+
from dapla_metadata._shared import config
|
|
10
|
+
from dapla_metadata._shared.enums import DaplaRegion
|
|
11
|
+
from dapla_metadata._shared.enums import DaplaService
|
|
12
12
|
|
|
13
13
|
logger = logging.getLogger(__name__)
|
|
14
14
|
|
|
@@ -90,7 +90,7 @@ def get_user_info_for_current_platform() -> UserInfo:
|
|
|
90
90
|
|
|
91
91
|
def get_owner() -> str:
|
|
92
92
|
"""Returns the owner read from the GROUP_CONTEXT environment variable."""
|
|
93
|
-
if group := config.
|
|
93
|
+
if group := config.get_dapla_group_context():
|
|
94
94
|
return parse_team_name(group)
|
|
95
95
|
msg = "DAPLA_GROUP_CONTEXT environment variable not found"
|
|
96
96
|
raise OSError(msg)
|
dapla_metadata/datasets/core.py
CHANGED
|
@@ -13,8 +13,8 @@ from typing import TYPE_CHECKING
|
|
|
13
13
|
from datadoc_model import model
|
|
14
14
|
from datadoc_model.model import DataSetStatus
|
|
15
15
|
|
|
16
|
-
from dapla_metadata.
|
|
17
|
-
from dapla_metadata.
|
|
16
|
+
from dapla_metadata._shared import config
|
|
17
|
+
from dapla_metadata._shared import user_info
|
|
18
18
|
from dapla_metadata.datasets.dapla_dataset_path_info import DaplaDatasetPathInfo
|
|
19
19
|
from dapla_metadata.datasets.dataset_parser import DatasetParser
|
|
20
20
|
from dapla_metadata.datasets.model_backwards_compatibility import (
|
|
@@ -507,7 +507,10 @@ class Datadoc:
|
|
|
507
507
|
content = self.container.model_dump_json(indent=4)
|
|
508
508
|
self.metadata_document.write_text(content)
|
|
509
509
|
logger.info("Saved metadata document %s", self.metadata_document)
|
|
510
|
-
logger.info(
|
|
510
|
+
logger.info(
|
|
511
|
+
"Metadata content",
|
|
512
|
+
extra={"metadata_content": json.loads(content)},
|
|
513
|
+
)
|
|
511
514
|
else:
|
|
512
515
|
msg = "No metadata document to save"
|
|
513
516
|
raise ValueError(msg)
|
|
@@ -5,25 +5,6 @@ from __future__ import annotations
|
|
|
5
5
|
from enum import Enum
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
class DaplaRegion(str, Enum):
|
|
9
|
-
"""Dapla platforms/regions."""
|
|
10
|
-
|
|
11
|
-
DAPLA_LAB = "DAPLA_LAB"
|
|
12
|
-
BIP = "BIP"
|
|
13
|
-
ON_PREM = "ON_PREM"
|
|
14
|
-
CLOUD_RUN = "CLOUD_RUN"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
class DaplaService(str, Enum):
|
|
18
|
-
"""Dapla services."""
|
|
19
|
-
|
|
20
|
-
DATADOC = "DATADOC"
|
|
21
|
-
JUPYTERLAB = "JUPYTERLAB"
|
|
22
|
-
VS_CODE = "VS_CODE"
|
|
23
|
-
R_STUDIO = "R_STUDIO"
|
|
24
|
-
KILDOMATEN = "KILDOMATEN"
|
|
25
|
-
|
|
26
|
-
|
|
27
8
|
class SupportedLanguages(str, Enum):
|
|
28
9
|
"""The list of languages metadata may be recorded in.
|
|
29
10
|
|
|
@@ -14,7 +14,7 @@ from datadoc_model.model import Assessment
|
|
|
14
14
|
from datadoc_model.model import DataSetState
|
|
15
15
|
from datadoc_model.model import VariableRole
|
|
16
16
|
|
|
17
|
-
from dapla_metadata.
|
|
17
|
+
from dapla_metadata._shared import user_info
|
|
18
18
|
from dapla_metadata.datasets.utility.constants import (
|
|
19
19
|
DATASET_FIELDS_FROM_EXISTING_METADATA,
|
|
20
20
|
)
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"""Client for working with Variable Definitions at Statistics Norway."""
|
|
2
|
+
|
|
3
|
+
from .generated.vardef_client import models
|
|
4
|
+
from .generated.vardef_client.exceptions import * # noqa: F403
|
|
5
|
+
from .vardef import Vardef
|
|
6
|
+
from .variable_definition import CompletePatchOutput
|
|
7
|
+
from .variable_definition import VariableDefinition
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from dapla_metadata.variable_definitions.config import get_vardef_client_configuration
|
|
2
|
+
from dapla_metadata.variable_definitions.generated.vardef_client.api_client import (
|
|
3
|
+
ApiClient,
|
|
4
|
+
)
|
|
5
|
+
from dapla_metadata.variable_definitions.generated.vardef_client.configuration import (
|
|
6
|
+
Configuration,
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class VardefClient:
|
|
11
|
+
_client: ApiClient | None = None
|
|
12
|
+
_config: Configuration | None = None
|
|
13
|
+
|
|
14
|
+
@classmethod
|
|
15
|
+
def get_config(cls) -> Configuration | None:
|
|
16
|
+
"""Get the client configuration object."""
|
|
17
|
+
return cls._config
|
|
18
|
+
|
|
19
|
+
@classmethod
|
|
20
|
+
def set_config(cls, config: Configuration) -> None:
|
|
21
|
+
"""Set the client configuration object."""
|
|
22
|
+
cls._config = config
|
|
23
|
+
|
|
24
|
+
@classmethod
|
|
25
|
+
def get_client(cls) -> ApiClient:
|
|
26
|
+
if not cls._client:
|
|
27
|
+
if not cls._config:
|
|
28
|
+
cls._config = get_vardef_client_configuration()
|
|
29
|
+
cls._client = ApiClient(cls._config)
|
|
30
|
+
return cls._client
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from dapla_metadata._shared.config import get_config_item
|
|
2
|
+
from dapla_metadata._shared.config import get_dapla_environment
|
|
3
|
+
from dapla_metadata._shared.config import get_dapla_group_context
|
|
4
|
+
from dapla_metadata._shared.config import get_oidc_token
|
|
5
|
+
from dapla_metadata._shared.enums import DaplaEnvironment
|
|
6
|
+
from dapla_metadata.variable_definitions.generated.vardef_client.configuration import (
|
|
7
|
+
Configuration,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
VARDEF_HOST_TEST = "https://metadata.intern.test.ssb.no"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def get_active_group() -> str:
|
|
14
|
+
"""Get the group the user currently represents.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
A string with the active group.
|
|
18
|
+
"""
|
|
19
|
+
return str(get_dapla_group_context(raising=True))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def get_vardef_host() -> str:
|
|
23
|
+
"""Get the host for the server to make requests to.
|
|
24
|
+
|
|
25
|
+
Based on standard Dapla platform environment variables, or variables specific
|
|
26
|
+
to Vardef if these are not available.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
NotImplementedError: When Vardef is not available for the current environment.
|
|
30
|
+
"""
|
|
31
|
+
match get_dapla_environment():
|
|
32
|
+
case DaplaEnvironment.PROD:
|
|
33
|
+
msg = "Vardef is not available in prod."
|
|
34
|
+
raise NotImplementedError(msg)
|
|
35
|
+
case DaplaEnvironment.TEST:
|
|
36
|
+
return VARDEF_HOST_TEST
|
|
37
|
+
case DaplaEnvironment.DEV:
|
|
38
|
+
msg = "Vardef is not available in dev."
|
|
39
|
+
raise NotImplementedError(msg)
|
|
40
|
+
case _:
|
|
41
|
+
return get_config_item("VARDEF_HOST") or "http://localhost:8080"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def get_vardef_client_configuration() -> Configuration:
|
|
45
|
+
"""Build a config to be supplied to the `ApiClient`."""
|
|
46
|
+
return Configuration(
|
|
47
|
+
host=get_vardef_host(),
|
|
48
|
+
access_token=get_oidc_token(raising=True),
|
|
49
|
+
)
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Vardef client exceptions."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from functools import wraps
|
|
5
|
+
|
|
6
|
+
from dapla_metadata.variable_definitions.generated.vardef_client.exceptions import (
|
|
7
|
+
OpenApiException,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class VardefClientException(OpenApiException):
|
|
12
|
+
"""Custom exception to represent errors encountered in the Vardef client.
|
|
13
|
+
|
|
14
|
+
This exception extracts and formats error details from a JSON response body
|
|
15
|
+
provided by the Vardef API, enabling more descriptive error messages.
|
|
16
|
+
If the response body cannot be parsed as JSON or lacks expected keys,
|
|
17
|
+
default values are used to provide meaningful feedback.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, response_body: str) -> None:
|
|
21
|
+
"""Initialize the exception with a JSON-formatted response body.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
response_body (str): The JSON string containing error details
|
|
25
|
+
from the Vardef API response.
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
status (str): The status code from the response, or "Unknown status"
|
|
29
|
+
if not available or the response is invalid.
|
|
30
|
+
detail (str || list): A detailed error message from the response, or
|
|
31
|
+
"No detail provided" if not provided. If "Constraint violation"
|
|
32
|
+
detail contains 'field' and 'message'.
|
|
33
|
+
response_body (str): The raw response body string, stored for
|
|
34
|
+
debugging purposes.
|
|
35
|
+
"""
|
|
36
|
+
try:
|
|
37
|
+
data = json.loads(response_body)
|
|
38
|
+
self.status = data.get("status", "Unknown status")
|
|
39
|
+
if data.get("title") == "Constraint Violation":
|
|
40
|
+
violations = data.get("violations", [])
|
|
41
|
+
self.detail = "".join(
|
|
42
|
+
f"\n{violation.get('field', 'Unknown field')}: {violation.get('message', 'No message provided')}"
|
|
43
|
+
for violation in violations
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
else:
|
|
47
|
+
self.detail = data.get("detail", "No detail provided")
|
|
48
|
+
self.response_body = response_body
|
|
49
|
+
except (json.JSONDecodeError, TypeError):
|
|
50
|
+
self.status = "Unknown"
|
|
51
|
+
self.detail = "Could not decode error response from API"
|
|
52
|
+
data = None
|
|
53
|
+
super().__init__(f"Status {self.status}: {self.detail}")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def vardef_exception_handler(method): # noqa: ANN201, ANN001
|
|
57
|
+
"""Decorator for handling exceptions in Vardef."""
|
|
58
|
+
|
|
59
|
+
@wraps(method)
|
|
60
|
+
def _impl(self, *method_args, **method_kwargs): # noqa: ANN001, ANN002, ANN003
|
|
61
|
+
try:
|
|
62
|
+
return method(self, *method_args, **method_kwargs)
|
|
63
|
+
except OpenApiException as e:
|
|
64
|
+
raise VardefClientException(e.body) from e
|
|
65
|
+
|
|
66
|
+
return _impl
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
vardef_client/api/__init__.py
|
|
2
|
+
vardef_client/api/data_migration_api.py
|
|
3
|
+
vardef_client/api/draft_variable_definitions_api.py
|
|
4
|
+
vardef_client/api/patches_api.py
|
|
5
|
+
vardef_client/api/public_api.py
|
|
6
|
+
vardef_client/api/validity_periods_api.py
|
|
7
|
+
vardef_client/api/variable_definitions_api.py
|
|
8
|
+
vardef_client/models/__init__.py
|
|
9
|
+
vardef_client/models/complete_response.py
|
|
10
|
+
vardef_client/models/contact.py
|
|
11
|
+
vardef_client/models/draft.py
|
|
12
|
+
vardef_client/models/klass_reference.py
|
|
13
|
+
vardef_client/models/language_string_type.py
|
|
14
|
+
vardef_client/models/owner.py
|
|
15
|
+
vardef_client/models/patch.py
|
|
16
|
+
vardef_client/models/problem.py
|
|
17
|
+
vardef_client/models/rendered_contact.py
|
|
18
|
+
vardef_client/models/rendered_variable_definition.py
|
|
19
|
+
vardef_client/models/supported_languages.py
|
|
20
|
+
vardef_client/models/update_draft.py
|
|
21
|
+
vardef_client/models/validity_period.py
|
|
22
|
+
vardef_client/models/variable_status.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
7.9.0
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# vardef-client
|
|
2
|
+
|
|
3
|
+
No description provided (generated by Openapi Generator <https://github.com/openapitools/openapi-generator>)
|
|
4
|
+
|
|
5
|
+
This Python package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project:
|
|
6
|
+
|
|
7
|
+
- API version: 0.1
|
|
8
|
+
- Package version: 1.0.0
|
|
9
|
+
- Generator version: 7.9.0
|
|
10
|
+
- Build package: org.openapitools.codegen.languages.PythonClientCodegen
|
|
11
|
+
|
|
12
|
+
## Requirements
|
|
13
|
+
|
|
14
|
+
Python 3.7+
|
|
15
|
+
|
|
16
|
+
## Installation & Usage
|
|
17
|
+
|
|
18
|
+
### pip install
|
|
19
|
+
|
|
20
|
+
If the python package is hosted on a repository, you can install directly using:
|
|
21
|
+
|
|
22
|
+
```sh
|
|
23
|
+
pip install git+https://github.com/statisticsnorway/dapla-toolbelt-metadata.git
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
(you may need to run `pip` with root permission: `sudo pip install git+https://github.com/statisticsnorway/dapla-toolbelt-metadata.git`)
|
|
27
|
+
|
|
28
|
+
Then import the package:
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
import vardef_client
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Setuptools
|
|
35
|
+
|
|
36
|
+
Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
python setup.py install --user
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
(or `sudo python setup.py install` to install the package for all users)
|
|
43
|
+
|
|
44
|
+
Then import the package:
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import vardef_client
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Tests
|
|
51
|
+
|
|
52
|
+
Execute `pytest` to run the tests.
|
|
53
|
+
|
|
54
|
+
## Getting Started
|
|
55
|
+
|
|
56
|
+
Please follow the [installation procedure](#installation--usage) and then run the following:
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
|
|
60
|
+
import vardef_client
|
|
61
|
+
from vardef_client.rest import ApiException
|
|
62
|
+
from pprint import pprint
|
|
63
|
+
|
|
64
|
+
# Defining the host is optional and defaults to https://metadata.intern.test.ssb.no
|
|
65
|
+
# See configuration.py for a list of all supported configuration parameters.
|
|
66
|
+
configuration = vardef_client.Configuration(
|
|
67
|
+
host = "https://metadata.intern.test.ssb.no"
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
# The client must configure the authentication and authorization parameters
|
|
71
|
+
# in accordance with the API server security policy.
|
|
72
|
+
# Examples for each auth method are provided below, use the example that
|
|
73
|
+
# satisfies your auth use case.
|
|
74
|
+
|
|
75
|
+
# Configure Bearer authorization (JWT): Keycloak token
|
|
76
|
+
configuration = vardef_client.Configuration(
|
|
77
|
+
access_token = os.environ["BEARER_TOKEN"]
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
# Enter a context with an instance of the API client
|
|
82
|
+
with vardef_client.ApiClient(configuration) as api_client:
|
|
83
|
+
# Create an instance of the API class
|
|
84
|
+
api_instance = vardef_client.DataMigrationApi(api_client)
|
|
85
|
+
vardok_id = '1607' # str | The ID of the definition in Vardok.
|
|
86
|
+
active_group = 'dapla-felles-developers' # str | The group which the user currently represents.
|
|
87
|
+
|
|
88
|
+
try:
|
|
89
|
+
# Create a variable definition from a VarDok variable definition.
|
|
90
|
+
api_response = api_instance.create_variable_definition_from_var_dok(vardok_id, active_group)
|
|
91
|
+
print("The response of DataMigrationApi->create_variable_definition_from_var_dok:\n")
|
|
92
|
+
pprint(api_response)
|
|
93
|
+
except ApiException as e:
|
|
94
|
+
print("Exception when calling DataMigrationApi->create_variable_definition_from_var_dok: %s\n" % e)
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Documentation for API Endpoints
|
|
99
|
+
|
|
100
|
+
All URIs are relative to *<https://metadata.intern.test.ssb.no>*
|
|
101
|
+
|
|
102
|
+
Class | Method | HTTP request | Description
|
|
103
|
+
------------ | ------------- | ------------- | -------------
|
|
104
|
+
*DataMigrationApi* | [**create_variable_definition_from_var_dok**](vardef_client/docs/DataMigrationApi.md#create_variable_definition_from_var_dok) | **POST** /vardok-migration/{vardok-id} | Create a variable definition from a VarDok variable definition.
|
|
105
|
+
*DraftVariableDefinitionsApi* | [**create_variable_definition**](vardef_client/docs/DraftVariableDefinitionsApi.md#create_variable_definition) | **POST** /variable-definitions | Create a variable definition.
|
|
106
|
+
*DraftVariableDefinitionsApi* | [**delete_variable_definition_by_id**](vardef_client/docs/DraftVariableDefinitionsApi.md#delete_variable_definition_by_id) | **DELETE** /variable-definitions/{variable-definition-id} | Delete a variable definition.
|
|
107
|
+
*DraftVariableDefinitionsApi* | [**update_variable_definition_by_id**](vardef_client/docs/DraftVariableDefinitionsApi.md#update_variable_definition_by_id) | **PATCH** /variable-definitions/{variable-definition-id} | Update a variable definition.
|
|
108
|
+
*PatchesApi* | [**create_patch**](vardef_client/docs/PatchesApi.md#create_patch) | **POST** /variable-definitions/{variable-definition-id}/patches | Create a new patch for a variable definition.
|
|
109
|
+
*PatchesApi* | [**get_all_patches**](vardef_client/docs/PatchesApi.md#get_all_patches) | **GET** /variable-definitions/{variable-definition-id}/patches | List all patches for the given variable definition.
|
|
110
|
+
*PatchesApi* | [**get_one_patch**](vardef_client/docs/PatchesApi.md#get_one_patch) | **GET** /variable-definitions/{variable-definition-id}/patches/{patch-id} | Get one concrete patch for the given variable definition.
|
|
111
|
+
*PublicApi* | [**get_public_variable_definition_by_id**](vardef_client/docs/PublicApi.md#get_public_variable_definition_by_id) | **GET** /public/variable-definitions/{variable-definition-id} | Get one variable definition.
|
|
112
|
+
*PublicApi* | [**list_public_validity_periods**](vardef_client/docs/PublicApi.md#list_public_validity_periods) | **GET** /public/variable-definitions/{variable-definition-id}/validity-periods | List all validity periods.
|
|
113
|
+
*PublicApi* | [**list_public_variable_definitions**](vardef_client/docs/PublicApi.md#list_public_variable_definitions) | **GET** /public/variable-definitions | List all variable definitions.
|
|
114
|
+
*ValidityPeriodsApi* | [**create_validity_period**](vardef_client/docs/ValidityPeriodsApi.md#create_validity_period) | **POST** /variable-definitions/{variable-definition-id}/validity-periods | Create a new validity period for a variable definition.
|
|
115
|
+
*ValidityPeriodsApi* | [**list_public_validity_periods_0**](vardef_client/docs/ValidityPeriodsApi.md#list_public_validity_periods_0) | **GET** /public/variable-definitions/{variable-definition-id}/validity-periods | List all validity periods.
|
|
116
|
+
*ValidityPeriodsApi* | [**list_validity_periods**](vardef_client/docs/ValidityPeriodsApi.md#list_validity_periods) | **GET** /variable-definitions/{variable-definition-id}/validity-periods | List all validity periods.
|
|
117
|
+
*VariableDefinitionsApi* | [**get_public_variable_definition_by_id_0**](vardef_client/docs/VariableDefinitionsApi.md#get_public_variable_definition_by_id_0) | **GET** /public/variable-definitions/{variable-definition-id} | Get one variable definition.
|
|
118
|
+
*VariableDefinitionsApi* | [**get_variable_definition_by_id**](vardef_client/docs/VariableDefinitionsApi.md#get_variable_definition_by_id) | **GET** /variable-definitions/{variable-definition-id} | Get one variable definition.
|
|
119
|
+
*VariableDefinitionsApi* | [**list_public_variable_definitions_0**](vardef_client/docs/VariableDefinitionsApi.md#list_public_variable_definitions_0) | **GET** /public/variable-definitions | List all variable definitions.
|
|
120
|
+
*VariableDefinitionsApi* | [**list_variable_definitions**](vardef_client/docs/VariableDefinitionsApi.md#list_variable_definitions) | **GET** /variable-definitions | List all variable definitions.
|
|
121
|
+
|
|
122
|
+
## Documentation For Models
|
|
123
|
+
|
|
124
|
+
- [CompleteResponse](vardef_client/docs/CompleteResponse.md)
|
|
125
|
+
- [Contact](vardef_client/docs/Contact.md)
|
|
126
|
+
- [Draft](vardef_client/docs/Draft.md)
|
|
127
|
+
- [LanguageStringType](vardef_client/docs/LanguageStringType.md)
|
|
128
|
+
- [Owner](vardef_client/docs/Owner.md)
|
|
129
|
+
- [Patch](vardef_client/docs/Patch.md)
|
|
130
|
+
- [SupportedLanguages](vardef_client/docs/SupportedLanguages.md)
|
|
131
|
+
- [UpdateDraft](vardef_client/docs/UpdateDraft.md)
|
|
132
|
+
- [ValidityPeriod](vardef_client/docs/ValidityPeriod.md)
|
|
133
|
+
- [VariableStatus](vardef_client/docs/VariableStatus.md)
|
|
134
|
+
|
|
135
|
+
<a id="documentation-for-authorization"></a>
|
|
136
|
+
|
|
137
|
+
## Documentation For Authorization
|
|
138
|
+
|
|
139
|
+
Authentication schemes defined for the API:
|
|
140
|
+
<a id="Keycloak token"></a>
|
|
141
|
+
|
|
142
|
+
### Keycloak token
|
|
143
|
+
|
|
144
|
+
- **Type**: Bearer authentication (JWT)
|
|
145
|
+
|
|
146
|
+
## Author
|
|
147
|
+
|
|
148
|
+
<metadata@ssb.no>
|
|
File without changes
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
# flake8: noqa
|
|
4
|
+
|
|
5
|
+
"""
|
|
6
|
+
Variable Definitions
|
|
7
|
+
|
|
8
|
+
## Introduction Variable Definitions are centralized definitions of concrete variables which are typically present in multiple datasets. Variable Definitions support standardization of data and metadata and facilitate sharing and joining of data by clarifying when variables have an identical definition. ## Maintenance of Variable Definitions This API allows for creation, maintenance and access of Variable Definitions. ### Ownership Creation and maintenance of variables may only be performed by Statistics Norway employees representing a specific Dapla team, who are defined as the owners of a given Variable Definition. The team an owner represents must be specified when making a request through the `active_group` query parameter. All maintenance is to be performed by the owners, with no intervention from administrators. ### Status All Variable Definitions have an associated status. The possible values for status are `DRAFT`, `PUBLISHED_INTERNAL` and `PUBLISHED_EXTERNAL`. #### Draft When a Variable Definition is created it is assigned the status `DRAFT`. Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Mutable (it may be changed directly without need for versioning). - Not suitable to refer to from other systems. This status may be changed to `PUBLISHED_INTERNAL` or `PUBLISHED_EXTERNAL` with a direct update. #### Published Internal Under this status the Variable Definition is: - Only visible to Statistics Norway employees. - Immutable (all changes are versioned). - Suitable to refer to in internal systems for statistics production. - Not suitable to refer to for external use (for example in Statistikkbanken). This status may be changed to `PUBLISHED_EXTERNAL` by creating a Patch version. #### Published External Under this status the Variable Definition is: - Visible to the general public. - Immutable (all changes are versioned). - Suitable to refer to from any system. This status may not be changed as it would break immutability. If a Variable Definition is no longer relevant then its period of validity should be ended by specifying a `valid_until` date in a Patch version. ### Immutability Variable Definitions are immutable. This means that any changes must be performed in a strict versioning system. Consumers can avoid being exposed to breaking changes by specifying a `date_of_validity` when they request a Variable Definition. #### Patches Patches are for changes which do not affect the fundamental meaning of the Variable Definition. #### Validity Periods Validity Periods are versions with a period defined by a `valid_from` date and optionally a `valid_until` date. If the fundamental meaning of a Variable Definition is to be changed, it should be done by creating a new Validity Period.
|
|
9
|
+
|
|
10
|
+
The version of the OpenAPI document: 0.1
|
|
11
|
+
Contact: metadata@ssb.no
|
|
12
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
13
|
+
|
|
14
|
+
Do not edit the class manually.
|
|
15
|
+
""" # noqa: E501
|
|
16
|
+
|
|
17
|
+
__version__ = "1.0.0"
|
|
18
|
+
|
|
19
|
+
# import apis into sdk package
|
|
20
|
+
from .api.data_migration_api import DataMigrationApi
|
|
21
|
+
from .api.draft_variable_definitions_api import DraftVariableDefinitionsApi
|
|
22
|
+
from .api.patches_api import PatchesApi
|
|
23
|
+
from .api.public_api import PublicApi
|
|
24
|
+
from .api.validity_periods_api import ValidityPeriodsApi
|
|
25
|
+
from .api.variable_definitions_api import VariableDefinitionsApi
|
|
26
|
+
|
|
27
|
+
# import ApiClient
|
|
28
|
+
from .api_response import ApiResponse
|
|
29
|
+
from .api_client import ApiClient
|
|
30
|
+
from .configuration import Configuration
|
|
31
|
+
from .exceptions import OpenApiException
|
|
32
|
+
from .exceptions import ApiTypeError
|
|
33
|
+
from .exceptions import ApiValueError
|
|
34
|
+
from .exceptions import ApiKeyError
|
|
35
|
+
from .exceptions import ApiAttributeError
|
|
36
|
+
from .exceptions import ApiException
|
|
37
|
+
|
|
38
|
+
# import models into sdk package
|
|
39
|
+
from .models.complete_response import CompleteResponse
|
|
40
|
+
from .models.contact import Contact
|
|
41
|
+
from .models.draft import Draft
|
|
42
|
+
from .models.klass_reference import KlassReference
|
|
43
|
+
from .models.language_string_type import LanguageStringType
|
|
44
|
+
from .models.owner import Owner
|
|
45
|
+
from .models.patch import Patch
|
|
46
|
+
from .models.problem import Problem
|
|
47
|
+
from .models.rendered_contact import RenderedContact
|
|
48
|
+
from .models.rendered_variable_definition import RenderedVariableDefinition
|
|
49
|
+
from .models.supported_languages import SupportedLanguages
|
|
50
|
+
from .models.update_draft import UpdateDraft
|
|
51
|
+
from .models.validity_period import ValidityPeriod
|
|
52
|
+
from .models.variable_status import VariableStatus
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# flake8: noqa
|
|
2
|
+
|
|
3
|
+
# import apis into api package
|
|
4
|
+
from ..api.data_migration_api import DataMigrationApi
|
|
5
|
+
from ..api.draft_variable_definitions_api import DraftVariableDefinitionsApi
|
|
6
|
+
from ..api.patches_api import PatchesApi
|
|
7
|
+
from ..api.public_api import PublicApi
|
|
8
|
+
from ..api.validity_periods_api import ValidityPeriodsApi
|
|
9
|
+
from ..api.variable_definitions_api import VariableDefinitionsApi
|