Skip to content

Commit

Permalink
Allow loader to load policies from other paths
Browse files Browse the repository at this point in the history
Sequence is as follows:

1. Path from app_list
2. 'policies' folder inside loaded app
3. Built-in policies from inuits_policy_based_auth
  • Loading branch information
gverm committed Oct 23, 2023
1 parent 3c66e46 commit c84b24a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Empty file added src/__init__.py
Empty file.
19 changes: 13 additions & 6 deletions src/elody/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,19 @@ def load_queues(logger):


def __get_class(app, auth_type, policy_module_name):
try:
module = import_module(f"apps.{app}.policies.{auth_type}.{policy_module_name}")
except:
module = import_module(
f"inuits_policy_based_auth.{auth_type}.policies.{policy_module_name}"
)
locations = [
policy_module_name,
f"apps.{app}.policies.{auth_type}.{policy_module_name}",
f"inuits_policy_based_auth.{auth_type}.policies.{policy_module_name}",
]
for location in locations:
try:
module = import_module(location)
break
except ModuleNotFoundError:
pass
else:
raise ModuleNotFoundError(f"Policy {policy_module_name} not found")
policy_class_name = module.__name__.split(".")[-1].title().replace("_", "")
policy = getattr(module, policy_class_name)
return policy
Expand Down

0 comments on commit c84b24a

Please sign in to comment.