dcicutils 8.7.1.1b7__py3-none-any.whl → 8.7.1.1b9__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- dcicutils/portal_utils.py +16 -11
- {dcicutils-8.7.1.1b7.dist-info → dcicutils-8.7.1.1b9.dist-info}/METADATA +1 -1
- {dcicutils-8.7.1.1b7.dist-info → dcicutils-8.7.1.1b9.dist-info}/RECORD +6 -6
- {dcicutils-8.7.1.1b7.dist-info → dcicutils-8.7.1.1b9.dist-info}/LICENSE.txt +0 -0
- {dcicutils-8.7.1.1b7.dist-info → dcicutils-8.7.1.1b9.dist-info}/WHEEL +0 -0
- {dcicutils-8.7.1.1b7.dist-info → dcicutils-8.7.1.1b9.dist-info}/entry_points.txt +0 -0
dcicutils/portal_utils.py
CHANGED
@@ -15,7 +15,7 @@ from typing import Callable, Dict, List, Optional, Tuple, Type, Union
|
|
15
15
|
from uuid import uuid4 as uuid
|
16
16
|
from webtest.app import TestApp, TestResponse
|
17
17
|
from wsgiref.simple_server import make_server as wsgi_make_server
|
18
|
-
from dcicutils.common import OrchestratedApp, ORCHESTRATED_APPS
|
18
|
+
from dcicutils.common import APP_SMAHT, OrchestratedApp, ORCHESTRATED_APPS
|
19
19
|
from dcicutils.ff_utils import get_metadata, get_schema, patch_metadata, post_metadata
|
20
20
|
from dcicutils.misc_utils import to_camel_case, VirtualApp
|
21
21
|
from dcicutils.tmpfile_utils import temporary_file
|
@@ -42,6 +42,7 @@ class Portal:
|
|
42
42
|
or a dcicutils.misc_utils.VirtualApp, or even a pyramid.router.Router.
|
43
43
|
8. From another Portal object (i.e. copy constructor).
|
44
44
|
"""
|
45
|
+
DEFAULT_APP = APP_SMAHT
|
45
46
|
KEYS_FILE_DIRECTORY = "~"
|
46
47
|
MIME_TYPE_JSON = "application/json"
|
47
48
|
|
@@ -60,7 +61,7 @@ class Portal:
|
|
60
61
|
self._vapp = None
|
61
62
|
for arg in unspecified:
|
62
63
|
if arg is not None:
|
63
|
-
raise Exception("Portal
|
64
|
+
raise Exception("Portal initialization error; extraneous arguments.")
|
64
65
|
|
65
66
|
def init_from_portal(portal: Portal, unspecified: Optional[list] = None) -> None:
|
66
67
|
init(unspecified=unspecified)
|
@@ -93,13 +94,13 @@ class Portal:
|
|
93
94
|
raise Exception(f"Portal server inconsistency: {server} vs {key_server}")
|
94
95
|
self._key["server"] = self._server = server
|
95
96
|
if not self._key:
|
96
|
-
raise Exception("Portal
|
97
|
+
raise Exception("Portal initialization error; from key.")
|
97
98
|
|
98
99
|
def init_from_key_pair(key_pair: tuple, server: Optional[str], unspecified: Optional[list] = []) -> None:
|
99
100
|
if len(key_pair) >= 2:
|
100
101
|
init_from_key({"key": key_pair[0], "secret": key_pair[1]}, server, unspecified=unspecified)
|
101
102
|
else:
|
102
|
-
raise Exception("Portal
|
103
|
+
raise Exception("Portal initialization error; from key-pair.")
|
103
104
|
|
104
105
|
def init_from_keys_file(keys_file: str, env: Optional[str], server: Optional[str],
|
105
106
|
unspecified: Optional[list] = []) -> None:
|
@@ -107,7 +108,7 @@ class Portal:
|
|
107
108
|
with io.open(keys_file := os.path.expanduser(keys_file)) as f:
|
108
109
|
keys = json.load(f)
|
109
110
|
except Exception:
|
110
|
-
raise Exception(f"Portal
|
111
|
+
raise Exception(f"Portal initialization error; cannot open keys-file: {keys_file}")
|
111
112
|
if isinstance(env, str) and env and isinstance(key := keys.get(env), dict):
|
112
113
|
init_from_key(key, server)
|
113
114
|
self._keys_file = keys_file
|
@@ -121,7 +122,8 @@ class Portal:
|
|
121
122
|
self._keys_file = keys_file
|
122
123
|
self._env = env
|
123
124
|
else:
|
124
|
-
raise Exception(f"Portal
|
125
|
+
raise Exception(f"Portal initialization error;"
|
126
|
+
f" {env or server or None} not found in keys-file: {keys_file}")
|
125
127
|
|
126
128
|
def init_from_env_server_app(env: str, server: str, app: Optional[str],
|
127
129
|
unspecified: Optional[list] = None) -> None:
|
@@ -146,7 +148,7 @@ class Portal:
|
|
146
148
|
return prefix + server if server else None
|
147
149
|
|
148
150
|
if (valid_app := app) and not (valid_app := Portal._valid_app(app)):
|
149
|
-
raise Exception(f"Portal
|
151
|
+
raise Exception(f"Portal initialization error; invalid app: {app}")
|
150
152
|
self._app = valid_app
|
151
153
|
if isinstance(arg, Portal):
|
152
154
|
init_from_portal(arg, unspecified=[env, server, app])
|
@@ -164,12 +166,15 @@ class Portal:
|
|
164
166
|
init_from_env_server_app(arg, server, app, unspecified=[env])
|
165
167
|
elif (isinstance(env, str) and env) or (isinstance(server, str) and server):
|
166
168
|
init_from_env_server_app(env, server, app, unspecified=[arg])
|
169
|
+
elif not arg and (keys_file := self._default_keys_file(app=self._app or Portal.DEFAULT_APP, env=env)):
|
170
|
+
# If no initial arg then look for default app keys file.
|
171
|
+
init_from_keys_file(keys_file, env, server)
|
167
172
|
elif raise_exception:
|
168
|
-
raise Exception("Portal
|
173
|
+
raise Exception("Portal initialization error; insufficient arguments.")
|
169
174
|
else:
|
170
175
|
init()
|
171
176
|
if not self.vapp and not self.key and raise_exception:
|
172
|
-
raise Exception("Portal
|
177
|
+
raise Exception("Portal initialization error; neither key nor vapp defined.")
|
173
178
|
|
174
179
|
@property
|
175
180
|
def ini_file(self) -> Optional[str]:
|
@@ -443,7 +448,7 @@ class Portal:
|
|
443
448
|
if isinstance(arg, list) or isinstance(arg, dict) or isinstance(arg, Callable):
|
444
449
|
return Portal(Portal._create_router_for_testing(arg))
|
445
450
|
elif isinstance(arg, str) and arg.endswith(".ini"):
|
446
|
-
return Portal(
|
451
|
+
return Portal(arg)
|
447
452
|
elif arg == "local" or arg is True:
|
448
453
|
minimal_ini_for_testing = "\n".join([
|
449
454
|
"[app:app]\nuse = egg:encoded\nfile_upload_bucket = dummy",
|
@@ -467,7 +472,7 @@ class Portal:
|
|
467
472
|
else:
|
468
473
|
minimal_ini_for_testing = "[app:app]\nuse = egg:encoded\nsqlalchemy.url = postgresql://dummy\n"
|
469
474
|
with temporary_file(content=minimal_ini_for_testing, suffix=".ini") as ini_file:
|
470
|
-
return Portal(
|
475
|
+
return Portal(ini_file)
|
471
476
|
|
472
477
|
@staticmethod
|
473
478
|
def _create_vapp(arg: Union[TestApp, VirtualApp, PyramidRouter, str] = None) -> TestApp:
|
@@ -45,7 +45,7 @@ dcicutils/misc_utils.py,sha256=9JqdVjHLkZUDTryngF3Dbu0m7XcbitbR7izWnxUSWc4,10195
|
|
45
45
|
dcicutils/obfuscation_utils.py,sha256=fo2jOmDRC6xWpYX49u80bVNisqRRoPskFNX3ymFAmjw,5963
|
46
46
|
dcicutils/opensearch_utils.py,sha256=V2exmFYW8Xl2_pGFixF4I2Cc549Opwe4PhFi5twC0M8,1017
|
47
47
|
dcicutils/portal_object_utils.py,sha256=KsOvrC2LM3OFX8GoHkqdO88td79v_Xvj1gVptZ5IiK4,12252
|
48
|
-
dcicutils/portal_utils.py,sha256=
|
48
|
+
dcicutils/portal_utils.py,sha256=VLTofvk9z5wAQg4PZUi9GmvMCcAeYAX1R3qU1H3CNjw,27065
|
49
49
|
dcicutils/project_utils.py,sha256=qPdCaFmWUVBJw4rw342iUytwdQC0P-XKpK4mhyIulMM,31250
|
50
50
|
dcicutils/qa_checkers.py,sha256=cdXjeL0jCDFDLT8VR8Px78aS10hwNISOO5G_Zv2TZ6M,20534
|
51
51
|
dcicutils/qa_utils.py,sha256=TT0SiJWiuxYvbsIyhK9VO4uV_suxhB6CpuC4qPacCzQ,160208
|
@@ -66,8 +66,8 @@ dcicutils/trace_utils.py,sha256=g8kwV4ebEy5kXW6oOrEAUsurBcCROvwtZqz9fczsGRE,1769
|
|
66
66
|
dcicutils/validation_utils.py,sha256=cMZIU2cY98FYtzK52z5WUYck7urH6JcqOuz9jkXpqzg,14797
|
67
67
|
dcicutils/variant_utils.py,sha256=2H9azNx3xAj-MySg-uZ2SFqbWs4kZvf61JnK6b-h4Qw,4343
|
68
68
|
dcicutils/zip_utils.py,sha256=rnjNv_k6L9jT2SjDSgVXp4BEJYLtz9XN6Cl2Fy-tqnM,2027
|
69
|
-
dcicutils-8.7.1.
|
70
|
-
dcicutils-8.7.1.
|
71
|
-
dcicutils-8.7.1.
|
72
|
-
dcicutils-8.7.1.
|
73
|
-
dcicutils-8.7.1.
|
69
|
+
dcicutils-8.7.1.1b9.dist-info/LICENSE.txt,sha256=qnwSmfnEWMl5l78VPDEzAmEbLVrRqQvfUQiHT0ehrOo,1102
|
70
|
+
dcicutils-8.7.1.1b9.dist-info/METADATA,sha256=6NZZJZyyO_0mZfDU0xU948JwXitVSbKiup22bPx6be8,3314
|
71
|
+
dcicutils-8.7.1.1b9.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
72
|
+
dcicutils-8.7.1.1b9.dist-info/entry_points.txt,sha256=8wbw5csMIgBXhkwfgsgJeuFcoUc0WsucUxmOyml2aoA,209
|
73
|
+
dcicutils-8.7.1.1b9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|