Skip to content

Commit

Permalink
minor tweaks to portal_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
dmichaels-harvard committed Jan 7, 2024
1 parent 0abc046 commit 25d2bd5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions dcicutils/portal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ class Portal:
def __init__(self,
arg: Optional[Union[Portal, TestApp, VirtualApp, PyramidRouter, dict, tuple, str]] = None,
env: Optional[str] = None, server: Optional[str] = None,
app: Optional[OrchestratedApp] = None) -> None:
app: Optional[OrchestratedApp] = None,
raise_exception: bool = True) -> None:

def init(unspecified: Optional[list] = []) -> None:
self._ini_file = None
self._key = None
self._keys_file = None
self._env = None
self._server = None
self._app = None
self._vapp = None
for arg in unspecified:
if arg is not None:
Expand Down Expand Up @@ -96,7 +96,7 @@ def init_from_key(key: dict, server: Optional[str], unspecified: Optional[list]
raise Exception("Portal init error; from key.")

def init_from_key_pair(key_pair: tuple, server: Optional[str], unspecified: Optional[list] = []) -> None:
if len(key_pair) == 2:
if len(key_pair) >= 2:
init_from_key({"key": key_pair[0], "secret": key_pair[1]}, server, unspecified=unspecified)
else:
raise Exception("Portal init error; from key-pair.")
Expand Down Expand Up @@ -147,6 +147,7 @@ def normalize_server(server: str) -> Optional[str]:

if app and not (app := Portal._valid_app(app)):
raise Exception(f"Portal init error; invalid app: {app}")
self._app = app
if isinstance(arg, Portal):
init_from_portal(arg, unspecified=[env, server, app])
elif isinstance(arg, (TestApp, VirtualApp, PyramidRouter)):
Expand All @@ -163,10 +164,9 @@ def normalize_server(server: str) -> Optional[str]:
init_from_env_server_app(arg, server, app, unspecified=[env])
elif (isinstance(env, str) and env) or (isinstance(server, str) and server):
init_from_env_server_app(env, server, app, unspecified=[arg])
else:
elif raise_exception:
raise Exception("Portal init error; insufficient args.")
self._app = app
if not self.vapp and not self.key:
if not self.vapp and not self.key and raise_exception:
raise Exception("Portal init error; neither key nor vapp defined.")

@property
Expand Down Expand Up @@ -372,7 +372,7 @@ def _default_keys_file(self, app: Optional[str], env: Optional[str] = None) -> O
def infer_app_from_env(env: str) -> Optional[str]: # noqa
if isinstance(env, str) and (lowercase_env := env.lower()):
if app := [app for app in ORCHESTRATED_APPS if lowercase_env.startswith(app.lower())]:
return app[0]
return self._valid_app(app[0])
if (app := Portal._valid_app(app)) or (app := infer_app_from_env(env)):
keys_file = os.path.expanduser(os.path.join(Portal.KEYS_FILE_DIRECTORY, f".{app.lower()}-keys.json"))
return keys_file if os.path.exists(keys_file) else None
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dcicutils"
version = "8.7.0.1b16" # TODO: To become 8.7.1
version = "8.7.0.1b17" # TODO: To become 8.7.1
description = "Utility package for interacting with the 4DN Data Portal and other 4DN resources"
authors = ["4DN-DCIC Team <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 25d2bd5

Please sign in to comment.