Skip to content

Commit

Permalink
portal_utils tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Dec 18, 2023
1 parent 3cc9bba commit f10e4ac
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,7 @@ def init_from_keys_file(keys_file: str, env: Optional[str], server: Optional[str

def init_from_env_server_app(env: str, server: str, app: Optional[str],
unspecified: Optional[list] = None) -> None:
return init_from_keys_file(default_keys_file(app, env), env, server, unspecified)

def default_keys_file(app: Optional[str], env: Optional[str] = None) -> Optional[str]:
def is_valid_app(app: Optional[str]) -> bool: # noqa
return app and app.lower() in [name.lower() for name in ORCHESTRATED_APPS]
def infer_app_from_env(env: str) -> Optional[str]: # noqa
if isinstance(env, str) and (lenv := env.lower()):
if app := [app for app in ORCHESTRATED_APPS if lenv.startswith(app.lower())]:
return app[0]
if is_valid_app(app) or (app := infer_app_from_env(env)):
return os.path.join(Portal.KEYS_FILE_DIRECTORY, f".{app.lower()}-keys.json")
return init_from_keys_file(self._default_keys_file(app, env), env, server, unspecified)

def normalize_server(server: str) -> Optional[str]:
prefix = ""
Expand Down Expand Up @@ -286,6 +276,16 @@ def ping(self) -> bool:
except Exception:
return False

def _default_keys_file(self, app: Optional[str], env: Optional[str] = None) -> Optional[str]:
def is_valid_app(app: Optional[str]) -> bool: # noqa
return app and app.lower() in [name.lower() for name in ORCHESTRATED_APPS]
def infer_app_from_env(env: str) -> Optional[str]: # noqa
if isinstance(env, str) and (lenv := env.lower()):
if app := [app for app in ORCHESTRATED_APPS if lenv.startswith(app.lower())]:
return app[0]
if is_valid_app(app) or (app := infer_app_from_env(env)):
return os.path.join(Portal.KEYS_FILE_DIRECTORY, f".{app.lower()}-keys.json")

def _uri(self, uri: str) -> str:
if not isinstance(uri, str) or not uri:
return "/"
Expand Down

0 comments on commit f10e4ac

Please sign in to comment.