-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: authz plugin dynamic import setup
- Loading branch information
1 parent
411f1d2
commit 877e741
Showing
7 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -167,3 +167,6 @@ cython_debug/ | |
|
||
# tds-db | ||
pg_data | ||
|
||
# TDS custom authz module | ||
lib/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from fastapi import Request | ||
from bento_lib.auth.middleware.fastapi import FastApiAuthMiddleware | ||
|
||
from transcriptomics_data_service.config import get_config | ||
from transcriptomics_data_service.logger import get_logger | ||
|
||
config = get_config() | ||
logger = get_logger(config) | ||
|
||
bento_authz = FastApiAuthMiddleware.build_from_pydantic_config(config, logger) | ||
|
||
async def get_current_user_authorization(req: Request): | ||
# TODO use as a propper middleware, or simply as an injectable with method calls? | ||
print("************ This middleware performs authz checks for Bento") | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from fastapi import Depends, Request | ||
|
||
async def get_current_user_authorization(request: Request): | ||
print("****************** This is a dynamically imported module function") | ||
return True |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import importlib.util | ||
import sys | ||
|
||
from fastapi import Depends, Request | ||
|
||
__all__ = ["get_request_authorization"] | ||
|
||
|
||
def import_module_from_path(path): | ||
spec = importlib.util.spec_from_file_location("authz_plugin", path) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
return module | ||
|
||
|
||
# TODO find a way to allow plugin writers to specify additional dependencies to be installed | ||
|
||
AUTHZ_MODULE_PATH = "/tds/lib/authz.module.py" | ||
authz_plugin = import_module_from_path(AUTHZ_MODULE_PATH) | ||
|
||
|
||
async def get_request_authorization(req: Request): | ||
return await authz_plugin.get_current_user_authorization(req) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters