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.

Files changed (97) hide show
  1. dapla_metadata/__init__.py +11 -1
  2. dapla_metadata/_shared/__init__.py +1 -0
  3. dapla_metadata/_shared/config.py +109 -0
  4. dapla_metadata/_shared/enums.py +27 -0
  5. dapla_metadata/_shared/py.typed +0 -0
  6. dapla_metadata/dapla/__init__.py +4 -0
  7. dapla_metadata/dapla/user_info.py +138 -0
  8. dapla_metadata/datasets/__init__.py +1 -1
  9. dapla_metadata/datasets/_merge.py +333 -0
  10. dapla_metadata/datasets/code_list.py +5 -6
  11. dapla_metadata/datasets/compatibility/__init__.py +10 -0
  12. dapla_metadata/datasets/compatibility/_handlers.py +363 -0
  13. dapla_metadata/datasets/compatibility/_utils.py +259 -0
  14. dapla_metadata/datasets/compatibility/model_backwards_compatibility.py +135 -0
  15. dapla_metadata/datasets/core.py +136 -182
  16. dapla_metadata/datasets/dapla_dataset_path_info.py +145 -19
  17. dapla_metadata/datasets/dataset_parser.py +41 -28
  18. dapla_metadata/datasets/model_validation.py +29 -20
  19. dapla_metadata/datasets/statistic_subject_mapping.py +5 -1
  20. dapla_metadata/datasets/utility/constants.py +22 -15
  21. dapla_metadata/datasets/utility/enums.py +8 -20
  22. dapla_metadata/datasets/utility/urn.py +234 -0
  23. dapla_metadata/datasets/utility/utils.py +183 -111
  24. dapla_metadata/standards/__init__.py +4 -0
  25. dapla_metadata/standards/name_validator.py +250 -0
  26. dapla_metadata/standards/standard_validators.py +98 -0
  27. dapla_metadata/standards/utils/__init__.py +1 -0
  28. dapla_metadata/standards/utils/constants.py +49 -0
  29. dapla_metadata/variable_definitions/__init__.py +11 -0
  30. dapla_metadata/variable_definitions/_generated/.openapi-generator/FILES +20 -0
  31. dapla_metadata/variable_definitions/_generated/.openapi-generator/VERSION +1 -0
  32. dapla_metadata/variable_definitions/_generated/.openapi-generator-ignore +6 -0
  33. dapla_metadata/variable_definitions/_generated/README.md +148 -0
  34. dapla_metadata/variable_definitions/_generated/__init__.py +0 -0
  35. dapla_metadata/variable_definitions/_generated/vardef_client/__init__.py +47 -0
  36. dapla_metadata/variable_definitions/_generated/vardef_client/api/__init__.py +8 -0
  37. dapla_metadata/variable_definitions/_generated/vardef_client/api/data_migration_api.py +766 -0
  38. dapla_metadata/variable_definitions/_generated/vardef_client/api/draft_variable_definitions_api.py +888 -0
  39. dapla_metadata/variable_definitions/_generated/vardef_client/api/patches_api.py +888 -0
  40. dapla_metadata/variable_definitions/_generated/vardef_client/api/validity_periods_api.py +583 -0
  41. dapla_metadata/variable_definitions/_generated/vardef_client/api/variable_definitions_api.py +613 -0
  42. dapla_metadata/variable_definitions/_generated/vardef_client/api_client.py +779 -0
  43. dapla_metadata/variable_definitions/_generated/vardef_client/api_response.py +27 -0
  44. dapla_metadata/variable_definitions/_generated/vardef_client/configuration.py +474 -0
  45. dapla_metadata/variable_definitions/_generated/vardef_client/docs/CompleteResponse.md +51 -0
  46. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Contact.md +30 -0
  47. dapla_metadata/variable_definitions/_generated/vardef_client/docs/DataMigrationApi.md +90 -0
  48. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Draft.md +42 -0
  49. dapla_metadata/variable_definitions/_generated/vardef_client/docs/DraftVariableDefinitionsApi.md +259 -0
  50. dapla_metadata/variable_definitions/_generated/vardef_client/docs/LanguageStringType.md +31 -0
  51. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Owner.md +31 -0
  52. dapla_metadata/variable_definitions/_generated/vardef_client/docs/Patch.md +43 -0
  53. dapla_metadata/variable_definitions/_generated/vardef_client/docs/PatchesApi.md +249 -0
  54. dapla_metadata/variable_definitions/_generated/vardef_client/docs/PublicApi.md +218 -0
  55. dapla_metadata/variable_definitions/_generated/vardef_client/docs/SupportedLanguages.md +15 -0
  56. dapla_metadata/variable_definitions/_generated/vardef_client/docs/UpdateDraft.md +44 -0
  57. dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriod.md +42 -0
  58. dapla_metadata/variable_definitions/_generated/vardef_client/docs/ValidityPeriodsApi.md +236 -0
  59. dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableDefinitionsApi.md +304 -0
  60. dapla_metadata/variable_definitions/_generated/vardef_client/docs/VariableStatus.md +17 -0
  61. dapla_metadata/variable_definitions/_generated/vardef_client/exceptions.py +193 -0
  62. dapla_metadata/variable_definitions/_generated/vardef_client/models/__init__.py +31 -0
  63. dapla_metadata/variable_definitions/_generated/vardef_client/models/complete_response.py +260 -0
  64. dapla_metadata/variable_definitions/_generated/vardef_client/models/contact.py +94 -0
  65. dapla_metadata/variable_definitions/_generated/vardef_client/models/draft.py +228 -0
  66. dapla_metadata/variable_definitions/_generated/vardef_client/models/get_vardok_vardef_mapping_by_id200_response.py +158 -0
  67. dapla_metadata/variable_definitions/_generated/vardef_client/models/language_string_type.py +101 -0
  68. dapla_metadata/variable_definitions/_generated/vardef_client/models/owner.py +87 -0
  69. dapla_metadata/variable_definitions/_generated/vardef_client/models/patch.py +244 -0
  70. dapla_metadata/variable_definitions/_generated/vardef_client/models/problem.py +118 -0
  71. dapla_metadata/variable_definitions/_generated/vardef_client/models/update_draft.py +274 -0
  72. dapla_metadata/variable_definitions/_generated/vardef_client/models/validity_period.py +225 -0
  73. dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_id_response.py +81 -0
  74. dapla_metadata/variable_definitions/_generated/vardef_client/models/vardok_vardef_id_pair_response.py +84 -0
  75. dapla_metadata/variable_definitions/_generated/vardef_client/models/variable_status.py +33 -0
  76. dapla_metadata/variable_definitions/_generated/vardef_client/py.typed +0 -0
  77. dapla_metadata/variable_definitions/_generated/vardef_client/rest.py +249 -0
  78. dapla_metadata/variable_definitions/_utils/__init__.py +1 -0
  79. dapla_metadata/variable_definitions/_utils/_client.py +32 -0
  80. dapla_metadata/variable_definitions/_utils/config.py +54 -0
  81. dapla_metadata/variable_definitions/_utils/constants.py +80 -0
  82. dapla_metadata/variable_definitions/_utils/files.py +309 -0
  83. dapla_metadata/variable_definitions/_utils/template_files.py +99 -0
  84. dapla_metadata/variable_definitions/_utils/variable_definition_files.py +143 -0
  85. dapla_metadata/variable_definitions/exceptions.py +255 -0
  86. dapla_metadata/variable_definitions/vardef.py +372 -0
  87. dapla_metadata/variable_definitions/vardok_id.py +48 -0
  88. dapla_metadata/variable_definitions/vardok_vardef_id_pair.py +47 -0
  89. dapla_metadata/variable_definitions/variable_definition.py +422 -0
  90. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/METADATA +34 -36
  91. dapla_toolbelt_metadata-0.9.11.dist-info/RECORD +97 -0
  92. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info}/WHEEL +1 -1
  93. dapla_metadata/datasets/config.py +0 -80
  94. dapla_metadata/datasets/model_backwards_compatibility.py +0 -520
  95. dapla_metadata/datasets/user_info.py +0 -88
  96. dapla_toolbelt_metadata-0.2.1.dist-info/RECORD +0 -22
  97. {dapla_toolbelt_metadata-0.2.1.dist-info → dapla_toolbelt_metadata-0.9.11.dist-info/licenses}/LICENSE +0 -0
