seqslab-cli 3.3.7__tar.gz → 3.3.8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {seqslab-cli-3.3.7/python/seqslab_cli.egg-info → seqslab-cli-3.3.8}/PKG-INFO +1 -1
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/__init__.py +1 -1
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/auth/commands.py +54 -15
- seqslab-cli-3.3.8/python/seqslab/auth/utils.py +46 -0
- seqslab-cli-3.3.8/python/seqslab/organization/commands.py +117 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/commands.py +2 -3
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8/python/seqslab_cli.egg-info}/PKG-INFO +1 -1
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/SOURCES.txt +1 -0
- seqslab-cli-3.3.7/python/seqslab/organization/commands.py +0 -77
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/LICENSE +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/MANIFEST.in +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/README.md +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/auth/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/auth/azuread.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/cli.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/color.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/context.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/api/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/api/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/api/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/api/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/api/template.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/internal/aiocopy.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/internal/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/internal/utils.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/storage/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/storage/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/storage/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/utils/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/utils/atgxmetadata.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/utils/biomimetype.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/drs/utils/progressbar.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/exceptions.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/organization/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/organization/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/organization/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/plugin.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/internal/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/role/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/runsheet/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/runsheet/runsheet.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/sample_sheet/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/sample_sheet/_version.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/sample_sheet/util.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/internal/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/scr/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/session_logger.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/settings.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/statusbar.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/internal/utils.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/register/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/register/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/register/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/register/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/register/template.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/resource/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/template/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/template/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/trs/template/template.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/usage_logger.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/internal/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/user/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/internal/parameters.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/resource/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/template/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/template/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/wes/template/template.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/commands.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/internal/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/internal/common.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/resource/__init__.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/resource/azure.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab/workspace/resource/base.py +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/dependency_links.txt +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/entry_points.txt +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/requires.txt +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/top_level.txt +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/python/seqslab_cli.egg-info/zip-safe +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/requirements.txt +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/setup.cfg +0 -0
- {seqslab-cli-3.3.7 → seqslab-cli-3.3.8}/setup.py +0 -0
|
@@ -19,6 +19,7 @@ from requests import HTTPError, request
|
|
|
19
19
|
from seqslab import settings as api_settings
|
|
20
20
|
from seqslab.auth import __version__, aad_app, azuread
|
|
21
21
|
from seqslab.auth.azuread import API_HOSTNAME
|
|
22
|
+
from seqslab.auth.utils import get_org, request_wrap
|
|
22
23
|
from termcolor import cprint
|
|
23
24
|
|
|
24
25
|
"""
|
|
@@ -44,12 +45,10 @@ class BaseAuth:
|
|
|
44
45
|
AUTHORIZATION_URL = f"https://{API_HOSTNAME}/auth/{__version__}/signin/{{backend}}/"
|
|
45
46
|
ACCESS_TOKEN_URL = f"https://{API_HOSTNAME}/auth/{__version__}/token/{{backend}}/"
|
|
46
47
|
REFRESH_TOKEN_URL = f"https://{API_HOSTNAME}/auth/{__version__}/token/refresh/"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
response.raise_for_status()
|
|
52
|
-
return response
|
|
48
|
+
PROFILE_URL = f"https://{API_HOSTNAME}/auth/{__version__}/profile/"
|
|
49
|
+
ORGANIZATION_GET_URL = (
|
|
50
|
+
f"https://{API_HOSTNAME}/management/{__version__}/organizations/{{cus_id}}/"
|
|
51
|
+
)
|
|
53
52
|
|
|
54
53
|
def _signin_azure_silent(
|
|
55
54
|
self,
|
|
@@ -76,7 +75,7 @@ class BaseAuth:
|
|
|
76
75
|
)
|
|
77
76
|
|
|
78
77
|
result.update({"assertion": assertion, "scope": " ".join(scopes)})
|
|
79
|
-
return
|
|
78
|
+
return request_wrap(
|
|
80
79
|
self.ACCESS_TOKEN_URL.format(backend=backend),
|
|
81
80
|
method=self.ACCESS_TOKEN_METHOD,
|
|
82
81
|
params={"secure": True},
|
|
@@ -89,7 +88,12 @@ class BaseAuth:
|
|
|
89
88
|
).json()
|
|
90
89
|
|
|
91
90
|
def _signin_azure(
|
|
92
|
-
self,
|
|
91
|
+
self,
|
|
92
|
+
device_code: bool,
|
|
93
|
+
daemon: bool,
|
|
94
|
+
backend: str,
|
|
95
|
+
organization_id: str,
|
|
96
|
+
proxy: str = None,
|
|
93
97
|
) -> dict:
|
|
94
98
|
result = None
|
|
95
99
|
token_uri = self.ACCESS_TOKEN_URL.format(backend=backend)
|
|
@@ -121,7 +125,7 @@ class BaseAuth:
|
|
|
121
125
|
if not device_code:
|
|
122
126
|
# obtain authorization uri
|
|
123
127
|
auth_uri = (
|
|
124
|
-
|
|
128
|
+
request_wrap(
|
|
125
129
|
self.AUTHORIZATION_URL.format(backend=backend),
|
|
126
130
|
method=self.ACCESS_TOKEN_METHOD,
|
|
127
131
|
headers={
|
|
@@ -176,8 +180,10 @@ class BaseAuth:
|
|
|
176
180
|
raise PermissionError(
|
|
177
181
|
"{}: {}".format(result["error"], result["error_description"])
|
|
178
182
|
)
|
|
183
|
+
if organization_id:
|
|
184
|
+
result.update({"cus_id": organization_id})
|
|
179
185
|
|
|
180
|
-
return
|
|
186
|
+
return request_wrap(
|
|
181
187
|
token_uri,
|
|
182
188
|
method=self.ACCESS_TOKEN_METHOD,
|
|
183
189
|
params={"secure": True} if daemon else None,
|
|
@@ -230,7 +236,7 @@ class BaseAuth:
|
|
|
230
236
|
if arrow.utcnow() >= arrow.get(Auth.tokens["attrs"]["exp"]):
|
|
231
237
|
# expired, refresh token
|
|
232
238
|
proxy = context.get_context().args.proxy
|
|
233
|
-
with
|
|
239
|
+
with request_wrap(
|
|
234
240
|
Auth.REFRESH_TOKEN_URL,
|
|
235
241
|
method=Auth.ACCESS_TOKEN_METHOD,
|
|
236
242
|
json={"refresh": Auth.tokens["tokens"]["refresh"]},
|
|
@@ -270,13 +276,27 @@ class BaseAuth:
|
|
|
270
276
|
"daemon",
|
|
271
277
|
type=bool,
|
|
272
278
|
positional=False,
|
|
273
|
-
description="Sign in for a long-running, non-interactive daemon process (optional).",
|
|
279
|
+
description="Sign in for a long-running, non-interactive daemon process. (optional).",
|
|
274
280
|
aliases=["d"],
|
|
275
281
|
)
|
|
276
|
-
|
|
282
|
+
@argument(
|
|
283
|
+
"organization_id",
|
|
284
|
+
type=str,
|
|
285
|
+
positional=False,
|
|
286
|
+
description="The organization id to signin to (optional). This argument is valid only for device_code flow.",
|
|
287
|
+
aliases=["o"],
|
|
288
|
+
)
|
|
289
|
+
def signin(
|
|
290
|
+
self, device_code: bool = False, daemon: bool = False, organization_id=None
|
|
291
|
+
) -> int:
|
|
277
292
|
"""
|
|
278
293
|
Sign in to the configured authentication backend and obtain API access token.
|
|
279
294
|
"""
|
|
295
|
+
if organization_id and not device_code:
|
|
296
|
+
logging.warning("Organization_id is only valid for device code flow")
|
|
297
|
+
cprint("Organization_id is valid only for device cod flow.", "red")
|
|
298
|
+
return errno.EINVAL
|
|
299
|
+
|
|
280
300
|
ctx = context.get_context()
|
|
281
301
|
backend = ctx.args.backend
|
|
282
302
|
proxy = ctx.args.proxy
|
|
@@ -289,9 +309,10 @@ class BaseAuth:
|
|
|
289
309
|
|
|
290
310
|
try:
|
|
291
311
|
method = getattr(self, mname)
|
|
292
|
-
result = method(device_code, daemon, backend, proxy)
|
|
312
|
+
result = method(device_code, daemon, backend, organization_id, proxy)
|
|
293
313
|
# store in keyring secret service
|
|
294
314
|
user = getpass.getuser()
|
|
315
|
+
|
|
295
316
|
keyring.set_password(
|
|
296
317
|
"net.seqslab.api.tokens.refresh", user, result["tokens"]["refresh"]
|
|
297
318
|
)
|
|
@@ -313,7 +334,8 @@ class BaseAuth:
|
|
|
313
334
|
@command(
|
|
314
335
|
aliases=["daemon"],
|
|
315
336
|
help="Authenticate silently to the platform and obtain API access token. "
|
|
316
|
-
"This requires that the SeqsLab API app admin consent has been granted
|
|
337
|
+
"This requires that the SeqsLab API app admin consent has been granted and also the user must "
|
|
338
|
+
"daemon-signin beforehand.",
|
|
317
339
|
)
|
|
318
340
|
@argument(
|
|
319
341
|
"scope",
|
|
@@ -362,6 +384,15 @@ class BaseAuth:
|
|
|
362
384
|
keyring.set_password(
|
|
363
385
|
"net.seqslab.api.tokens.access", user, result["tokens"]["access"]
|
|
364
386
|
)
|
|
387
|
+
org_info = get_org(
|
|
388
|
+
access_token=result["tokens"]["access"],
|
|
389
|
+
cus_id=self._decode(result["tokens"]["access"])["cus_id"],
|
|
390
|
+
proxy=proxy,
|
|
391
|
+
)
|
|
392
|
+
cprint(
|
|
393
|
+
f"Daemon process signin to {org_info['name']}",
|
|
394
|
+
"yellow",
|
|
395
|
+
)
|
|
365
396
|
return 0
|
|
366
397
|
except ValueError:
|
|
367
398
|
return errno.EINVAL
|
|
@@ -381,11 +412,19 @@ class BaseAuth:
|
|
|
381
412
|
"""
|
|
382
413
|
Print platform access token.
|
|
383
414
|
"""
|
|
415
|
+
ctx = context.get_context()
|
|
416
|
+
proxy = ctx.args.proxy
|
|
384
417
|
token = self.get_token()
|
|
385
418
|
if not token:
|
|
386
419
|
cprint("Not signed in yet")
|
|
387
420
|
return errno.EPERM
|
|
388
421
|
|
|
422
|
+
org_info = get_org(
|
|
423
|
+
access_token=token["tokens"]["access"],
|
|
424
|
+
cus_id=self._decode(token["tokens"]["access"])["cus_id"],
|
|
425
|
+
proxy=proxy,
|
|
426
|
+
)
|
|
427
|
+
cprint(f"For Organization: {org_info['name']} ({org_info['cus_id']})", "yellow")
|
|
389
428
|
cprint(token["tokens"]["access"], "yellow")
|
|
390
429
|
return 0
|
|
391
430
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# Standard Library
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
|
|
4
|
+
from requests import request
|
|
5
|
+
from seqslab.auth import __version__, aad_app, azuread
|
|
6
|
+
from seqslab.auth.azuread import API_HOSTNAME
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
Copyright (C) 2024, Atgenomix Incorporated.
|
|
10
|
+
|
|
11
|
+
All Rights Reserved.
|
|
12
|
+
|
|
13
|
+
This program is an unpublished copyrighted work which is proprietary to
|
|
14
|
+
Atgenomix Incorporated and contains confidential information that is not to
|
|
15
|
+
be reproduced or disclosed to any other person or entity without prior
|
|
16
|
+
written consent from Atgenomix, Inc. in each and every instance.
|
|
17
|
+
|
|
18
|
+
Unauthorized reproduction of this program as well as unauthorized
|
|
19
|
+
preparation of derivative works based upon the program or distribution of
|
|
20
|
+
copies by sale, rental, lease or lending are violations of federal copyright
|
|
21
|
+
laws and state trade secret laws, punishable by civil and criminal penalties.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
ORGANIZATION_GET_URL = (
|
|
25
|
+
f"https://{API_HOSTNAME}/management/{__version__}/organizations/{{cus_id}}/"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def request_wrap(url, method, *args, **kwargs):
|
|
30
|
+
response = request(method, url, **kwargs)
|
|
31
|
+
response.raise_for_status()
|
|
32
|
+
return response
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@lru_cache(maxsize=16)
|
|
36
|
+
def get_org(access_token, cus_id, proxy):
|
|
37
|
+
return request_wrap(
|
|
38
|
+
ORGANIZATION_GET_URL.format(cus_id=cus_id),
|
|
39
|
+
method="GET",
|
|
40
|
+
headers={
|
|
41
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
42
|
+
"Accept": "application/json",
|
|
43
|
+
"Authorization": f"Bearer {access_token}",
|
|
44
|
+
},
|
|
45
|
+
proxies=proxy,
|
|
46
|
+
).json()
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# Standard Library
|
|
3
|
+
import errno
|
|
4
|
+
import getpass
|
|
5
|
+
from typing import List
|
|
6
|
+
|
|
7
|
+
import keyring
|
|
8
|
+
import requests
|
|
9
|
+
import yarl
|
|
10
|
+
from nubia import argument, command, context
|
|
11
|
+
from requests import HTTPError
|
|
12
|
+
from seqslab.auth.commands import BaseAuth as Auth
|
|
13
|
+
from seqslab.auth.utils import get_org
|
|
14
|
+
from seqslab.organization.resource.base import BaseResource
|
|
15
|
+
from termcolor import cprint
|
|
16
|
+
|
|
17
|
+
"""
|
|
18
|
+
Copyright (C) 2023, Atgenomix Incorporated.
|
|
19
|
+
|
|
20
|
+
All Rights Reserved.
|
|
21
|
+
|
|
22
|
+
This program is an unpublished copyrighted work which is proprietary to
|
|
23
|
+
Atgenomix Incorporated and contains confidential information that is not to
|
|
24
|
+
be reproduced or disclosed to any other person or entity without prior
|
|
25
|
+
written consent from Atgenomix, Inc. in each and every instance.
|
|
26
|
+
|
|
27
|
+
Unauthorized reproduction of this program as well as unauthorized
|
|
28
|
+
preparation of derivative works based upon the program or distribution of
|
|
29
|
+
copies by sale, rental, lease or lending are violations of federal copyright
|
|
30
|
+
laws and state trade secret laws, punishable by civil and criminal penalties.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class BaseOrg:
|
|
35
|
+
@command
|
|
36
|
+
def list(self, **kwargs) -> int:
|
|
37
|
+
"""
|
|
38
|
+
List organizations to which the current user belongs
|
|
39
|
+
"""
|
|
40
|
+
ctx = context.get_context()
|
|
41
|
+
backend = ctx.args.backend
|
|
42
|
+
|
|
43
|
+
try:
|
|
44
|
+
token = Auth.get_token().get("tokens").get("access")
|
|
45
|
+
organizations = (
|
|
46
|
+
BaseResource.request_wrapper(
|
|
47
|
+
callback=requests.get,
|
|
48
|
+
url=Auth.PROFILE_URL.format(backend=backend),
|
|
49
|
+
headers={"Authorization": f"Bearer {token}"},
|
|
50
|
+
status=[requests.codes.ok],
|
|
51
|
+
)
|
|
52
|
+
.json()
|
|
53
|
+
.get("organizations")
|
|
54
|
+
)
|
|
55
|
+
for index, org_id in enumerate(organizations):
|
|
56
|
+
values = organizations[org_id]
|
|
57
|
+
cprint(
|
|
58
|
+
f"{values['name']} ({org_id})",
|
|
59
|
+
"yellow",
|
|
60
|
+
)
|
|
61
|
+
except HTTPError as e:
|
|
62
|
+
cprint(str(e), "red")
|
|
63
|
+
return errno.EPROTO
|
|
64
|
+
else:
|
|
65
|
+
return 0
|
|
66
|
+
|
|
67
|
+
@command
|
|
68
|
+
@argument(
|
|
69
|
+
"id",
|
|
70
|
+
type=str,
|
|
71
|
+
positional=False,
|
|
72
|
+
description="Specify an organization ID (required).",
|
|
73
|
+
)
|
|
74
|
+
def switch(self, id, **kwargs) -> int:
|
|
75
|
+
"""
|
|
76
|
+
Switch organizations
|
|
77
|
+
"""
|
|
78
|
+
ctx = context.get_context()
|
|
79
|
+
backend = ctx.args.backend
|
|
80
|
+
proxy = ctx.args.proxy
|
|
81
|
+
user = getpass.getuser()
|
|
82
|
+
|
|
83
|
+
try:
|
|
84
|
+
token = Auth.get_token().get("tokens").get("access")
|
|
85
|
+
resp = BaseResource.request_wrapper(
|
|
86
|
+
callback=requests.get,
|
|
87
|
+
url=f"{Auth.AUTHORIZATION_URL.format(backend=backend)}{id}/",
|
|
88
|
+
headers={"Authorization": f"Bearer {token}"},
|
|
89
|
+
status=[requests.codes.ok],
|
|
90
|
+
).json()
|
|
91
|
+
|
|
92
|
+
keyring.set_password(
|
|
93
|
+
"net.seqslab.api.tokens.refresh", user, resp["tokens"]["refresh"]
|
|
94
|
+
)
|
|
95
|
+
keyring.set_password(
|
|
96
|
+
"net.seqslab.api.tokens.access", user, resp["tokens"]["access"]
|
|
97
|
+
)
|
|
98
|
+
org_info = get_org(
|
|
99
|
+
access_token=token, cus_id=Auth._decode(token)["cus_id"], proxy=proxy
|
|
100
|
+
)
|
|
101
|
+
cprint(
|
|
102
|
+
f"The organization you are currently signed into: {org_info['name']}.",
|
|
103
|
+
"yellow",
|
|
104
|
+
)
|
|
105
|
+
except HTTPError as e:
|
|
106
|
+
cprint(str(e), "red")
|
|
107
|
+
return errno.EPROTO
|
|
108
|
+
else:
|
|
109
|
+
return 0
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
@command
|
|
113
|
+
class Org(BaseOrg):
|
|
114
|
+
"""Organization commands"""
|
|
115
|
+
|
|
116
|
+
def __init__(self):
|
|
117
|
+
super().__init__()
|
|
@@ -149,12 +149,11 @@ class BaseUser:
|
|
|
149
149
|
if email.find("@") == -1:
|
|
150
150
|
cprint("Please give a legitimate email", "red")
|
|
151
151
|
return errno.ENOENT
|
|
152
|
-
|
|
153
152
|
ret = backend.add_user(
|
|
154
153
|
email=email,
|
|
155
154
|
roles=roles,
|
|
156
155
|
active=not deactivate,
|
|
157
|
-
name=name if
|
|
156
|
+
name=name if name else email.split("@")[0],
|
|
158
157
|
)
|
|
159
158
|
if isinstance(ret, int):
|
|
160
159
|
return ret
|
|
@@ -214,7 +213,7 @@ class BaseUser:
|
|
|
214
213
|
if roles:
|
|
215
214
|
payload["roles"] = roles
|
|
216
215
|
if name:
|
|
217
|
-
payload["
|
|
216
|
+
payload["username"] = name
|
|
218
217
|
if activate and not deactivate:
|
|
219
218
|
payload["is_active"] = True
|
|
220
219
|
elif deactivate and not activate:
|
|
@@ -17,6 +17,7 @@ python/seqslab/usage_logger.py
|
|
|
17
17
|
python/seqslab/auth/__init__.py
|
|
18
18
|
python/seqslab/auth/azuread.py
|
|
19
19
|
python/seqslab/auth/commands.py
|
|
20
|
+
python/seqslab/auth/utils.py
|
|
20
21
|
python/seqslab/drs/__init__.py
|
|
21
22
|
python/seqslab/drs/commands.py
|
|
22
23
|
python/seqslab/drs/api/__init__.py
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
# Standard Library
|
|
3
|
-
import errno
|
|
4
|
-
from typing import List
|
|
5
|
-
|
|
6
|
-
import requests
|
|
7
|
-
import yarl
|
|
8
|
-
from nubia import argument, command
|
|
9
|
-
from requests import HTTPError
|
|
10
|
-
from seqslab.auth.commands import BaseAuth as Auth
|
|
11
|
-
from seqslab.organization.resource.base import BaseResource
|
|
12
|
-
from termcolor import cprint
|
|
13
|
-
|
|
14
|
-
"""
|
|
15
|
-
Copyright (C) 2023, Atgenomix Incorporated.
|
|
16
|
-
|
|
17
|
-
All Rights Reserved.
|
|
18
|
-
|
|
19
|
-
This program is an unpublished copyrighted work which is proprietary to
|
|
20
|
-
Atgenomix Incorporated and contains confidential information that is not to
|
|
21
|
-
be reproduced or disclosed to any other person or entity without prior
|
|
22
|
-
written consent from Atgenomix, Inc. in each and every instance.
|
|
23
|
-
|
|
24
|
-
Unauthorized reproduction of this program as well as unauthorized
|
|
25
|
-
preparation of derivative works based upon the program or distribution of
|
|
26
|
-
copies by sale, rental, lease or lending are violations of federal copyright
|
|
27
|
-
laws and state trade secret laws, punishable by civil and criminal penalties.
|
|
28
|
-
"""
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
class BaseOrg:
|
|
32
|
-
@command
|
|
33
|
-
@argument(
|
|
34
|
-
"id",
|
|
35
|
-
type=str,
|
|
36
|
-
positional=False,
|
|
37
|
-
description="Specify an organization ID (required).",
|
|
38
|
-
)
|
|
39
|
-
@argument(
|
|
40
|
-
"uri",
|
|
41
|
-
type=List[str],
|
|
42
|
-
positional=False,
|
|
43
|
-
description="Specify the redirect URI for auth code flow (optional). If no URI is provided, "
|
|
44
|
-
"all existing registered URIs will be removed.",
|
|
45
|
-
)
|
|
46
|
-
def redirect_uri(self, id: str, uri: List[str] = [], **kwargs) -> int:
|
|
47
|
-
"""
|
|
48
|
-
Register redirect URI(s) for auth code flow.
|
|
49
|
-
"""
|
|
50
|
-
for u in uri:
|
|
51
|
-
o = yarl.URL(u)
|
|
52
|
-
if not o.scheme or not o.host:
|
|
53
|
-
cprint(f"Invalid URI '{u}'", "red")
|
|
54
|
-
return -1
|
|
55
|
-
|
|
56
|
-
try:
|
|
57
|
-
token = Auth.get_token().get("tokens").get("access")
|
|
58
|
-
BaseResource.request_wrapper(
|
|
59
|
-
callback=requests.post,
|
|
60
|
-
url=BaseResource.MGMT_ORG_URL.format(organization=id),
|
|
61
|
-
headers={"Authorization": f"Bearer {token}"},
|
|
62
|
-
data={"redirect_uris": uri},
|
|
63
|
-
status=[requests.codes.ok],
|
|
64
|
-
)
|
|
65
|
-
except HTTPError as e:
|
|
66
|
-
cprint(str(e), "red")
|
|
67
|
-
return errno.EPROTO
|
|
68
|
-
else:
|
|
69
|
-
return 0
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
@command
|
|
73
|
-
class Org(BaseOrg):
|
|
74
|
-
"""Organization commands"""
|
|
75
|
-
|
|
76
|
-
def __init__(self):
|
|
77
|
-
super().__init__()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|