Some checks failed
Ruff / Code linting (pull_request) Failing after 42s
Codespell / Check for spelling errors (push) Successful in 43s
Codespell / Check for spelling errors (pull_request) Successful in 43s
Ruff / Code linting (push) Failing after 43s
Type annotation (PR) / check (pull_request) Failing after 1m6s
Test execution / Test-all (push) Successful in 1m12s
217 lines
5.4 KiB
Python
217 lines
5.4 KiB
Python
import yaml
|
|
|
|
config_version_1 = """
|
|
type: collections
|
|
version: 1
|
|
|
|
collections:
|
|
penguins:
|
|
default_token: no_access
|
|
curated: penguins/curated
|
|
incoming: penguins/incoming-v1
|
|
backend:
|
|
type: sqlite
|
|
schema: https://concepts.datalad.org/s/flat-study/unreleased.yaml
|
|
|
|
tokens:
|
|
no_access:
|
|
user_id: nobody
|
|
collections:
|
|
penguins:
|
|
mode: NOTHING
|
|
incoming_label: ''
|
|
|
|
token_1:
|
|
user_id: cristian
|
|
# The collections for which the token holds rights are defined in "collections"
|
|
collections:
|
|
penguins:
|
|
mode: WRITE_COLLECTION
|
|
incoming_label: 'cristian'
|
|
|
|
token_c:
|
|
user_id: curator
|
|
# The collections for which the token holds rights are defined in "collections"
|
|
collections:
|
|
penguins:
|
|
mode: CURATOR
|
|
incoming_label: 'curator'
|
|
"""
|
|
|
|
config_version_2_inlined_only_policy = """
|
|
pid: dump_things:config
|
|
version: 2
|
|
type: collections
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
curated: dfg-survey/2026/main/curated
|
|
default_policy: policy_1
|
|
default_token: noaccess
|
|
incoming: dfg-survey/2026/main/inboxes
|
|
policy_annotation_tag: abc
|
|
policy_mapping:
|
|
- auth_source: config
|
|
authorized_by:
|
|
- policy_1
|
|
- policy_2
|
|
- policy_3
|
|
user_id: cmo
|
|
- auth_source: trr379hub
|
|
authorized_by:
|
|
- policy_3
|
|
- policy_4
|
|
- policy_5
|
|
user_id: mih
|
|
schema: https://concepts.datalad.org/s/things/v2.yaml
|
|
tokens:
|
|
no_access:
|
|
user_id: nobody
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
mode: NOTHING
|
|
incoming_label: ''
|
|
admin_tokens: {}
|
|
"""
|
|
|
|
config_version_2_external_only_policy = """
|
|
pid: dump_things:config
|
|
version: 2
|
|
type: collections
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
audit_backends: []
|
|
auth_sources:
|
|
- instance_id: trr379hub
|
|
label_type: user
|
|
organization: dfg-survey
|
|
team: 2026-participants
|
|
type: forgejo
|
|
url: https://hub.trr379.de/api/v1
|
|
backend:
|
|
type: sqlite
|
|
curated: dfg-survey/2026/main/curated
|
|
policy_info_location: https://concepts.datalad.org/s/things/v2-policies.yaml
|
|
default_token: noaccess
|
|
ignore_classes: []
|
|
incoming: dfg-survey/2026/main/inboxes
|
|
schema: https://concepts.datalad.org/s/things/v2.yaml
|
|
submission_tags:
|
|
submission_time_tag: http://semanticscience.org/resource/SIO_001083
|
|
submitter_id_tag: http://purl.obolibrary.org/obo/NCIT_C54269
|
|
tokens:
|
|
no_access:
|
|
user_id: nobody
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
mode: NOTHING
|
|
incoming_label: ''
|
|
admin_tokens: {}
|
|
"""
|
|
|
|
config_version_2_inlined_and_external_policy = """
|
|
pid: dump_things:config
|
|
version: 2
|
|
type: collections
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
curated: dfg-survey/2026/main/curated
|
|
default_policy: policy_1
|
|
default_token: noaccess
|
|
ignore_classes: []
|
|
incoming: dfg-survey/2026/main/inboxes
|
|
policy_annotation_tag: abc
|
|
policy_mapping:
|
|
- auth_source: config
|
|
authorized_by:
|
|
- policy_1
|
|
- policy_2
|
|
- policy_3
|
|
user_id: cmo
|
|
- auth_source: trr379hub
|
|
authorized_by:
|
|
- policy_3
|
|
- policy_4
|
|
- policy_5
|
|
user_id: mih
|
|
policy_info_location: https://concepts.datalad.org/s/things/v2-policies.yaml
|
|
schema: https://concepts.datalad.org/s/things/v2.yaml
|
|
submission_tags:
|
|
submission_time_tag: http://semanticscience.org/resource/SIO_001083
|
|
submitter_id_tag: http://purl.obolibrary.org/obo/NCIT_C54269
|
|
tokens:
|
|
tokens:
|
|
no_access:
|
|
user_id: nobody
|
|
collections:
|
|
dfg-survey-2026-main:
|
|
mode: NOTHING
|
|
incoming_label: ''
|
|
admin_tokens: {}
|
|
"""
|
|
|
|
config_example_1 = """
|
|
admin_tokens: {}
|
|
collections:
|
|
collection-2026:
|
|
audit_backends: []
|
|
auth_sources:
|
|
- instance_id: cerebra
|
|
label_type: user
|
|
organization: collection-2026
|
|
repository: null
|
|
team: collection-2026-participants
|
|
type: forgejo
|
|
url: https://example.com/api/v1
|
|
- type: config
|
|
backend:
|
|
type: sqlite
|
|
curated: collection-2026/main/curated
|
|
default_token: noaccess
|
|
ignore_classes: []
|
|
incoming: collection-2026/main/inboxes
|
|
schema: https://www.example.com/s/things/v2.yaml
|
|
submission_tags:
|
|
submission_time_tag: http://semanticscience.org/resource/SIO_001083
|
|
submitter_id_tag: http://purl.obolibrary.org/obo/NCIT_C54269
|
|
use_classes: []
|
|
tokens:
|
|
john_doe:
|
|
collections:
|
|
collection-2026:
|
|
incoming_label: john_doe
|
|
mode: CURATOR
|
|
hashed: false
|
|
representation: abcdefg
|
|
user_id: john_doe
|
|
noaccess:
|
|
collections: {}
|
|
hashed: false
|
|
representation: abcdefg
|
|
user_id: noaccess
|
|
type: collections
|
|
version: 2
|
|
"""
|
|
|
|
|
|
all_configurations = [
|
|
config_version_1,
|
|
config_version_2_inlined_only_policy,
|
|
config_version_2_external_only_policy,
|
|
config_version_2_inlined_and_external_policy,
|
|
config_example_1,
|
|
]
|
|
|
|
|
|
# Check that old configurations can be read by the current Configuration class
|
|
def test_config_backward_compatibility():
|
|
from dump_things_service.abstract_config import Configuration
|
|
from dump_things_service.commands.upload_config import convert_config_1_to_config_2
|
|
|
|
for config_yaml in all_configurations:
|
|
config_dict = yaml.safe_load(config_yaml)
|
|
if config_dict['version'] == 1:
|
|
config_dict = convert_config_1_to_config_2(
|
|
config_dict,
|
|
None,
|
|
)
|
|
_ = Configuration(**config_dict)
|