@@ -0,0 +1,81 @@
1
+ """Internal Variable Definitions Administration API
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
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Any
18
+ from typing import ClassVar
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import ConfigDict
22
+ from pydantic import StrictStr
23
+ from typing_extensions import Self
24
+
25
+
26
+ class VardokIdResponse(BaseModel):
27
+ """VardokIdResponse"""
28
+
29
+ vardok_id: StrictStr
30
+ __properties: ClassVar[list[str]] = ["vardok_id"]
31
+
32
+ model_config = ConfigDict(
33
+ populate_by_name=True,
34
+ validate_assignment=True,
35
+ protected_namespaces=(),
36
+ )
37
+
38
+ def to_str(self) -> str:
39
+ """Returns the string representation of the model using alias"""
40
+ return pprint.pformat(self.model_dump(by_alias=True))
41
+
42
+ def to_json(self) -> str:
43
+ """Returns the JSON representation of the model using alias"""
44
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
45
+ return json.dumps(self.to_dict())
46
+
47
+ @classmethod
48
+ def from_json(cls, json_str: str) -> Self | None:
49
+ """Create an instance of VardokIdResponse from a JSON string"""
50
+ return cls.from_dict(json.loads(json_str))
51
+
52
+ def to_dict(self) -> dict[str, Any]:
53
+ """Return the dictionary representation of the model using alias.
54
+
55
+ This has the following differences from calling pydantic's
56
+ `self.model_dump(by_alias=True)`:
57
+
58
+ * `None` is only added to the output dict for nullable fields that
59
+ were set at model initialization. Other fields with value `None`
60
+ are ignored.
61
+ """
62
+ excluded_fields: set[str] = set([])
63
+
64
+ _dict = self.model_dump(
65
+ by_alias=True,
66
+ exclude=excluded_fields,
67
+ exclude_none=True,
68
+ )
69
+ return _dict
70
+
71
+ @classmethod
72
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
73
+ """Create an instance of VardokIdResponse from a dict"""
74
+ if obj is None:
75
+ return None
76
+
77
+ if not isinstance(obj, dict):
78
+ return cls.model_validate(obj)
79
+
80
+ _obj = cls.model_validate({"vardok_id": obj.get("vardok_id")})
81
+ return _obj
@@ -0,0 +1,84 @@
1
+ """Internal Variable Definitions Administration API
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
+ from __future__ import annotations
13
+
14
+ import json
15
+ import pprint
16
+ import re # noqa: F401
17
+ from typing import Any
18
+ from typing import ClassVar
19
+
20
+ from pydantic import BaseModel
21
+ from pydantic import ConfigDict
22
+ from pydantic import StrictStr
23
+ from typing_extensions import Self
24
+
25
+
26
+ class VardokVardefIdPairResponse(BaseModel):
27
+ """VardokVardefIdPairResponse"""
28
+
29
+ vardok_id: StrictStr
30
+ vardef_id: StrictStr
31
+ __properties: ClassVar[list[str]] = ["vardok_id", "vardef_id"]
32
+
33
+ model_config = ConfigDict(
34
+ populate_by_name=True,
35
+ validate_assignment=True,
36
+ protected_namespaces=(),
37
+ )
38
+
39
+ def to_str(self) -> str:
40
+ """Returns the string representation of the model using alias"""
41
+ return pprint.pformat(self.model_dump(by_alias=True))
42
+
43
+ def to_json(self) -> str:
44
+ """Returns the JSON representation of the model using alias"""
45
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
46
+ return json.dumps(self.to_dict())
47
+
48
+ @classmethod
49
+ def from_json(cls, json_str: str) -> Self | None:
50
+ """Create an instance of VardokVardefIdPairResponse from a JSON string"""
51
+ return cls.from_dict(json.loads(json_str))
52
+
53
+ def to_dict(self) -> dict[str, Any]:
54
+ """Return the dictionary representation of the model using alias.
55
+
56
+ This has the following differences from calling pydantic's
57
+ `self.model_dump(by_alias=True)`:
58
+
59
+ * `None` is only added to the output dict for nullable fields that
60
+ were set at model initialization. Other fields with value `None`
61
+ are ignored.
62
+ """
63
+ excluded_fields: set[str] = set([])
64
+
65
+ _dict = self.model_dump(
66
+ by_alias=True,
67
+ exclude=excluded_fields,
68
+ exclude_none=True,
69
+ )
70
+ return _dict
71
+
72
+ @classmethod
73
+ def from_dict(cls, obj: dict[str, Any] | None) -> Self | None:
74
+ """Create an instance of VardokVardefIdPairResponse from a dict"""
75
+ if obj is None:
76
+ return None
77
+
78
+ if not isinstance(obj, dict):
79
+ return cls.model_validate(obj)
80
+
81
+ _obj = cls.model_validate(
82
+ {"vardok_id": obj.get("vardok_id"), "vardef_id": obj.get("vardef_id")}
83
+ )
84
+ return _obj
@@ -0,0 +1,33 @@
1
+ """Internal Variable Definitions Administration API
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
+ from __future__ import annotations
13
+
14
+ import json
15
+ from enum import Enum
16
+
17
+ from typing_extensions import Self
18
+
19
+
20
+ class VariableStatus(str, Enum):
21
+ """Life cycle status of a variable definition."""
22
+
23
+ """
24
+ allowed enum values
25
+ """
26
+ DRAFT = "DRAFT"
27
+ PUBLISHED_INTERNAL = "PUBLISHED_INTERNAL"
28
+ PUBLISHED_EXTERNAL = "PUBLISHED_EXTERNAL"
29
+
30
+ @classmethod
31
+ def from_json(cls, json_str: str) -> Self:
32
+ """Create an instance of VariableStatus from a JSON string"""
33
+ return cls(json.loads(json_str))
@@ -0,0 +1,249 @@
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 io
13
+ import json
14
+ import re
15
+ import ssl
16
+
17
+ import urllib3
18
+
19
+ from .exceptions import ApiException
20
+ from .exceptions import ApiValueError
21
+
22
+ SUPPORTED_SOCKS_PROXIES = {"socks5", "socks5h", "socks4", "socks4a"}
23
+ RESTResponseType = urllib3.HTTPResponse
24
+
25
+
26
+ def is_socks_proxy_url(url):
27
+ if url is None:
28
+ return False
29
+ split_section = url.split("://")
30
+ if len(split_section) < 2:
31
+ return False
32
+ return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES
33
+
34
+
35
+ class RESTResponse(io.IOBase):
36
+ def __init__(self, resp) -> None:
37
+ self.response = resp
38
+ self.status = resp.status
39
+ self.reason = resp.reason
40
+ self.data = None
41
+
42
+ def read(self):
43
+ if self.data is None:
44
+ self.data = self.response.data
45
+ return self.data
46
+
47
+ def getheaders(self):
48
+ """Returns a dictionary of the response headers."""
49
+ return self.response.headers
50
+
51
+ def getheader(self, name, default=None):
52
+ """Returns a given response header."""
53
+ return self.response.headers.get(name, default)
54
+
55
+
56
+ class RESTClientObject:
57
+ def __init__(self, configuration) -> None:
58
+ # urllib3.PoolManager will pass all kw parameters to connectionpool
59
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75
60
+ # https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680
61
+ # Custom SSL certificates and client certificates: http://urllib3.readthedocs.io/en/latest/advanced-usage.html
62
+
63
+ # cert_reqs
64
+ if configuration.verify_ssl:
65
+ cert_reqs = ssl.CERT_REQUIRED
66
+ else:
67
+ cert_reqs = ssl.CERT_NONE
68
+
69
+ pool_args = {
70
+ "cert_reqs": cert_reqs,
71
+ "ca_certs": configuration.ssl_ca_cert,
72
+ "cert_file": configuration.cert_file,
73
+ "key_file": configuration.key_file,
74
+ }
75
+ if configuration.assert_hostname is not None:
76
+ pool_args["assert_hostname"] = configuration.assert_hostname
77
+
78
+ if configuration.retries is not None:
79
+ pool_args["retries"] = configuration.retries
80
+
81
+ if configuration.tls_server_name:
82
+ pool_args["server_hostname"] = configuration.tls_server_name
83
+
84
+ if configuration.socket_options is not None:
85
+ pool_args["socket_options"] = configuration.socket_options
86
+
87
+ if configuration.connection_pool_maxsize is not None:
88
+ pool_args["maxsize"] = configuration.connection_pool_maxsize
89
+
90
+ # https pool manager
91
+ self.pool_manager: urllib3.PoolManager
92
+
93
+ if configuration.proxy:
94
+ if is_socks_proxy_url(configuration.proxy):
95
+ from urllib3.contrib.socks import SOCKSProxyManager
96
+
97
+ pool_args["proxy_url"] = configuration.proxy
98
+ pool_args["headers"] = configuration.proxy_headers
99
+ self.pool_manager = SOCKSProxyManager(**pool_args)
100
+ else:
101
+ pool_args["proxy_url"] = configuration.proxy
102
+ pool_args["proxy_headers"] = configuration.proxy_headers
103
+ self.pool_manager = urllib3.ProxyManager(**pool_args)
104
+ else:
105
+ self.pool_manager = urllib3.PoolManager(**pool_args)
106
+
107
+ def request(
108
+ self,
109
+ method,
110
+ url,
111
+ headers=None,
112
+ body=None,
113
+ post_params=None,
114
+ _request_timeout=None,
115
+ ):
116
+ """Perform requests.
117
+
118
+ :param method: http request method
119
+ :param url: http request url
120
+ :param headers: http request headers
121
+ :param body: request json body, for `application/json`
122
+ :param post_params: request post parameters,
123
+ `application/x-www-form-urlencoded`
124
+ and `multipart/form-data`
125
+ :param _request_timeout: timeout setting for this request. If one
126
+ number provided, it will be total request
127
+ timeout. It can also be a pair (tuple) of
128
+ (connection, read) timeouts.
129
+ """
130
+ method = method.upper()
131
+ assert method in [
132
+ "GET",
133
+ "HEAD",
134
+ "DELETE",
135
+ "POST",
136
+ "PUT",
137
+ "PATCH",
138
+ "OPTIONS",
139
+ ]
140
+
141
+ if post_params and body:
142
+ raise ApiValueError(
143
+ "body parameter cannot be used with post_params parameter.",
144
+ )
145
+
146
+ post_params = post_params or {}
147
+ headers = headers or {}
148
+
149
+ timeout = None
150
+ if _request_timeout:
151
+ if isinstance(_request_timeout, (int, float)):
152
+ timeout = urllib3.Timeout(total=_request_timeout)
153
+ elif isinstance(_request_timeout, tuple) and len(_request_timeout) == 2:
154
+ timeout = urllib3.Timeout(
155
+ connect=_request_timeout[0],
156
+ read=_request_timeout[1],
157
+ )
158
+
159
+ try:
160
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
161
+ if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
162
+ # no content type provided or payload is json
163
+ content_type = headers.get("Content-Type")
164
+ if not content_type or re.search("json", content_type, re.IGNORECASE):
165
+ request_body = None
166
+ if body is not None:
167
+ request_body = json.dumps(body)
168
+ r = self.pool_manager.request(
169
+ method,
170
+ url,
171
+ body=request_body,
172
+ timeout=timeout,
173
+ headers=headers,
174
+ preload_content=False,
175
+ )
176
+ elif content_type == "application/x-www-form-urlencoded":
177
+ r = self.pool_manager.request(
178
+ method,
179
+ url,
180
+ fields=post_params,
181
+ encode_multipart=False,
182
+ timeout=timeout,
183
+ headers=headers,
184
+ preload_content=False,
185
+ )
186
+ elif content_type == "multipart/form-data":
187
+ # must del headers['Content-Type'], or the correct
188
+ # Content-Type which generated by urllib3 will be
189
+ # overwritten.
190
+ del headers["Content-Type"]
191
+ # Ensures that dict objects are serialized
192
+ post_params = [
193
+ (a, json.dumps(b)) if isinstance(b, dict) else (a, b)
194
+ for a, b in post_params
195
+ ]
196
+ r = self.pool_manager.request(
197
+ method,
198
+ url,
199
+ fields=post_params,
200
+ encode_multipart=True,
201
+ timeout=timeout,
202
+ headers=headers,
203
+ preload_content=False,
204
+ )
205
+ # Pass a `string` parameter directly in the body to support
206
+ # other content types than JSON when `body` argument is
207
+ # provided in serialized form.
208
+ elif isinstance(body, str) or isinstance(body, bytes):
209
+ r = self.pool_manager.request(
210
+ method,
211
+ url,
212
+ body=body,
213
+ timeout=timeout,
214
+ headers=headers,
215
+ preload_content=False,
216
+ )
217
+ elif headers["Content-Type"].startswith("text/") and isinstance(
218
+ body, bool
219
+ ):
220
+ request_body = "true" if body else "false"
221
+ r = self.pool_manager.request(
222
+ method,
223
+ url,
224
+ body=request_body,
225
+ preload_content=False,
226
+ timeout=timeout,
227
+ headers=headers,
228
+ )
229
+ else:
230
+ # Cannot generate the request from given parameters
231
+ msg = """Cannot prepare a request message for provided
232
+ arguments. Please check that your arguments match
233
+ declared content type."""
234
+ raise ApiException(status=0, reason=msg)
235
+ # For `GET`, `HEAD`
236
+ else:
237
+ r = self.pool_manager.request(
238
+ method,
239
+ url,
240
+ fields={},
241
+ timeout=timeout,
242
+ headers=headers,
243
+ preload_content=False,
244
+ )
245
+ except urllib3.exceptions.SSLError as e:
246
+ msg = "\n".join([type(e).__name__, str(e)])
247
+ raise ApiException(status=0, reason=msg)
248
+
249
+ return RESTResponse(r)
@@ -0,0 +1 @@
1
+ """Util methods for variable definitions."""
@@ -0,0 +1,32 @@
1
+ from dapla_metadata.variable_definitions._generated.vardef_client.api_client import (
2
+ ApiClient,
3
+ )
4
+ from dapla_metadata.variable_definitions._generated.vardef_client.configuration import (
5
+ Configuration,
6
+ )
7
+ from dapla_metadata.variable_definitions._utils.config import (
8
+ get_vardef_client_configuration,
9
+ )
10
+
11
+
12
+ class VardefClient:
13
+ _client: ApiClient | None = None
14
+ _config: Configuration | None = None
15
+
16
+ @classmethod
17
+ def get_config(cls) -> Configuration | None:
18
+ """Get the client configuration object."""
19
+ return cls._config
20
+
21
+ @classmethod
22
+ def set_config(cls, config: Configuration) -> None:
23
+ """Set the client configuration object."""
24
+ cls._config = config
25
+
26
+ @classmethod
27
+ def get_client(cls) -> ApiClient:
28
+ if not cls._client:
29
+ if not cls._config:
30
+ cls._config = get_vardef_client_configuration()
31
+ cls._client = ApiClient(cls._config)
32
+ return cls._client
@@ -0,0 +1,54 @@
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_PROD = "https://metadata.intern.ssb.no"
11
+ VARDEF_HOST_TEST = "https://metadata.intern.test.ssb.no"
12
+ WORKSPACE_DIR = "WORKSPACE_DIR"
13
+
14
+
15
+ def get_workspace_dir() -> str | None:
16
+ """Get the path to work directory from workspace environment variable."""
17
+ return get_config_item(WORKSPACE_DIR)
18
+
19
+
20
+ def get_active_group() -> str:
21
+ """Get the group the user currently represents.
22
+
23
+ Returns:
24
+ A string with the active group.
25
+ """
26
+ return str(get_dapla_group_context(raising=True))
27
+
28
+
29
+ def get_vardef_host() -> str:
30
+ """Get the host for the server to make requests to.
31
+
32
+ Based on standard Dapla platform environment variables, or variables specific
33
+ to Vardef if these are not available.
34
+
35
+ Raises:
36
+ NotImplementedError: When Vardef is not available for the current environment.
37
+ """
38
+ match get_dapla_environment():
39
+ case DaplaEnvironment.PROD:
40
+ return VARDEF_HOST_PROD
41
+ case DaplaEnvironment.TEST:
42
+ return VARDEF_HOST_TEST
43
+ case DaplaEnvironment.DEV:
44
+ return VARDEF_HOST_TEST
45
+ case _:
46
+ return get_config_item("VARDEF_HOST") or "http://localhost:8080"
47
+
48
+
49
+ def get_vardef_client_configuration() -> Configuration:
50
+ """Build a config to be supplied to the `ApiClient`."""
51
+ return Configuration(
52
+ host=get_vardef_host(),
53
+ access_token=get_oidc_token(raising=True),
54
+ )
@@ -0,0 +1,80 @@
1
+ """Constants for variable definitions."""
2
+
3
+ from datetime import date
4
+
5
+ from dapla_metadata.variable_definitions._generated.vardef_client.models.contact import (
6
+ Contact,
7
+ )
8
+ from dapla_metadata.variable_definitions._generated.vardef_client.models.language_string_type import (
9
+ LanguageStringType,
10
+ )
11
+
12
+ VARIABLE_DEFINITIONS_DIR = "variable_definitions"
13
+
14
+ VARIABLE_STATUS_FIELD_NAME = "variable_status"
15
+ OWNER_FIELD_NAME = "owner"
16
+
17
+ TEMPLATE_HEADER = "--- Variabeldefinisjon mal ---\n"
18
+ HEADER = "--- Variabeldefinisjon ---\n"
19
+
20
+ TEMPLATE_SECTION_HEADER_STATUS = "\n--- Statusfelt. Verdi 'DRAFT' før publisering. Ikke rediger hvis du oppretter en ny variabeldefinisjon. ---\n"
21
+ TEMPLATE_SECTION_HEADER_OWNER = "\n--- Eierteam og grupper. Ikke rediger hvis du oppretter en ny variabeldefinisjon, verdien genereres ---\n"
22
+ TEMPLATE_SECTION_HEADER_MACHINE_GENERATED = (
23
+ "\n--- Maskin-genererte felt. Ikke rediger. ---\n"
24
+ )
25
+
26
+ TEMPLATE_HEADER_EN = "--- Variable definition template ---\n"
27
+ HEADER_EN = "--- Variable definition ---\n"
28
+ TEMPLATE_SECTION_HEADER_STATUS_EN = "\n--- Status field. Value 'DRAFT' before publishing. Do not edit if creating new variable defintion ---\n"
29
+ TEMPLATE_SECTION_HEADER_OWNER_EN = "\n--- Owner team and groups. Do not edit if creating new variable defintion, value is generated ---\n"
30
+ TEMPLATE_SECTION_HEADER_MACHINE_GENERATED_EN = (
31
+ "\n--- Machine generated fields. Do not edit ---\n"
32
+ )
33
+
34
+ DEFAULT_DATE = date(1000, 1, 1)
35
+
36
+ GENERATED_CONTACT = Contact(
37
+ title=LanguageStringType(
38
+ nb="generert tittel",
39
+ ),
40
+ email="generert@ssb.no",
41
+ )
42
+
43
+ MACHINE_GENERATED_FIELDS = [
44
+ "id",
45
+ "patch_id",
46
+ "created_at",
47
+ "created_by",
48
+ "last_updated_at",
49
+ "last_updated_by",
50
+ ]
51
+
52
+ OPTIONAL_FIELD = "~ Valgfritt felt ~"
53
+ REQUIRED_FIELD = "! Obligatorisk felt !"
54
+
55
+ YAML_STR_TAG = "tag:yaml.org,2002:str"
56
+
57
+ BLOCK_FIELDS = [
58
+ "definition",
59
+ "name",
60
+ "contact.title",
61
+ "comment",
62
+ ]
63
+
64
+ DOUBLE_QUOTE_FIELDS = [
65
+ "unit_types",
66
+ "subject_fields",
67
+ "related_variable_definition_uris",
68
+ "owner",
69
+ "short_name",
70
+ "classification_reference",
71
+ "measurement_type",
72
+ "external_reference_uri",
73
+ "created_by",
74
+ "id",
75
+ "last_updated_by",
76
+ ]
77
+
78
+ PUBLISHING_BLOCKED_ERROR_MESSAGE = "Publishing blocked: Publishing variable definitions is not allowed until further notice."
79
+ VARDEF_PROD_URL = "https://metadata.intern.ssb.no"
80
+ VARDEF_TEST_URL = "https://metadata.intern.test.ssb.no"