From 1a5a615b3d24c2285879df4e6c63a1dc74b9774c Mon Sep 17 00:00:00 2001 From: Pierre Delaunay Date: Tue, 18 Jul 2023 11:41:26 -0400 Subject: [PATCH] - --- sarc/config.py | 23 ++++++++++++++++++++++ tests/functional/ldap/test_acquire_ldap.py | 1 + tests/sarc-test.json | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/sarc/config.py b/sarc/config.py index dec64091..28ca6f75 100644 --- a/sarc/config.py +++ b/sarc/config.py @@ -142,6 +142,14 @@ class LDAPConfig(BaseModel): group_to_prof_json_path: str = None exceptions_json_path: str = None + @validator("group_to_prof_json_path") + def _relative_group_to_prof(cls, value): + return relative_filepath(value) + + @validator("exceptions_json_path") + def _relative_exception(cls, value): + return relative_filepath(value) + class AccountMatchingConfig(BaseModel): drac_members_csv_path: Path @@ -174,8 +182,23 @@ def _complete_cluster_fields(cls, value, values): config_var = ContextVar("config", default=None) +_config_folder = None + + +def relative_filepath(path): + """Allows files to be relative to the config""" + global _config_folder + + if "$SELF" in path: + return path.replace("$SELF", str(_config_folder)) + + return path + + def parse_config(config_path): + global _config_folder config_path = Path(config_path) + _config_folder = str(config_path.parent) if not config_path.exists(): raise ConfigurationError( diff --git a/tests/functional/ldap/test_acquire_ldap.py b/tests/functional/ldap/test_acquire_ldap.py index fba1a973..f90ea4c0 100644 --- a/tests/functional/ldap/test_acquire_ldap.py +++ b/tests/functional/ldap/test_acquire_ldap.py @@ -127,6 +127,7 @@ def mock_file(filename, *vargs, **kwargs): print(i, js_user_d) for segment in ["drac_roles", "drac_members"]: assert segment in js_user_d + assert js_user_d[segment] is not None assert "email" in js_user_d[segment] assert js_user_d[segment]["email"] == f"js{i:03d}@yahoo.ca" assert "username" in js_user_d[segment] diff --git a/tests/sarc-test.json b/tests/sarc-test.json index f5ef64ec..77e43ebb 100644 --- a/tests/sarc-test.json +++ b/tests/sarc-test.json @@ -7,7 +7,9 @@ "local_private_key_file": "not_a_valid_path.key", "local_certificate_file": "not_a_valid_path.crt", "ldap_service_uri": "ldaps://ldap.google.com", - "mongo_collection_name": "users" + "mongo_collection_name": "users", + "group_to_prof_json_path": "$SELF/group_to_prof.json", + "exceptions_json_path": "$SELF/exceptions.json" }, "account_matching": { "drac_members_csv_path": "drac_members_not_valid_path.csv",