hcs-core 0.1.281__py3-none-any.whl → 0.1.283__py3-none-any.whl
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.
- hcs_core/__init__.py +1 -1
- hcs_core/ctxp/_init.py +3 -1
- hcs_core/plan/dag.py +1 -0
- hcs_core/sglib/auth.py +25 -15
- hcs_core/sglib/client_util.py +20 -13
- hcs_core/sglib/ez_client.py +24 -17
- {hcs_core-0.1.281.dist-info → hcs_core-0.1.283.dist-info}/METADATA +1 -1
- {hcs_core-0.1.281.dist-info → hcs_core-0.1.283.dist-info}/RECORD +9 -9
- {hcs_core-0.1.281.dist-info → hcs_core-0.1.283.dist-info}/WHEEL +0 -0
hcs_core/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "0.1.
|
|
1
|
+
__version__ = "0.1.283"
|
hcs_core/ctxp/_init.py
CHANGED
|
@@ -23,6 +23,8 @@ from . import cli_processor, config, profile, state
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def _get_store_path():
|
|
26
|
+
if os.name == "nt": # Windows OS
|
|
27
|
+
return str(Path.home())
|
|
26
28
|
uid = os.getuid()
|
|
27
29
|
if uid == 0 or uid == 1000:
|
|
28
30
|
return "/tmp"
|
|
@@ -69,7 +71,7 @@ if _app_name:
|
|
|
69
71
|
|
|
70
72
|
def app_name():
|
|
71
73
|
dir_name = path.dirname(state._file._path)
|
|
72
|
-
name = dir_name[dir_name.rindex(
|
|
74
|
+
name = dir_name[dir_name.rindex(os.sep) + 1 :]
|
|
73
75
|
if name.startswith("."):
|
|
74
76
|
return name[1:]
|
|
75
77
|
raise ValueError("Unable to determine app name: " + dir_name)
|
hcs_core/plan/dag.py
CHANGED
hcs_core/sglib/auth.py
CHANGED
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
import hashlib
|
|
17
17
|
import json
|
|
18
18
|
import logging
|
|
19
|
+
import threading
|
|
19
20
|
import time
|
|
20
21
|
|
|
21
22
|
import jwt
|
|
@@ -59,24 +60,32 @@ def _decode_http_basic_auth_token(basic_token: str):
|
|
|
59
60
|
raise CtxpException(f"Invalid basic http auth token: {e}")
|
|
60
61
|
|
|
61
62
|
|
|
63
|
+
_login_lock = threading.Lock()
|
|
64
|
+
|
|
65
|
+
|
|
62
66
|
def login(force_refresh: bool = False, panic_on_failure: bool = True):
|
|
63
67
|
"""Ensure login state, using credentials from the current profile. Return oauth token."""
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
|
|
69
|
+
_login_lock.acquire()
|
|
70
|
+
try:
|
|
71
|
+
effective_profile = profile.current()
|
|
72
|
+
|
|
73
|
+
auth_data = profile.auth.get()
|
|
74
|
+
if force_refresh or not _is_auth_valid(auth_data, effective_profile):
|
|
75
|
+
oauth_token = _get_new_oauth_token(auth_data.token, effective_profile)
|
|
76
|
+
if oauth_token:
|
|
77
|
+
use_oauth_token(oauth_token, effective_profile)
|
|
78
|
+
elif panic_on_failure:
|
|
79
|
+
panic(
|
|
80
|
+
"Login failed. If this is configured API key or client credential, refresh the credential from CSP and update profile config. If this is browser based interactive login, login again."
|
|
81
|
+
)
|
|
82
|
+
else:
|
|
83
|
+
return None
|
|
75
84
|
else:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
85
|
+
oauth_token = auth_data.token
|
|
86
|
+
return oauth_token
|
|
87
|
+
finally:
|
|
88
|
+
_login_lock.release()
|
|
80
89
|
|
|
81
90
|
|
|
82
91
|
def _get_new_oauth_token(old_oauth_token, effective_profile):
|
|
@@ -130,6 +139,7 @@ class MyOAuth2Client(OAuth2Client):
|
|
|
130
139
|
super().__init__()
|
|
131
140
|
|
|
132
141
|
def ensure_token(self):
|
|
142
|
+
# pylint: disable=access-member-before-definition
|
|
133
143
|
if self.token is None or not super().ensure_active_token():
|
|
134
144
|
self.token = login()
|
|
135
145
|
|
hcs_core/sglib/client_util.py
CHANGED
|
@@ -16,6 +16,7 @@ limitations under the License.
|
|
|
16
16
|
import json
|
|
17
17
|
import os
|
|
18
18
|
import sys
|
|
19
|
+
import threading
|
|
19
20
|
import time
|
|
20
21
|
from typing import Callable, Iterator
|
|
21
22
|
|
|
@@ -27,21 +28,27 @@ from hcs_core.util.query_util import PageRequest, with_query
|
|
|
27
28
|
|
|
28
29
|
_caches = {}
|
|
29
30
|
|
|
31
|
+
_client_instance_lock = threading.RLock()
|
|
32
|
+
|
|
30
33
|
|
|
31
34
|
def hdc_service_client(service_name: str) -> EzClient:
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
url
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
_client_instance_lock.acquire()
|
|
36
|
+
try:
|
|
37
|
+
instance = _caches.get(service_name)
|
|
38
|
+
if not instance:
|
|
39
|
+
|
|
40
|
+
def _get_url(): # make it deferred so no need to initialize profile
|
|
41
|
+
url = _get_hcs_url_considering_env_override(service_name)
|
|
42
|
+
if not url.endswith("/"):
|
|
43
|
+
url += "/"
|
|
44
|
+
url += service_name
|
|
45
|
+
return url
|
|
46
|
+
|
|
47
|
+
instance = hcs_client(_get_url)
|
|
48
|
+
_caches[service_name] = instance
|
|
49
|
+
return instance
|
|
50
|
+
finally:
|
|
51
|
+
_client_instance_lock.release()
|
|
45
52
|
|
|
46
53
|
|
|
47
54
|
def _get_hcs_url_considering_env_override(service_name: str):
|
hcs_core/sglib/ez_client.py
CHANGED
|
@@ -15,7 +15,9 @@ limitations under the License.
|
|
|
15
15
|
|
|
16
16
|
import json
|
|
17
17
|
import logging
|
|
18
|
+
import os
|
|
18
19
|
import sys
|
|
20
|
+
import threading
|
|
19
21
|
from http.client import HTTPResponse
|
|
20
22
|
from typing import Callable, Optional, Type, Union
|
|
21
23
|
|
|
@@ -138,25 +140,30 @@ class EzClient:
|
|
|
138
140
|
self._base_url = base_url
|
|
139
141
|
self._client_impl = oauth_client
|
|
140
142
|
self._lazy_oauth_client = lazy_oauth_client
|
|
143
|
+
self._lock = threading.Lock()
|
|
141
144
|
|
|
142
145
|
def _client(self):
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
146
|
+
self._lock.acquire()
|
|
147
|
+
try:
|
|
148
|
+
if not self._client_impl:
|
|
149
|
+
client = self._lazy_oauth_client()
|
|
150
|
+
base_url = self._base_url() if callable(self._base_url) else self._base_url
|
|
151
|
+
client.base_url = base_url
|
|
152
|
+
client.timeout = int(os.environ.get("HCS_TIMEOUT", 30))
|
|
153
|
+
request_hooks = client.event_hooks["request"]
|
|
154
|
+
response_hooks = client.event_hooks["response"]
|
|
155
|
+
if _log_request not in request_hooks:
|
|
156
|
+
request_hooks.append(_log_request)
|
|
157
|
+
if _log_response not in response_hooks:
|
|
158
|
+
response_hooks.append(_log_response)
|
|
159
|
+
if _raise_on_4xx_5xx not in response_hooks:
|
|
160
|
+
response_hooks.append(_raise_on_4xx_5xx)
|
|
161
|
+
self._client_impl = client
|
|
162
|
+
|
|
163
|
+
self._client_impl.ensure_token()
|
|
164
|
+
return self._client_impl
|
|
165
|
+
finally:
|
|
166
|
+
self._lock.release()
|
|
160
167
|
|
|
161
168
|
def post(
|
|
162
169
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
hcs_core/__init__.py,sha256=
|
|
1
|
+
hcs_core/__init__.py,sha256=x9ZiM3jL6aO4MBjTZ4F4ssx87GjJ59ZjZUo5JQbJRa4,24
|
|
2
2
|
hcs_core/ctxp/__init__.py,sha256=bHVHhJP10Luz1a3Kk3zFx14dAO4SY6Q20Lrv8rNWWGc,1075
|
|
3
|
-
hcs_core/ctxp/_init.py,sha256=
|
|
3
|
+
hcs_core/ctxp/_init.py,sha256=yq46VOty4zs_WcLt1SrtePxbW8S4RIz4YUCP3xIBvCA,2797
|
|
4
4
|
hcs_core/ctxp/cli_options.py,sha256=g5JnzOtyWiGLCLcGp5x54MPFLW_NOfhfevXUlX5L8tM,2532
|
|
5
5
|
hcs_core/ctxp/cli_processor.py,sha256=2RhBz7zFm2UDRwbMDwBpeAQQCt4sjZJzn1nePAcMA_o,7329
|
|
6
6
|
hcs_core/ctxp/cmd_util.py,sha256=_-VwQSmkfi52qWC3uHQI06mSiIPfsZroDruTDYHXiMA,3119
|
|
@@ -32,7 +32,7 @@ hcs_core/plan/actions.py,sha256=UvCynzApJUxi39HUoPIQ_uownlbvFbJ4aAs6pmulrLY,125
|
|
|
32
32
|
hcs_core/plan/base_provider.py,sha256=CSJFN8lopWTUblw8CW78Epnef9BbJVLhPLk9bPfZceM,1299
|
|
33
33
|
hcs_core/plan/context.py,sha256=5NI5Otk0jGKtBGvO8Sc1xdOHUCu_lXQYNrSctT3Hyq8,116
|
|
34
34
|
hcs_core/plan/core.py,sha256=vJDG5WYV6XtYtDjK7lyM6MLrB0OEfH6YDqF06DoC9iw,21137
|
|
35
|
-
hcs_core/plan/dag.py,sha256=
|
|
35
|
+
hcs_core/plan/dag.py,sha256=TDpyXVuiwAxeWwNq2HkeZq8F90CnT97NfAl1NjYcII4,12970
|
|
36
36
|
hcs_core/plan/helper.py,sha256=__b8tlzLBT1Rm3vgiS-pWnZImaoZbsmKSRJtt_1gj8E,7763
|
|
37
37
|
hcs_core/plan/kop.py,sha256=G1bOPvvaSqrH_AHWWpGx3sFHNvsulbSu6OnPWgBkOqs,5455
|
|
38
38
|
hcs_core/plan/provider/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -41,11 +41,11 @@ hcs_core/plan/provider/dev/_prepare.py,sha256=PvVnheEQwpj8sWYz2lDONQVTs4pHPYuo2c
|
|
|
41
41
|
hcs_core/plan/provider/dev/dummy.py,sha256=zKEr9J4WHhlN5gFdmrFyEfCF0xlQlCJg0CC1dG9VaLA,1958
|
|
42
42
|
hcs_core/plan/provider/dev/fibonacci.py,sha256=8WhDr5c9harNAlVPZomQJEqbWe0hUqbppO6ZkwEUcJ0,1104
|
|
43
43
|
hcs_core/sglib/__init__.py,sha256=oT0etW7vsEbHlXiGL5x23ZXyyFqeLi81RxQQ5lfKSV0,654
|
|
44
|
-
hcs_core/sglib/auth.py,sha256=
|
|
44
|
+
hcs_core/sglib/auth.py,sha256=voI-55RFh3_CkmzldkayQX-5s8n8JwYM9eLdExB6xTQ,6237
|
|
45
45
|
hcs_core/sglib/cli_options.py,sha256=NvdiHpX_o6IYPEM8cQYLb_R7T4aiXVvYLqn6Vk4Q2-Y,1761
|
|
46
|
-
hcs_core/sglib/client_util.py,sha256=
|
|
46
|
+
hcs_core/sglib/client_util.py,sha256=ZCXmNfmUL4_iry4yU2bPWL0dLLNIGu3zp541cFt6Or0,10876
|
|
47
47
|
hcs_core/sglib/csp.py,sha256=anZqbQLIZw831PgW9Z4pweqfAeBH7rXPIAkwkyPkfGY,8054
|
|
48
|
-
hcs_core/sglib/ez_client.py,sha256=
|
|
48
|
+
hcs_core/sglib/ez_client.py,sha256=6R_gnRRxxmJYg6oJTnUB7ZLvUTRlEEYuhRyLLOvMxWI,7592
|
|
49
49
|
hcs_core/sglib/hcs_client.py,sha256=pxRZQ79ABhOyihAI8oOeTxw2dXkce5-NyRkJAoo0OL0,888
|
|
50
50
|
hcs_core/sglib/init.py,sha256=w_0ZU70Q1TGbSZsqSi7ewKQqpExFlepOT7mIqH0wnho,310
|
|
51
51
|
hcs_core/sglib/login_support.py,sha256=9YLhaocomqMLkoXcVW5-iDfS7QW9ON2Btx4OBZMAhaE,7581
|
|
@@ -63,6 +63,6 @@ hcs_core/util/query_util.py,sha256=5bh3bUVIQuY9qerndfuyfyzkTExYJ8zD0_e3PSN7y-4,3
|
|
|
63
63
|
hcs_core/util/scheduler.py,sha256=bPpCmGUL1UctJMfLPAg-h4Hl2YZr96FiI78-G_Usn08,2958
|
|
64
64
|
hcs_core/util/ssl_util.py,sha256=MvU102fGwWWh9hhSmLnn1qQIWuD6TjZnN0iH0MXUtW0,1239
|
|
65
65
|
hcs_core/util/versions.py,sha256=wwbcYFpxBohI-QjcrmxGsNghdnx4EWHBipMUL7vnpwM,1728
|
|
66
|
-
hcs_core-0.1.
|
|
67
|
-
hcs_core-0.1.
|
|
68
|
-
hcs_core-0.1.
|
|
66
|
+
hcs_core-0.1.283.dist-info/METADATA,sha256=ra0XDflOSJYp33ZyUkKxDncj2gZkkrbMJf-Ui0QuRkw,1837
|
|
67
|
+
hcs_core-0.1.283.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
68
|
+
hcs_core-0.1.283.dist-info/RECORD,,
|
|
File without changes
|