haplohub-cli 2.4.0__tar.gz → 2.5.0__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.
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/PKG-INFO +1 -1
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/_version.py +3 -3
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/auth.py +2 -2
- haplohub_cli-2.5.0/haplohub_cli/auth/tests/test_token_storage.py +74 -0
- haplohub_cli-2.5.0/haplohub_cli/auth/token_storage.py +107 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/config.py +2 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/config/config_manager.py +2 -1
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/api/client.py +11 -5
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/PKG-INFO +1 -1
- haplohub_cli-2.5.0/haplohub_cli.egg-info/scm_version.json +8 -0
- haplohub_cli-2.4.0/haplohub_cli/auth/tests/test_token_storage.py +0 -64
- haplohub_cli-2.4.0/haplohub_cli/auth/token_storage.py +0 -37
- haplohub_cli-2.4.0/haplohub_cli.egg-info/scm_version.json +0 -8
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/.github/dependabot.yml +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/.github/workflows/on_pr.yml +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/.github/workflows/on_push_main.yml +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/.gitignore +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/.pre-commit-config.yaml +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/README.md +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/auth_web_server.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/oauth_client.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/tests/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/auth/tests/test_auth_web_server.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/cli.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/algorithm/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/algorithm/result/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/cohort/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/cohort/biomarker.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/cohort/member/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/cohort/member/report.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/cohort/sample.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/file.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/login.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/metadata/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/variant.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/version.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/config/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/config/config.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/api/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/checksum.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/network.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/slug.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/tests/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/tests/test_checksum.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/tests/test_network.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/tests/test_slug.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/types.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/core/upload.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/algorithm.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/algorithm_result.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/biomarker.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/cohort.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/config.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/decorators.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/file.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/formatter_registry.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/generic.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/member.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/metadata.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/sample.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/utils.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/formatters/variant.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/settings.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/types/__init__.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/types/variant_range.py +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/SOURCES.txt +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/dependency_links.txt +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/entry_points.txt +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/requires.txt +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/scm_file_list.json +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli.egg-info/top_level.txt +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/pyproject.toml +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/setup.cfg +0 -0
- {haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/uv.lock +0 -0
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '2.
|
|
22
|
-
__version_tuple__ = version_tuple = (2,
|
|
21
|
+
__version__ = version = '2.5.0'
|
|
22
|
+
__version_tuple__ = version_tuple = (2, 5, 0)
|
|
23
23
|
|
|
24
|
-
__commit_id__ = commit_id = '
|
|
24
|
+
__commit_id__ = commit_id = 'gcd8a204d2'
|
|
@@ -20,7 +20,7 @@ def token_login(api_key: str):
|
|
|
20
20
|
|
|
21
21
|
response.raise_for_status()
|
|
22
22
|
|
|
23
|
-
oauth_client.token_storage.store_credentials({"api_key": api_key})
|
|
23
|
+
oauth_client.token_storage.store_credentials(api_url, {"api_key": api_key})
|
|
24
24
|
click.echo("Successfully authenticated with HaploHub.")
|
|
25
25
|
|
|
26
26
|
|
|
@@ -47,4 +47,4 @@ def interactive_login():
|
|
|
47
47
|
credentials = auth_request.exchange_code(auth_code)
|
|
48
48
|
|
|
49
49
|
click.echo("Successfully authenticated with HaploHub.")
|
|
50
|
-
oauth_client.token_storage.store_credentials(credentials)
|
|
50
|
+
oauth_client.token_storage.store_credentials(config_manager.config.api_url, credentials)
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from pyfakefs.fake_filesystem_unittest import TestCase
|
|
5
|
+
|
|
6
|
+
from haplohub_cli.auth.token_storage import CREDENTIALS_VERSION, TokenStorage, normalize_api_url
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TokenStorageTestCase(TestCase):
|
|
10
|
+
def setUp(self):
|
|
11
|
+
self.setUpPyfakefs()
|
|
12
|
+
self.instance = TokenStorage("/tmp/test_token_storage.json")
|
|
13
|
+
|
|
14
|
+
def test_credentials_exist_should_return_false_when_file_does_not_exist(self):
|
|
15
|
+
self.assertFalse(self.instance.credentials_exist("https://api.example.com"))
|
|
16
|
+
|
|
17
|
+
def test_store_credentials_should_save_versioned_credentials(self):
|
|
18
|
+
self.instance.store_credentials("https://api.example.com", {"access_token": "123456"})
|
|
19
|
+
|
|
20
|
+
with open(self.instance.token_file) as f:
|
|
21
|
+
self.assertEqual(
|
|
22
|
+
json.load(f),
|
|
23
|
+
{
|
|
24
|
+
"version": CREDENTIALS_VERSION,
|
|
25
|
+
"environments": {"https://api.example.com": {"access_token": "123456"}},
|
|
26
|
+
},
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def test_credentials_are_isolated_by_environment(self):
|
|
30
|
+
self.instance.store_credentials("https://api-a.example.com", {"access_token": "token-a"})
|
|
31
|
+
self.instance.store_credentials("https://api-b.example.com", {"api_key": "key-b"})
|
|
32
|
+
|
|
33
|
+
self.assertEqual(self.instance.get_access_token("https://api-a.example.com"), "token-a")
|
|
34
|
+
self.assertEqual(self.instance.get_api_key("https://api-b.example.com"), "key-b")
|
|
35
|
+
self.assertFalse(self.instance.has_api_key("https://api-a.example.com"))
|
|
36
|
+
self.assertTrue(self.instance.has_api_key("https://api-b.example.com"))
|
|
37
|
+
|
|
38
|
+
def test_get_credentials_should_fail_for_unknown_environment(self):
|
|
39
|
+
self.instance.store_credentials("https://api-a.example.com", {"access_token": "token-a"})
|
|
40
|
+
|
|
41
|
+
with pytest.raises(KeyError):
|
|
42
|
+
self.instance.get_credentials("https://api-b.example.com")
|
|
43
|
+
|
|
44
|
+
def test_legacy_credentials_are_migrated_to_current_environment(self):
|
|
45
|
+
credentials = {"access_token": "123456", "refresh_token": "refresh-123456"}
|
|
46
|
+
with open(self.instance.token_file, "w") as f:
|
|
47
|
+
json.dump(credentials, f)
|
|
48
|
+
|
|
49
|
+
self.assertTrue(self.instance.migrate("https://api.example.com/"))
|
|
50
|
+
self.assertEqual(self.instance.get_credentials("https://api.example.com"), credentials)
|
|
51
|
+
|
|
52
|
+
with open(self.instance.token_file) as f:
|
|
53
|
+
self.assertEqual(
|
|
54
|
+
json.load(f),
|
|
55
|
+
{
|
|
56
|
+
"version": CREDENTIALS_VERSION,
|
|
57
|
+
"environments": {"https://api.example.com": credentials},
|
|
58
|
+
},
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
def test_versioned_credentials_are_not_migrated_again(self):
|
|
62
|
+
self.instance.store_credentials("https://api-a.example.com", {"access_token": "token-a"})
|
|
63
|
+
|
|
64
|
+
self.assertFalse(self.instance.migrate("https://api-b.example.com"))
|
|
65
|
+
self.assertFalse(self.instance.credentials_exist("https://api-b.example.com"))
|
|
66
|
+
|
|
67
|
+
def test_get_refresh_token_should_return_none_when_missing(self):
|
|
68
|
+
self.instance.store_credentials("https://api.example.com", {"access_token": "123456"})
|
|
69
|
+
|
|
70
|
+
self.assertIsNone(self.instance.get_refresh_token("https://api.example.com"))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def test_normalize_api_url():
|
|
74
|
+
assert normalize_api_url(" HTTPS://API.Example.COM/base/ ") == "https://api.example.com/base"
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import tempfile
|
|
4
|
+
from genericpath import exists
|
|
5
|
+
from os import path
|
|
6
|
+
from typing import Dict, Tuple
|
|
7
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
8
|
+
|
|
9
|
+
from haplohub_cli import settings
|
|
10
|
+
|
|
11
|
+
CREDENTIALS_VERSION = 2
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def normalize_api_url(api_url: str) -> str:
|
|
15
|
+
api_url = api_url.strip()
|
|
16
|
+
parsed = urlsplit(api_url)
|
|
17
|
+
|
|
18
|
+
if not parsed.scheme or not parsed.netloc:
|
|
19
|
+
return api_url.rstrip("/")
|
|
20
|
+
|
|
21
|
+
return urlunsplit(
|
|
22
|
+
(
|
|
23
|
+
parsed.scheme.lower(),
|
|
24
|
+
parsed.netloc.lower(),
|
|
25
|
+
parsed.path.rstrip("/"),
|
|
26
|
+
parsed.query,
|
|
27
|
+
parsed.fragment,
|
|
28
|
+
)
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class TokenStorage:
|
|
33
|
+
def __init__(self, token_file: str):
|
|
34
|
+
self.token_file = token_file
|
|
35
|
+
|
|
36
|
+
def migrate(self, api_url: str) -> bool:
|
|
37
|
+
_, migrated = self._load(api_url)
|
|
38
|
+
return migrated
|
|
39
|
+
|
|
40
|
+
def credentials_exist(self, api_url: str) -> bool:
|
|
41
|
+
data, _ = self._load(api_url)
|
|
42
|
+
return normalize_api_url(api_url) in data["environments"]
|
|
43
|
+
|
|
44
|
+
def store_credentials(self, api_url: str, credentials: dict):
|
|
45
|
+
data, _ = self._load(api_url)
|
|
46
|
+
data["environments"][normalize_api_url(api_url)] = credentials
|
|
47
|
+
self._save(data)
|
|
48
|
+
|
|
49
|
+
def get_credentials(self, api_url: str) -> dict:
|
|
50
|
+
data, _ = self._load(api_url)
|
|
51
|
+
return data["environments"][normalize_api_url(api_url)]
|
|
52
|
+
|
|
53
|
+
def get_access_token(self, api_url: str):
|
|
54
|
+
return self.get_credentials(api_url)["access_token"]
|
|
55
|
+
|
|
56
|
+
def get_api_key(self, api_url: str):
|
|
57
|
+
return self.get_credentials(api_url)["api_key"]
|
|
58
|
+
|
|
59
|
+
def get_refresh_token(self, api_url: str):
|
|
60
|
+
return self.get_credentials(api_url).get("refresh_token")
|
|
61
|
+
|
|
62
|
+
def has_api_key(self, api_url: str) -> bool:
|
|
63
|
+
return self.credentials_exist(api_url) and "api_key" in self.get_credentials(api_url)
|
|
64
|
+
|
|
65
|
+
def _load(self, migration_api_url: str) -> Tuple[Dict[str, object], bool]:
|
|
66
|
+
if not exists(self.token_file):
|
|
67
|
+
return self._empty_store(), False
|
|
68
|
+
|
|
69
|
+
with open(self.token_file) as f:
|
|
70
|
+
data = json.load(f)
|
|
71
|
+
|
|
72
|
+
if data.get("version") == CREDENTIALS_VERSION:
|
|
73
|
+
if not isinstance(data.get("environments"), dict):
|
|
74
|
+
raise ValueError("Invalid credentials file: 'environments' must be an object")
|
|
75
|
+
return data, False
|
|
76
|
+
|
|
77
|
+
if "version" in data:
|
|
78
|
+
raise ValueError(f"Unsupported credentials file version: {data['version']}")
|
|
79
|
+
|
|
80
|
+
migrated = self._empty_store()
|
|
81
|
+
migrated["environments"][normalize_api_url(migration_api_url)] = data
|
|
82
|
+
self._save(migrated)
|
|
83
|
+
return migrated, True
|
|
84
|
+
|
|
85
|
+
def _save(self, data: Dict[str, object]):
|
|
86
|
+
directory = path.dirname(self.token_file) or "."
|
|
87
|
+
os.makedirs(directory, exist_ok=True)
|
|
88
|
+
|
|
89
|
+
temporary_file = None
|
|
90
|
+
try:
|
|
91
|
+
with tempfile.NamedTemporaryFile("w", dir=directory, delete=False) as f:
|
|
92
|
+
temporary_file = f.name
|
|
93
|
+
json.dump(data, f, indent=4)
|
|
94
|
+
f.write("\n")
|
|
95
|
+
|
|
96
|
+
os.chmod(temporary_file, 0o600)
|
|
97
|
+
os.replace(temporary_file, self.token_file)
|
|
98
|
+
finally:
|
|
99
|
+
if temporary_file and exists(temporary_file):
|
|
100
|
+
os.unlink(temporary_file)
|
|
101
|
+
|
|
102
|
+
@staticmethod
|
|
103
|
+
def _empty_store() -> Dict[str, object]:
|
|
104
|
+
return {"version": CREDENTIALS_VERSION, "environments": {}}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
token_storage = TokenStorage(settings.CREDENTIALS_FILE)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import click
|
|
2
2
|
|
|
3
|
+
from haplohub_cli.auth.token_storage import token_storage
|
|
3
4
|
from haplohub_cli.config.config_manager import config_manager
|
|
4
5
|
|
|
5
6
|
|
|
@@ -28,6 +29,7 @@ def set(key, value):
|
|
|
28
29
|
@config.command()
|
|
29
30
|
@click.argument("api_url", type=click.STRING)
|
|
30
31
|
def switch(api_url):
|
|
32
|
+
token_storage.migrate(config_manager.config.api_url)
|
|
31
33
|
config_manager.switch_environment(api_url)
|
|
32
34
|
return config_manager.config
|
|
33
35
|
|
|
@@ -37,6 +37,7 @@ class ConfigManager:
|
|
|
37
37
|
return self._config
|
|
38
38
|
|
|
39
39
|
def switch_environment(self, api_url: str):
|
|
40
|
+
api_url = api_url.strip().rstrip("/")
|
|
40
41
|
response = requests.get(f"{api_url}/api/v1/config/")
|
|
41
42
|
response.raise_for_status()
|
|
42
43
|
data = response.json()
|
|
@@ -44,7 +45,7 @@ class ConfigManager:
|
|
|
44
45
|
if data["status"] != "success":
|
|
45
46
|
raise Exception(data.get("error", "Unknown error"))
|
|
46
47
|
|
|
47
|
-
new_config = {"redirect_port": settings.REDIRECT_PORT, "api_url": api_url
|
|
48
|
+
new_config = {**data["result"]["cli"], "redirect_port": settings.REDIRECT_PORT, "api_url": api_url}
|
|
48
49
|
|
|
49
50
|
self._config = Config(**new_config)
|
|
50
51
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from functools import cached_property
|
|
2
2
|
|
|
3
|
+
import click
|
|
3
4
|
from haplohub import (
|
|
4
5
|
AlgorithmApi,
|
|
5
6
|
AlgorithmResultApi,
|
|
@@ -25,15 +26,20 @@ class Client:
|
|
|
25
26
|
|
|
26
27
|
@cached_property
|
|
27
28
|
def client(self):
|
|
28
|
-
|
|
29
|
+
api_url = config_manager.config.api_url
|
|
30
|
+
|
|
31
|
+
if not self.token_storage.credentials_exist(api_url):
|
|
32
|
+
raise click.ClickException(f"No credentials found for {api_url}. Run `haplohub login` first.")
|
|
33
|
+
|
|
34
|
+
if self.token_storage.has_api_key(api_url):
|
|
29
35
|
config = Configuration(
|
|
30
|
-
host=
|
|
31
|
-
api_key={"ApiKeyAuth": self.token_storage.get_api_key()},
|
|
36
|
+
host=api_url,
|
|
37
|
+
api_key={"ApiKeyAuth": self.token_storage.get_api_key(api_url)},
|
|
32
38
|
)
|
|
33
39
|
else:
|
|
34
40
|
config = Configuration(
|
|
35
|
-
host=
|
|
36
|
-
access_token=self.token_storage.get_access_token(),
|
|
41
|
+
host=api_url,
|
|
42
|
+
access_token=self.token_storage.get_access_token(api_url),
|
|
37
43
|
)
|
|
38
44
|
return ApiClient(config)
|
|
39
45
|
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
|
|
3
|
-
from pyfakefs.fake_filesystem_unittest import TestCase
|
|
4
|
-
|
|
5
|
-
from haplohub_cli.auth.token_storage import TokenStorage
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class TokenStorageTestCase(TestCase):
|
|
9
|
-
@classmethod
|
|
10
|
-
def setUpClass(cls):
|
|
11
|
-
cls.setUpClassPyfakefs()
|
|
12
|
-
cls.instance = TokenStorage("/tmp/test_token_storage.json")
|
|
13
|
-
|
|
14
|
-
def test_credentials_exist_should_return_false_when_file_does_not_exist(self):
|
|
15
|
-
self.assertFalse(self.instance.credentials_exist)
|
|
16
|
-
|
|
17
|
-
def test_credentials_exist_should_return_true_when_file_exists(self):
|
|
18
|
-
with open(self.instance.token_file, "w"):
|
|
19
|
-
pass
|
|
20
|
-
|
|
21
|
-
self.assertTrue(self.instance.credentials_exist)
|
|
22
|
-
|
|
23
|
-
def test_store_credentials_should_save_credentials_to_file(self):
|
|
24
|
-
creds = {"test": True}
|
|
25
|
-
|
|
26
|
-
self.instance.store_credentials(creds)
|
|
27
|
-
|
|
28
|
-
with open(self.instance.token_file, "r") as f:
|
|
29
|
-
self.assertEqual(json.load(f), creds)
|
|
30
|
-
|
|
31
|
-
def test_get_credentials_should_return_credentials_from_file(self):
|
|
32
|
-
creds = {"test": True}
|
|
33
|
-
|
|
34
|
-
self.instance.store_credentials(creds)
|
|
35
|
-
|
|
36
|
-
self.assertEqual(self.instance.get_credentials(), creds)
|
|
37
|
-
|
|
38
|
-
def test_get_access_token_should_return_access_token_from_credentials(self):
|
|
39
|
-
creds = {"access_token": "123456"}
|
|
40
|
-
|
|
41
|
-
self.instance.store_credentials(creds)
|
|
42
|
-
|
|
43
|
-
self.assertEqual(self.instance.get_access_token(), "123456")
|
|
44
|
-
|
|
45
|
-
def test_get_api_key_should_return_api_key_from_credentials(self):
|
|
46
|
-
creds = {"api_key": "ak_789"}
|
|
47
|
-
|
|
48
|
-
self.instance.store_credentials(creds)
|
|
49
|
-
|
|
50
|
-
self.assertEqual(self.instance.get_api_key(), "ak_789")
|
|
51
|
-
|
|
52
|
-
def test_has_api_key_should_return_true_when_api_key_exists(self):
|
|
53
|
-
creds = {"api_key": "ak_789"}
|
|
54
|
-
|
|
55
|
-
self.instance.store_credentials(creds)
|
|
56
|
-
|
|
57
|
-
self.assertTrue(self.instance.has_api_key)
|
|
58
|
-
|
|
59
|
-
def test_has_api_key_should_return_false_when_access_token_credentials(self):
|
|
60
|
-
creds = {"access_token": "123456"}
|
|
61
|
-
|
|
62
|
-
self.instance.store_credentials(creds)
|
|
63
|
-
|
|
64
|
-
self.assertFalse(self.instance.has_api_key)
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from genericpath import exists
|
|
3
|
-
|
|
4
|
-
from haplohub_cli import settings
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class TokenStorage:
|
|
8
|
-
def __init__(self, token_file: str):
|
|
9
|
-
self.token_file = token_file
|
|
10
|
-
|
|
11
|
-
@property
|
|
12
|
-
def credentials_exist(self):
|
|
13
|
-
return exists(self.token_file)
|
|
14
|
-
|
|
15
|
-
def store_credentials(self, credentials: dict):
|
|
16
|
-
with open(self.token_file, "w") as f:
|
|
17
|
-
json.dump(credentials, f)
|
|
18
|
-
|
|
19
|
-
def get_credentials(self):
|
|
20
|
-
with open(self.token_file, "r") as f:
|
|
21
|
-
return json.load(f)
|
|
22
|
-
|
|
23
|
-
def get_access_token(self):
|
|
24
|
-
return self.get_credentials()["access_token"]
|
|
25
|
-
|
|
26
|
-
def get_api_key(self):
|
|
27
|
-
return self.get_credentials()["api_key"]
|
|
28
|
-
|
|
29
|
-
def get_refresh_token(self):
|
|
30
|
-
return self.get_credentials().get("refresh_token")
|
|
31
|
-
|
|
32
|
-
@property
|
|
33
|
-
def has_api_key(self):
|
|
34
|
-
return self.credentials_exist and "api_key" in self.get_credentials()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
token_storage = TokenStorage(settings.CREDENTIALS_FILE)
|
|
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
|
{haplohub_cli-2.4.0 → haplohub_cli-2.5.0}/haplohub_cli/commands/algorithm/result/__init__.py
RENAMED
|
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
|