172 lines
4.3 KiB
Python
172 lines
4.3 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: {}
|
|
"""
|
|
|
|
all_configurations = [
|
|
config_version_1,
|
|
config_version_2_inlined_only_policy,
|
|
config_version_2_external_only_policy,
|
|
config_version_2_inlined_and_external_policy,
|
|
]
|
|
|
|
|
|
# Check that old configurations can be read by the current Configuration class
|
|
def test_config_backward_compatiblity():
|
|
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)
|