dapla-toolbelt-metadata 0.2.1__py3-none-any.whl → 0.9.11__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 +11 -1
- dapla_metadata/_shared/__init__.py +1 -0
- dapla_metadata/_shared/config.py +109 -0
- dapla_metadata/_shared/enums.py +27 -0
- dapla_metadata/_shared/py.typed +0 -0
- dapla_metadata/dapla/__init__.py +4 -0
- dapla_metadata/dapla/user_info.py +138 -0
- dapla_metadata/datasets/__init__.py +1 -1
- dapla_metadata/datasets/_merge.py +333 -0
- dapla_metadata/datasets/code_list.py +5 -6
- dapla_metadata/datasets/compatibility/__init__.py +10 -0
- dapla_metadata/datasets/compatibility/_handlers.py +363 -0
- dapla_metadata/datasets/compatibility/_utils.py +259 -0
- dapla_metadata/datasets/compatibility/model_backwards_compatibility.py +135 -0
- dapla_metadata/datasets/core.py +136 -182
- dapla_metadata/datasets/dapla_dataset_path_info.py +145 -19
- dapla_metadata/datasets/dataset_parser.py +41 -28
- dapla_metadata/datasets/model_validation.py +29 -20
- dapla_metadata/datasets/statistic_subject_mapping.py +5 -1
- dapla_metadata/datasets/utility/constants.py +22 -15
- dapla_metadata/datasets/utility/enums.py +8 -20
- dapla_metadata/datasets/utility/urn.py +234 -0
- dapla_metadata/datasets/utility/utils.py +183 -111
- dapla_metadata/standards/__init__.py +4 -0
- dapla_metadata/standards/name_validator.py +250 -0
- dapla_metadata/standards/standard_validators.py +98 -0
- dapla_metadata/standards/utils/__init__.py +1 -0
- dapla_metadata/standards/utils/constants.py +49 -0
- dapla_metadata/variable_definitions/__init__.py +11 -0
- dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +20 -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 +47 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/__init__.py +8 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +766 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/draft_variable_definitions_api.py +888 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/patches_api.py +888 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/validity_periods_api.py +583 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/api/variable_definitions_api.py +613 -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 +31 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/complete_response.py +260 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/contact.py +94 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/draft.py +228 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +158 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/language_string_type.py +101 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/owner.py +87 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/patch.py +244 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/problem.py +118 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/update_draft.py +274 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/validity_period.py +225 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_id_response.py +81 -0
- dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_vardef_id_pair_response.py +84 -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/_utils/__init__.py +1 -0
- dapla_metadata/variable_definitions/_utils/_client.py +32 -0
- dapla_metadata/variable_definitions/_utils/config.py +54 -0
- dapla_metadata/variable_definitions/_utils/constants.py +80 -0
- dapla_metadata/variable_definitions/_utils/files.py +309 -0
- dapla_metadata/variable_definitions/_utils/template_files.py +99 -0
- dapla_metadata/variable_definitions/_utils/variable_definition_files.py +143 -0
- dapla_metadata/variable_definitions/exceptions.py +255 -0
- dapla_metadata/variable_definitions/vardef.py +372 -0
- dapla_metadata/variable_definitions/vardok_id.py +48 -0
- dapla_metadata/variable_definitions/vardok_vardef_id_pair.py +47 -0
- dapla_metadata/variable_definitions/variable_definition.py +422 -0
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/METADATA +34 -36
- dapla_toolbelt_metadata-0.9.11.dist-info/RECORD +97 -0
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/WHEEL +1 -1
- dapla_metadata/datasets/config.py +0 -80
- dapla_metadata/datasets/model_backwards_compatibility.py +0 -520
- dapla_metadata/datasets/user_info.py +0 -88
- dapla_toolbelt_metadata-0.2.1.dist-info/RECORD +0 -22
- {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info/licenses}/LICENSE +0 -0
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""API response object."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import Generic
|
|
7
|
+
from typing import TypeVar
|
|
8
|
+
|
|
9
|
+
from pydantic import BaseModel
|
|
10
|
+
from pydantic import Field
|
|
11
|
+
from pydantic import StrictBytes
|
|
12
|
+
from pydantic import StrictInt
|
|
13
|
+
|
|
14
|
+
T = TypeVar("T")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class ApiResponse(BaseModel, Generic[T]):
|
|
18
|
+
"""API response object"""
|
|
19
|
+
|
|
20
|
+
status_code: StrictInt = Field(description="HTTP status code")
|
|
21
|
+
headers: Mapping[str, str] | None = Field(None, description="HTTP headers")
|
|
22
|
+
data: T = Field(description="Deserialized data given the data type")
|
|
23
|
+
raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
|
|
24
|
+
|
|
25
|
+
model_config = {
|
|
26
|
+
"arbitrary_types_allowed": True,
|
|
27
|
+
}
|
|
@@ -0,0 +1,474 @@
|
|
|
1
|
+
"""Variable Definitions
|
|
2
|
+
|
|
3
|
+
## 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.
|
|
4
|
+
|
|
5
|
+
The version of the OpenAPI document: 0.1
|
|
6
|
+
Contact: metadata@ssb.no
|
|
7
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
8
|
+
|
|
9
|
+
Do not edit the class manually.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import copy
|
|
13
|
+
import http.client as httplib
|
|
14
|
+
import logging
|
|
15
|
+
import multiprocessing
|
|
16
|
+
import sys
|
|
17
|
+
from logging import FileHandler
|
|
18
|
+
|
|
19
|
+
import urllib3
|
|
20
|
+
|
|
21
|
+
JSON_SCHEMA_VALIDATION_KEYWORDS = {
|
|
22
|
+
"multipleOf",
|
|
23
|
+
"maximum",
|
|
24
|
+
"exclusiveMaximum",
|
|
25
|
+
"minimum",
|
|
26
|
+
"exclusiveMinimum",
|
|
27
|
+
"maxLength",
|
|
28
|
+
"minLength",
|
|
29
|
+
"pattern",
|
|
30
|
+
"maxItems",
|
|
31
|
+
"minItems",
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Configuration:
|
|
36
|
+
"""This class contains various settings of the API client.
|
|
37
|
+
|
|
38
|
+
:param host: Base url.
|
|
39
|
+
:param ignore_operation_servers
|
|
40
|
+
Boolean to ignore operation servers for the API client.
|
|
41
|
+
Config will use `host` as the base url regardless of the operation servers.
|
|
42
|
+
:param api_key: Dict to store API key(s).
|
|
43
|
+
Each entry in the dict specifies an API key.
|
|
44
|
+
The dict key is the name of the security scheme in the OAS specification.
|
|
45
|
+
The dict value is the API key secret.
|
|
46
|
+
:param api_key_prefix: Dict to store API prefix (e.g. Bearer).
|
|
47
|
+
The dict key is the name of the security scheme in the OAS specification.
|
|
48
|
+
The dict value is an API key prefix when generating the auth data.
|
|
49
|
+
:param username: Username for HTTP basic authentication.
|
|
50
|
+
:param password: Password for HTTP basic authentication.
|
|
51
|
+
:param access_token: Access token.
|
|
52
|
+
:param server_index: Index to servers configuration.
|
|
53
|
+
:param server_variables: Mapping with string values to replace variables in
|
|
54
|
+
templated server configuration. The validation of enums is performed for
|
|
55
|
+
variables with defined enum values before.
|
|
56
|
+
:param server_operation_index: Mapping from operation ID to an index to server
|
|
57
|
+
configuration.
|
|
58
|
+
:param server_operation_variables: Mapping from operation ID to a mapping with
|
|
59
|
+
string values to replace variables in templated server configuration.
|
|
60
|
+
The validation of enums is performed for variables with defined enum
|
|
61
|
+
values before.
|
|
62
|
+
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
|
|
63
|
+
in PEM format.
|
|
64
|
+
:param retries: Number of retries for API requests.
|
|
65
|
+
|
|
66
|
+
:Example:
|
|
67
|
+
"""
|
|
68
|
+
|
|
69
|
+
_default = None
|
|
70
|
+
|
|
71
|
+
def __init__(
|
|
72
|
+
self,
|
|
73
|
+
host=None,
|
|
74
|
+
api_key=None,
|
|
75
|
+
api_key_prefix=None,
|
|
76
|
+
username=None,
|
|
77
|
+
password=None,
|
|
78
|
+
access_token=None,
|
|
79
|
+
server_index=None,
|
|
80
|
+
server_variables=None,
|
|
81
|
+
server_operation_index=None,
|
|
82
|
+
server_operation_variables=None,
|
|
83
|
+
ignore_operation_servers=False,
|
|
84
|
+
ssl_ca_cert=None,
|
|
85
|
+
retries=None,
|
|
86
|
+
*,
|
|
87
|
+
debug: bool | None = None,
|
|
88
|
+
) -> None:
|
|
89
|
+
"""Constructor"""
|
|
90
|
+
self._base_path = (
|
|
91
|
+
"https://metadata.intern.test.ssb.no" if host is None else host
|
|
92
|
+
)
|
|
93
|
+
"""Default Base url
|
|
94
|
+
"""
|
|
95
|
+
self.server_index = 0 if server_index is None and host is None else server_index
|
|
96
|
+
self.server_operation_index = server_operation_index or {}
|
|
97
|
+
"""Default server index
|
|
98
|
+
"""
|
|
99
|
+
self.server_variables = server_variables or {}
|
|
100
|
+
self.server_operation_variables = server_operation_variables or {}
|
|
101
|
+
"""Default server variables
|
|
102
|
+
"""
|
|
103
|
+
self.ignore_operation_servers = ignore_operation_servers
|
|
104
|
+
"""Ignore operation servers
|
|
105
|
+
"""
|
|
106
|
+
self.temp_folder_path = None
|
|
107
|
+
"""Temp file folder for downloading files
|
|
108
|
+
"""
|
|
109
|
+
# Authentication Settings
|
|
110
|
+
self.api_key = {}
|
|
111
|
+
if api_key:
|
|
112
|
+
self.api_key = api_key
|
|
113
|
+
"""dict to store API key(s)
|
|
114
|
+
"""
|
|
115
|
+
self.api_key_prefix = {}
|
|
116
|
+
if api_key_prefix:
|
|
117
|
+
self.api_key_prefix = api_key_prefix
|
|
118
|
+
"""dict to store API prefix (e.g. Bearer)
|
|
119
|
+
"""
|
|
120
|
+
self.refresh_api_key_hook = None
|
|
121
|
+
"""function hook to refresh API key if expired
|
|
122
|
+
"""
|
|
123
|
+
self.username = username
|
|
124
|
+
"""Username for HTTP basic authentication
|
|
125
|
+
"""
|
|
126
|
+
self.password = password
|
|
127
|
+
"""Password for HTTP basic authentication
|
|
128
|
+
"""
|
|
129
|
+
self.access_token = access_token
|
|
130
|
+
"""Access token
|
|
131
|
+
"""
|
|
132
|
+
self.logger = {}
|
|
133
|
+
"""Logging Settings
|
|
134
|
+
"""
|
|
135
|
+
self.logger["package_logger"] = logging.getLogger("vardef_client")
|
|
136
|
+
self.logger["urllib3_logger"] = logging.getLogger("urllib3")
|
|
137
|
+
self.logger_format = "%(asctime)s %(levelname)s %(message)s"
|
|
138
|
+
"""Log format
|
|
139
|
+
"""
|
|
140
|
+
self.logger_stream_handler = None
|
|
141
|
+
"""Log stream handler
|
|
142
|
+
"""
|
|
143
|
+
self.logger_file_handler: FileHandler | None = None
|
|
144
|
+
"""Log file handler
|
|
145
|
+
"""
|
|
146
|
+
self.logger_file = None
|
|
147
|
+
"""Debug file location
|
|
148
|
+
"""
|
|
149
|
+
if debug is not None:
|
|
150
|
+
self.debug = debug
|
|
151
|
+
else:
|
|
152
|
+
self.__debug = False
|
|
153
|
+
"""Debug switch
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
self.verify_ssl = True
|
|
157
|
+
"""SSL/TLS verification
|
|
158
|
+
Set this to false to skip verifying SSL certificate when calling API
|
|
159
|
+
from https server.
|
|
160
|
+
"""
|
|
161
|
+
self.ssl_ca_cert = ssl_ca_cert
|
|
162
|
+
"""Set this to customize the certificate file to verify the peer.
|
|
163
|
+
"""
|
|
164
|
+
self.cert_file = None
|
|
165
|
+
"""client certificate file
|
|
166
|
+
"""
|
|
167
|
+
self.key_file = None
|
|
168
|
+
"""client key file
|
|
169
|
+
"""
|
|
170
|
+
self.assert_hostname = None
|
|
171
|
+
"""Set this to True/False to enable/disable SSL hostname verification.
|
|
172
|
+
"""
|
|
173
|
+
self.tls_server_name = None
|
|
174
|
+
"""SSL/TLS Server Name Indication (SNI)
|
|
175
|
+
Set this to the SNI value expected by the server.
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
|
|
179
|
+
"""urllib3 connection pool's maximum number of connections saved
|
|
180
|
+
per pool. urllib3 uses 1 connection as default value, but this is
|
|
181
|
+
not the best value when you are making a lot of possibly parallel
|
|
182
|
+
requests to the same host, which is often the case here.
|
|
183
|
+
cpu_count * 5 is used as default value to increase performance.
|
|
184
|
+
"""
|
|
185
|
+
|
|
186
|
+
self.proxy: str | None = None
|
|
187
|
+
"""Proxy URL
|
|
188
|
+
"""
|
|
189
|
+
self.proxy_headers = None
|
|
190
|
+
"""Proxy headers
|
|
191
|
+
"""
|
|
192
|
+
self.safe_chars_for_path_param = ""
|
|
193
|
+
"""Safe chars for path_param
|
|
194
|
+
"""
|
|
195
|
+
self.retries = retries
|
|
196
|
+
"""Adding retries to override urllib3 default value 3
|
|
197
|
+
"""
|
|
198
|
+
# Enable client side validation
|
|
199
|
+
self.client_side_validation = True
|
|
200
|
+
|
|
201
|
+
self.socket_options = None
|
|
202
|
+
"""Options to pass down to the underlying urllib3 socket
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
|
|
206
|
+
"""datetime format
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
self.date_format = "%Y-%m-%d"
|
|
210
|
+
"""date format
|
|
211
|
+
"""
|
|
212
|
+
|
|
213
|
+
def __deepcopy__(self, memo):
|
|
214
|
+
cls = self.__class__
|
|
215
|
+
result = cls.__new__(cls)
|
|
216
|
+
memo[id(self)] = result
|
|
217
|
+
for k, v in self.__dict__.items():
|
|
218
|
+
if k not in ("logger", "logger_file_handler"):
|
|
219
|
+
setattr(result, k, copy.deepcopy(v, memo))
|
|
220
|
+
# shallow copy of loggers
|
|
221
|
+
result.logger = copy.copy(self.logger)
|
|
222
|
+
# use setters to configure loggers
|
|
223
|
+
result.logger_file = self.logger_file
|
|
224
|
+
result.debug = self.debug
|
|
225
|
+
return result
|
|
226
|
+
|
|
227
|
+
def __setattr__(self, name, value):
|
|
228
|
+
object.__setattr__(self, name, value)
|
|
229
|
+
|
|
230
|
+
@classmethod
|
|
231
|
+
def set_default(cls, default):
|
|
232
|
+
"""Set default instance of configuration.
|
|
233
|
+
|
|
234
|
+
It stores default configuration, which can be
|
|
235
|
+
returned by get_default_copy method.
|
|
236
|
+
|
|
237
|
+
:param default: object of Configuration
|
|
238
|
+
"""
|
|
239
|
+
cls._default = default
|
|
240
|
+
|
|
241
|
+
@classmethod
|
|
242
|
+
def get_default_copy(cls):
|
|
243
|
+
"""Deprecated. Please use `get_default` instead.
|
|
244
|
+
|
|
245
|
+
Deprecated. Please use `get_default` instead.
|
|
246
|
+
|
|
247
|
+
:return: The configuration object.
|
|
248
|
+
"""
|
|
249
|
+
return cls.get_default()
|
|
250
|
+
|
|
251
|
+
@classmethod
|
|
252
|
+
def get_default(cls):
|
|
253
|
+
"""Return the default configuration.
|
|
254
|
+
|
|
255
|
+
This method returns newly created, based on default constructor,
|
|
256
|
+
object of Configuration class or returns a copy of default
|
|
257
|
+
configuration.
|
|
258
|
+
|
|
259
|
+
:return: The configuration object.
|
|
260
|
+
"""
|
|
261
|
+
if cls._default is None:
|
|
262
|
+
cls._default = Configuration()
|
|
263
|
+
return cls._default
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def logger_file(self):
|
|
267
|
+
"""The logger file.
|
|
268
|
+
|
|
269
|
+
If the logger_file is None, then add stream handler and remove file
|
|
270
|
+
handler. Otherwise, add file handler and remove stream handler.
|
|
271
|
+
|
|
272
|
+
:param value: The logger_file path.
|
|
273
|
+
:type: str
|
|
274
|
+
"""
|
|
275
|
+
return self.__logger_file
|
|
276
|
+
|
|
277
|
+
@logger_file.setter
|
|
278
|
+
def logger_file(self, value):
|
|
279
|
+
"""The logger file.
|
|
280
|
+
|
|
281
|
+
If the logger_file is None, then add stream handler and remove file
|
|
282
|
+
handler. Otherwise, add file handler and remove stream handler.
|
|
283
|
+
|
|
284
|
+
:param value: The logger_file path.
|
|
285
|
+
:type: str
|
|
286
|
+
"""
|
|
287
|
+
self.__logger_file = value
|
|
288
|
+
if self.__logger_file:
|
|
289
|
+
# If set logging file,
|
|
290
|
+
# then add file handler and remove stream handler.
|
|
291
|
+
self.logger_file_handler = logging.FileHandler(self.__logger_file)
|
|
292
|
+
self.logger_file_handler.setFormatter(self.logger_formatter)
|
|
293
|
+
for _, logger in self.logger.items():
|
|
294
|
+
logger.addHandler(self.logger_file_handler)
|
|
295
|
+
|
|
296
|
+
@property
|
|
297
|
+
def debug(self):
|
|
298
|
+
"""Debug status
|
|
299
|
+
|
|
300
|
+
:param value: The debug status, True or False.
|
|
301
|
+
:type: bool
|
|
302
|
+
"""
|
|
303
|
+
return self.__debug
|
|
304
|
+
|
|
305
|
+
@debug.setter
|
|
306
|
+
def debug(self, value):
|
|
307
|
+
"""Debug status
|
|
308
|
+
|
|
309
|
+
:param value: The debug status, True or False.
|
|
310
|
+
:type: bool
|
|
311
|
+
"""
|
|
312
|
+
self.__debug = value
|
|
313
|
+
if self.__debug:
|
|
314
|
+
# if debug status is True, turn on debug logging
|
|
315
|
+
for _, logger in self.logger.items():
|
|
316
|
+
logger.setLevel(logging.DEBUG)
|
|
317
|
+
# turn on httplib debug
|
|
318
|
+
httplib.HTTPConnection.debuglevel = 1
|
|
319
|
+
else:
|
|
320
|
+
# if debug status is False, turn off debug logging,
|
|
321
|
+
# setting log level to default `logging.WARNING`
|
|
322
|
+
for _, logger in self.logger.items():
|
|
323
|
+
logger.setLevel(logging.WARNING)
|
|
324
|
+
# turn off httplib debug
|
|
325
|
+
httplib.HTTPConnection.debuglevel = 0
|
|
326
|
+
|
|
327
|
+
@property
|
|
328
|
+
def logger_format(self):
|
|
329
|
+
"""The logger format.
|
|
330
|
+
|
|
331
|
+
The logger_formatter will be updated when sets logger_format.
|
|
332
|
+
|
|
333
|
+
:param value: The format string.
|
|
334
|
+
:type: str
|
|
335
|
+
"""
|
|
336
|
+
return self.__logger_format
|
|
337
|
+
|
|
338
|
+
@logger_format.setter
|
|
339
|
+
def logger_format(self, value):
|
|
340
|
+
"""The logger format.
|
|
341
|
+
|
|
342
|
+
The logger_formatter will be updated when sets logger_format.
|
|
343
|
+
|
|
344
|
+
:param value: The format string.
|
|
345
|
+
:type: str
|
|
346
|
+
"""
|
|
347
|
+
self.__logger_format = value
|
|
348
|
+
self.logger_formatter = logging.Formatter(self.__logger_format)
|
|
349
|
+
|
|
350
|
+
def get_api_key_with_prefix(self, identifier, alias=None):
|
|
351
|
+
"""Gets API key (with prefix if set).
|
|
352
|
+
|
|
353
|
+
:param identifier: The identifier of apiKey.
|
|
354
|
+
:param alias: The alternative identifier of apiKey.
|
|
355
|
+
:return: The token for api key authentication.
|
|
356
|
+
"""
|
|
357
|
+
if self.refresh_api_key_hook is not None:
|
|
358
|
+
self.refresh_api_key_hook(self)
|
|
359
|
+
key = self.api_key.get(
|
|
360
|
+
identifier, self.api_key.get(alias) if alias is not None else None
|
|
361
|
+
)
|
|
362
|
+
if key:
|
|
363
|
+
prefix = self.api_key_prefix.get(identifier)
|
|
364
|
+
if prefix:
|
|
365
|
+
return "%s %s" % (prefix, key)
|
|
366
|
+
return key
|
|
367
|
+
|
|
368
|
+
def get_basic_auth_token(self):
|
|
369
|
+
"""Gets HTTP basic authentication header (string).
|
|
370
|
+
|
|
371
|
+
:return: The token for basic HTTP authentication.
|
|
372
|
+
"""
|
|
373
|
+
username = ""
|
|
374
|
+
if self.username is not None:
|
|
375
|
+
username = self.username
|
|
376
|
+
password = ""
|
|
377
|
+
if self.password is not None:
|
|
378
|
+
password = self.password
|
|
379
|
+
return urllib3.util.make_headers(
|
|
380
|
+
basic_auth=username + ":" + password,
|
|
381
|
+
).get("authorization")
|
|
382
|
+
|
|
383
|
+
def auth_settings(self):
|
|
384
|
+
"""Gets Auth Settings dict for api client.
|
|
385
|
+
|
|
386
|
+
:return: The Auth Settings information dict.
|
|
387
|
+
"""
|
|
388
|
+
auth = {}
|
|
389
|
+
if self.access_token is not None:
|
|
390
|
+
auth["keycloak_token"] = {
|
|
391
|
+
"type": "bearer",
|
|
392
|
+
"in": "header",
|
|
393
|
+
"format": "JWT",
|
|
394
|
+
"key": "Authorization",
|
|
395
|
+
"value": "Bearer " + self.access_token,
|
|
396
|
+
}
|
|
397
|
+
return auth
|
|
398
|
+
|
|
399
|
+
def to_debug_report(self):
|
|
400
|
+
"""Gets the essential information for debugging.
|
|
401
|
+
|
|
402
|
+
:return: The report for debugging.
|
|
403
|
+
"""
|
|
404
|
+
return (
|
|
405
|
+
"Python SDK Debug Report:\n"
|
|
406
|
+
f"OS: {sys.platform}\n"
|
|
407
|
+
f"Python Version: {sys.version}\n"
|
|
408
|
+
"Version of the API: 0.1\n"
|
|
409
|
+
"SDK Package Version: 1.0.0"
|
|
410
|
+
)
|
|
411
|
+
|
|
412
|
+
def get_host_settings(self):
|
|
413
|
+
"""Gets an array of host settings
|
|
414
|
+
|
|
415
|
+
:return: An array of host settings
|
|
416
|
+
"""
|
|
417
|
+
return [
|
|
418
|
+
{
|
|
419
|
+
"url": "https://metadata.intern.test.ssb.no",
|
|
420
|
+
"description": "Internal test server",
|
|
421
|
+
},
|
|
422
|
+
]
|
|
423
|
+
|
|
424
|
+
def get_host_from_settings(self, index, variables=None, servers=None):
|
|
425
|
+
"""Gets host URL based on the index and variables
|
|
426
|
+
:param index: array index of the host settings
|
|
427
|
+
:param variables: hash of variable and the corresponding value
|
|
428
|
+
:param servers: an array of host settings or None
|
|
429
|
+
:return: URL based on host settings
|
|
430
|
+
"""
|
|
431
|
+
if index is None:
|
|
432
|
+
return self._base_path
|
|
433
|
+
|
|
434
|
+
variables = {} if variables is None else variables
|
|
435
|
+
servers = self.get_host_settings() if servers is None else servers
|
|
436
|
+
|
|
437
|
+
try:
|
|
438
|
+
server = servers[index]
|
|
439
|
+
except IndexError:
|
|
440
|
+
raise ValueError(
|
|
441
|
+
f"Invalid index {index} when selecting the host settings. "
|
|
442
|
+
f"Must be less than {len(servers)}"
|
|
443
|
+
)
|
|
444
|
+
|
|
445
|
+
url = server["url"]
|
|
446
|
+
|
|
447
|
+
# go through variables and replace placeholders
|
|
448
|
+
for variable_name, variable in server.get("variables", {}).items():
|
|
449
|
+
used_value = variables.get(variable_name, variable["default_value"])
|
|
450
|
+
|
|
451
|
+
if "enum_values" in variable and used_value not in variable["enum_values"]:
|
|
452
|
+
raise ValueError(
|
|
453
|
+
"The variable `{0}` in the host URL has invalid value "
|
|
454
|
+
"{1}. Must be {2}.".format(
|
|
455
|
+
variable_name, variables[variable_name], variable["enum_values"]
|
|
456
|
+
)
|
|
457
|
+
)
|
|
458
|
+
|
|
459
|
+
url = url.replace("{" + variable_name + "}", used_value)
|
|
460
|
+
|
|
461
|
+
return url
|
|
462
|
+
|
|
463
|
+
@property
|
|
464
|
+
def host(self):
|
|
465
|
+
"""Return generated host."""
|
|
466
|
+
return self.get_host_from_settings(
|
|
467
|
+
self.server_index, variables=self.server_variables
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
@host.setter
|
|
471
|
+
def host(self, value):
|
|
472
|
+
"""Fix base path."""
|
|
473
|
+
self._base_path = value
|
|
474
|
+
self.server_index = None
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# CompleteResponse
|
|
2
|
+
|
|
3
|
+
Complete response For internal users who need all details while maintaining variable definitions.
|
|
4
|
+
|
|
5
|
+
## Properties
|
|
6
|
+
|
|
7
|
+
Name | Type | Description | Notes
|
|
8
|
+
------------ | ------------- | ------------- | -------------
|
|
9
|
+
**id** | **str** | Unique identifier for the variable definition. | [optional]
|
|
10
|
+
**patch_id** | **int** | Integer identifying a patch of a variable definition. |
|
|
11
|
+
**name** | [**LanguageStringType**](LanguageStringType.md) | Name of the variable. Must be unique for a given Unit Type and Owner combination. |
|
|
12
|
+
**short_name** | **str** | Recommended short name. Must be unique within an organization. |
|
|
13
|
+
**definition** | [**LanguageStringType**](LanguageStringType.md) | Definition of the variable. |
|
|
14
|
+
**classification_reference** | **str** | ID of a classification or code list from Klass. The given classification defines all possible values for the defined variable. | [optional]
|
|
15
|
+
**unit_types** | **List[str]** | A list of one or more unit types, e.g. person, vehicle, household. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/702. |
|
|
16
|
+
**subject_fields** | **List[str]** | A list of subject fields that the variable is used in. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/618. |
|
|
17
|
+
**contains_special_categories_of_personal_data** | **bool** | True if variable instances contain particularly sensitive information. Applies even if the information or identifiers are pseudonymized. Information within the following categories are regarded as particularly sensitive: Ethnicity, Political alignment, Religion, Philosophical beliefs, Union membership, Genetics, Biometrics, Health, Sexual relations, Sexual orientation |
|
|
18
|
+
**variable_status** | [**VariableStatus**](VariableStatus.md) | Status of the life cycle of the variable | [optional]
|
|
19
|
+
**measurement_type** | **str** | Type of measurement for the variable, e.g. length, volume, currency. Must be defined as codes from https://www.ssb.no/klass/klassifikasjoner/303 | [optional]
|
|
20
|
+
**valid_from** | **date** | The variable definition is valid from this date inclusive |
|
|
21
|
+
**valid_until** | **date** | The variable definition is valid until this date inclusive | [optional]
|
|
22
|
+
**external_reference_uri** | **str** | A link (URI) to an external definition/documentation | [optional]
|
|
23
|
+
**comment** | [**LanguageStringType**](LanguageStringType.md) | Optional comment to explain the definition or communicate potential changes. | [optional]
|
|
24
|
+
**related_variable_definition_uris** | **List[str]** | Link(s) to related definitions of variables - a list of one or more definitions. For example for a variable after-tax income it could be relevant to link to definitions of income from work, property income etc. | [optional]
|
|
25
|
+
**owner** | [**Owner**](Owner.md) | Owner of the definition, i.e. responsible Dapla team (statistics team) and information about access management groups. |
|
|
26
|
+
**contact** | [**Contact**](Contact.md) | Contact details | [optional]
|
|
27
|
+
**created_at** | **datetime** | The timestamp at which this variable definition was first created. |
|
|
28
|
+
**created_by** | **str** | The user who created this variable definition. | [optional]
|
|
29
|
+
**last_updated_at** | **datetime** | The timestamp at which this variable definition was last modified. |
|
|
30
|
+
**last_updated_by** | **str** | The user who last modified this variable definition. | [optional]
|
|
31
|
+
|
|
32
|
+
## Example
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from vardef_client.models.complete_response import CompleteResponse
|
|
36
|
+
|
|
37
|
+
# TODO update the JSON string below
|
|
38
|
+
json = "{}"
|
|
39
|
+
# create an instance of CompleteResponse from a JSON string
|
|
40
|
+
complete_response_instance = CompleteResponse.from_json(json)
|
|
41
|
+
# print the JSON string representation of the object
|
|
42
|
+
print(CompleteResponse.to_json())
|
|
43
|
+
|
|
44
|
+
# convert the object into a dict
|
|
45
|
+
complete_response_dict = complete_response_instance.to_dict()
|
|
46
|
+
# create an instance of CompleteResponse from a dict
|
|
47
|
+
complete_response_from_dict = CompleteResponse.from_dict(complete_response_dict)
|
|
48
|
+
```
|
|
49
|
+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Contact
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
## Properties
|
|
5
|
+
|
|
6
|
+
Name | Type | Description | Notes
|
|
7
|
+
------------ | ------------- | ------------- | -------------
|
|
8
|
+
**title** | [**LanguageStringType**](LanguageStringType.md) | |
|
|
9
|
+
**email** | **str** | |
|
|
10
|
+
|
|
11
|
+
## Example
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from vardef_client.models.contact import Contact
|
|
15
|
+
|
|
16
|
+
# TODO update the JSON string below
|
|
17
|
+
json = "{}"
|
|
18
|
+
# create an instance of Contact from a JSON string
|
|
19
|
+
contact_instance = Contact.from_json(json)
|
|
20
|
+
# print the JSON string representation of the object
|
|
21
|
+
print(Contact.to_json())
|
|
22
|
+
|
|
23
|
+
# convert the object into a dict
|
|
24
|
+
contact_dict = contact_instance.to_dict()
|
|
25
|
+
# create an instance of Contact from a dict
|
|
26
|
+
contact_from_dict = Contact.from_dict(contact_dict)
|
|
27
|
+
```
|
|
28
|
+
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)
|
|
29
|
+
|
|
30
|
+
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# vardef_client.DataMigrationApi
|
|
2
|
+
|
|
3
|
+
All URIs are relative to *https://metadata.intern.test.ssb.no*
|
|
4
|
+
|
|
5
|
+
Method | HTTP request | Description
|
|
6
|
+
------------- | ------------- | -------------
|
|
7
|
+
[**create_variable_definition_from_var_dok**](DataMigrationApi.md#create_variable_definition_from_var_dok) | **POST** /vardok-migration/{vardok-id} | Create a variable definition from a VarDok variable definition.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# **create_variable_definition_from_var_dok**
|
|
11
|
+
> CompleteResponse create_variable_definition_from_var_dok(vardok_id, active_group)
|
|
12
|
+
|
|
13
|
+
Create a variable definition from a VarDok variable definition.
|
|
14
|
+
|
|
15
|
+
Create a variable definition from a VarDok variable definition.
|
|
16
|
+
|
|
17
|
+
### Example
|
|
18
|
+
|
|
19
|
+
* Bearer (JWT) Authentication (Keycloak token):
|
|
20
|
+
|
|
21
|
+
```python
|
|
22
|
+
import vardef_client
|
|
23
|
+
from vardef_client.models.complete_response import CompleteResponse
|
|
24
|
+
from vardef_client.rest import ApiException
|
|
25
|
+
from pprint import pprint
|
|
26
|
+
|
|
27
|
+
# Defining the host is optional and defaults to https://metadata.intern.test.ssb.no
|
|
28
|
+
# See configuration.py for a list of all supported configuration parameters.
|
|
29
|
+
configuration = vardef_client.Configuration(
|
|
30
|
+
host = "https://metadata.intern.test.ssb.no"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
# The client must configure the authentication and authorization parameters
|
|
34
|
+
# in accordance with the API server security policy.
|
|
35
|
+
# Examples for each auth method are provided below, use the example that
|
|
36
|
+
# satisfies your auth use case.
|
|
37
|
+
|
|
38
|
+
# Configure Bearer authorization (JWT): Keycloak token
|
|
39
|
+
configuration = vardef_client.Configuration(
|
|
40
|
+
access_token = os.environ["BEARER_TOKEN"]
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
# Enter a context with an instance of the API client
|
|
44
|
+
with vardef_client.ApiClient(configuration) as api_client:
|
|
45
|
+
# Create an instance of the API class
|
|
46
|
+
api_instance = vardef_client.DataMigrationApi(api_client)
|
|
47
|
+
vardok_id = '1607' # str | The ID of the definition in Vardok.
|
|
48
|
+
active_group = 'dapla-felles-developers' # str | The group which the user currently represents.
|
|
49
|
+
|
|
50
|
+
try:
|
|
51
|
+
# Create a variable definition from a VarDok variable definition.
|
|
52
|
+
api_response = api_instance.create_variable_definition_from_var_dok(vardok_id, active_group)
|
|
53
|
+
print("The response of DataMigrationApi->create_variable_definition_from_var_dok:\n")
|
|
54
|
+
pprint(api_response)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
print("Exception when calling DataMigrationApi->create_variable_definition_from_var_dok: %s\n" % e)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
### Parameters
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
Name | Type | Description | Notes
|
|
65
|
+
------------- | ------------- | ------------- | -------------
|
|
66
|
+
**vardok_id** | **str**| The ID of the definition in Vardok. |
|
|
67
|
+
**active_group** | **str**| The group which the user currently represents. |
|
|
68
|
+
|
|
69
|
+
### Return type
|
|
70
|
+
|
|
71
|
+
[**CompleteResponse**](CompleteResponse.md)
|
|
72
|
+
|
|
73
|
+
### Authorization
|
|
74
|
+
|
|
75
|
+
[Keycloak token](../README.md#Keycloak token)
|
|
76
|
+
|
|
77
|
+
### HTTP request headers
|
|
78
|
+
|
|
79
|
+
- **Content-Type**: Not defined
|
|
80
|
+
- **Accept**: application/json
|
|
81
|
+
|
|
82
|
+
### HTTP response details
|
|
83
|
+
|
|
84
|
+
| Status code | Description | Response headers |
|
|
85
|
+
|-------------|-------------|------------------|
|
|
86
|
+
**201** | Successfully created. | - |
|
|
87
|
+
**400** | The definition in Vardok has missing or malformed metadata. | - |
|
|
88
|
+
|
|
89
|
+
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
|
|
90
|
+
|