Skip to content

Commit

Permalink
-
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre Delaunay committed Jul 18, 2023
1 parent ff608e6 commit 1a5a615
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
23 changes: 23 additions & 0 deletions sarc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions tests/functional/ldap/test_acquire_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 3 additions & 1 deletion tests/sarc-test.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1a5a615

Please sign in to comment.