lsst-ctrl-bps-panda 29.2025.4100__py3-none-any.whl → 29.2025.4300__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.
- lsst/ctrl/bps/panda/cli/cmd/__init__.py +2 -2
- lsst/ctrl/bps/panda/cli/cmd/panda_auth_commands.py +17 -1
- lsst/ctrl/bps/panda/panda_auth_drivers.py +28 -1
- lsst/ctrl/bps/panda/panda_auth_utils.py +97 -0
- lsst/ctrl/bps/panda/panda_exceptions.py +34 -0
- lsst/ctrl/bps/panda/version.py +1 -1
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/METADATA +1 -1
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/RECORD +15 -14
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/WHEEL +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/licenses/COPYRIGHT +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/licenses/LICENSE +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/licenses/bsd_license.txt +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/licenses/gpl-v3.0.txt +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/top_level.txt +0 -0
- {lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/zip-safe +0 -0
|
@@ -25,6 +25,6 @@
|
|
|
25
25
|
# You should have received a copy of the GNU General Public License
|
|
26
26
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
27
27
|
|
|
28
|
-
__all__ = ["clean", "reset", "status"]
|
|
28
|
+
__all__ = ["clean", "reset", "refresh", "status"]
|
|
29
29
|
|
|
30
|
-
from .panda_auth_commands import clean, reset, status
|
|
30
|
+
from .panda_auth_commands import clean, reset, refresh, status
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
|
|
29
29
|
__all__ = [
|
|
30
30
|
"clean",
|
|
31
|
+
"refresh",
|
|
31
32
|
"reset",
|
|
32
33
|
"status",
|
|
33
34
|
]
|
|
@@ -37,7 +38,12 @@ import click
|
|
|
37
38
|
|
|
38
39
|
from lsst.daf.butler.cli.utils import MWCommand
|
|
39
40
|
|
|
40
|
-
from ...panda_auth_drivers import
|
|
41
|
+
from ...panda_auth_drivers import (
|
|
42
|
+
panda_auth_clean_driver,
|
|
43
|
+
panda_auth_refresh_driver,
|
|
44
|
+
panda_auth_reset_driver,
|
|
45
|
+
panda_auth_status_driver,
|
|
46
|
+
)
|
|
41
47
|
|
|
42
48
|
|
|
43
49
|
class PandaAuthCommand(MWCommand):
|
|
@@ -62,3 +68,13 @@ def reset(*args, **kwargs):
|
|
|
62
68
|
def clean(*args, **kwargs):
|
|
63
69
|
"""Clean up token and token cache files."""
|
|
64
70
|
panda_auth_clean_driver(*args, **kwargs)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@click.command(cls=PandaAuthCommand)
|
|
74
|
+
@click.option("--days", default=4, help="The earlist remaining days to refresh the token.")
|
|
75
|
+
@click.option("--verbose", is_flag=True, help="Enable verbose output")
|
|
76
|
+
def refresh(*args, **kwargs):
|
|
77
|
+
"""Refresh auth tocken."""
|
|
78
|
+
days = kwargs.get("days", 4)
|
|
79
|
+
verbose = kwargs.get("verbose", False)
|
|
80
|
+
panda_auth_refresh_driver(days, verbose)
|
|
@@ -33,6 +33,7 @@ the subcommand method.
|
|
|
33
33
|
|
|
34
34
|
__all__ = [
|
|
35
35
|
"panda_auth_clean_driver",
|
|
36
|
+
"panda_auth_refresh_driver",
|
|
36
37
|
"panda_auth_reset_driver",
|
|
37
38
|
"panda_auth_status_driver",
|
|
38
39
|
]
|
|
@@ -41,7 +42,19 @@ __all__ = [
|
|
|
41
42
|
import logging
|
|
42
43
|
from datetime import datetime
|
|
43
44
|
|
|
44
|
-
from .
|
|
45
|
+
from lsst.ctrl.bps.panda.panda_exceptions import (
|
|
46
|
+
PandaAuthError,
|
|
47
|
+
TokenExpiredError,
|
|
48
|
+
TokenNotFoundError,
|
|
49
|
+
TokenTooEarlyError,
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
from .panda_auth_utils import (
|
|
53
|
+
panda_auth_clean,
|
|
54
|
+
panda_auth_refresh,
|
|
55
|
+
panda_auth_status,
|
|
56
|
+
panda_auth_update,
|
|
57
|
+
)
|
|
45
58
|
|
|
46
59
|
_LOG = logging.getLogger(__name__)
|
|
47
60
|
|
|
@@ -56,6 +69,20 @@ def panda_auth_reset_driver():
|
|
|
56
69
|
panda_auth_update(None, True)
|
|
57
70
|
|
|
58
71
|
|
|
72
|
+
def panda_auth_refresh_driver(days, verbose):
|
|
73
|
+
"""Refresh auth token."""
|
|
74
|
+
try:
|
|
75
|
+
panda_auth_refresh(days, verbose)
|
|
76
|
+
except TokenNotFoundError as e:
|
|
77
|
+
print(f"[ERROR] {e}")
|
|
78
|
+
except TokenExpiredError as e:
|
|
79
|
+
print(f"[ERROR] {e}")
|
|
80
|
+
except TokenTooEarlyError as e:
|
|
81
|
+
print(f"[INFO] {e}")
|
|
82
|
+
except PandaAuthError as e:
|
|
83
|
+
print(f"[FAIL] {e}")
|
|
84
|
+
|
|
85
|
+
|
|
59
86
|
def panda_auth_status_driver():
|
|
60
87
|
"""Gather information about a token if it exists."""
|
|
61
88
|
status = panda_auth_status()
|
|
@@ -30,19 +30,32 @@
|
|
|
30
30
|
__all__ = [
|
|
31
31
|
"panda_auth_clean",
|
|
32
32
|
"panda_auth_expiration",
|
|
33
|
+
"panda_auth_refresh",
|
|
33
34
|
"panda_auth_setup",
|
|
34
35
|
"panda_auth_status",
|
|
35
36
|
"panda_auth_update",
|
|
36
37
|
]
|
|
37
38
|
|
|
38
39
|
|
|
40
|
+
import base64
|
|
41
|
+
import json
|
|
39
42
|
import logging
|
|
40
43
|
import os
|
|
44
|
+
from datetime import UTC, datetime, timedelta
|
|
41
45
|
|
|
42
46
|
import idds.common.utils as idds_utils
|
|
43
47
|
import pandaclient.idds_api
|
|
44
48
|
from pandaclient.openidc_utils import OpenIdConnect_Utils
|
|
45
49
|
|
|
50
|
+
from lsst.ctrl.bps.panda.panda_exceptions import (
|
|
51
|
+
AuthConfigError,
|
|
52
|
+
PandaAuthError,
|
|
53
|
+
TokenExpiredError,
|
|
54
|
+
TokenNotFoundError,
|
|
55
|
+
TokenRefreshError,
|
|
56
|
+
TokenTooEarlyError,
|
|
57
|
+
)
|
|
58
|
+
|
|
46
59
|
_LOG = logging.getLogger(__name__)
|
|
47
60
|
|
|
48
61
|
|
|
@@ -151,3 +164,87 @@ def panda_auth_update(idds_server=None, reset=False):
|
|
|
151
164
|
# idds server given. So for now, check result string for keywords.
|
|
152
165
|
if "request_id" not in ret[1][-1] or "status" not in ret[1][-1]:
|
|
153
166
|
raise RuntimeError(f"Error contacting PanDA service: {ret}")
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def panda_auth_refresh(days=4, verbose=False):
|
|
170
|
+
"""
|
|
171
|
+
Refresh the current valid IAM OpenID authentication token.
|
|
172
|
+
|
|
173
|
+
This function checks the expiration time of the existing token stored
|
|
174
|
+
in the local token file and attempts to refresh it if it is close to
|
|
175
|
+
expiring (within a specified number of days).
|
|
176
|
+
|
|
177
|
+
Parameters
|
|
178
|
+
----------
|
|
179
|
+
days : `int`, optional
|
|
180
|
+
The minimum number of days before token expiration to trigger a
|
|
181
|
+
refresh. If the token expires in more than this number of days,
|
|
182
|
+
the refresh is skipped. Default is 4.
|
|
183
|
+
verbose : `bool`, optional
|
|
184
|
+
If True, enables verbose output for debugging or logging.
|
|
185
|
+
Default is False.
|
|
186
|
+
|
|
187
|
+
Returns
|
|
188
|
+
-------
|
|
189
|
+
status: `dict`
|
|
190
|
+
A dictionary containing the refreshed token status
|
|
191
|
+
"""
|
|
192
|
+
panda_url = os.environ.get("PANDA_URL")
|
|
193
|
+
panda_auth_vo = os.environ.get("PANDA_AUTH_VO")
|
|
194
|
+
|
|
195
|
+
if not panda_url or not panda_auth_vo:
|
|
196
|
+
raise PandaAuthError("Missing required environment variables: PANDA_URL or PANDA_AUTH_VO")
|
|
197
|
+
|
|
198
|
+
url_prefix = panda_url.split("/server", 1)[0]
|
|
199
|
+
auth_url = f"{url_prefix}/auth/{panda_auth_vo}_auth_config.json"
|
|
200
|
+
open_id = OpenIdConnect_Utils(auth_url, log_stream=_LOG, verbose=verbose)
|
|
201
|
+
|
|
202
|
+
token_file = open_id.get_token_path()
|
|
203
|
+
if not os.path.exists(token_file):
|
|
204
|
+
raise TokenNotFoundError("Cannot find token file. Use 'panda_auth reset' to obtain a new token.")
|
|
205
|
+
|
|
206
|
+
with open(token_file) as f:
|
|
207
|
+
data = json.load(f)
|
|
208
|
+
enc = data["id_token"].split(".")[1]
|
|
209
|
+
enc += "=" * (-len(enc) % 4)
|
|
210
|
+
dec = json.loads(base64.urlsafe_b64decode(enc.encode()))
|
|
211
|
+
exp_time = datetime.fromtimestamp(dec["exp"], tz=UTC)
|
|
212
|
+
delta = exp_time - datetime.now(UTC)
|
|
213
|
+
minutes = delta.total_seconds() / 60
|
|
214
|
+
print(f"Token will expire in {minutes} minutes.")
|
|
215
|
+
print(f"Token expiration time : {exp_time.strftime('%Y-%m-%d %H:%M:%S')} UTC")
|
|
216
|
+
if delta < timedelta(minutes=0):
|
|
217
|
+
raise TokenExpiredError("Token already expired. Cannot refresh.")
|
|
218
|
+
elif delta > timedelta(days=days):
|
|
219
|
+
raise TokenTooEarlyError(
|
|
220
|
+
f"Too early to refresh. More than {days} day(s) until expiration.\n"
|
|
221
|
+
f"Use '--days' option to adjust threshold, e.g.:\n"
|
|
222
|
+
f" panda_auth refresh --days 10"
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
refresh_token_string = data["refresh_token"]
|
|
226
|
+
|
|
227
|
+
s, auth_config = open_id.fetch_page(open_id.auth_config_url)
|
|
228
|
+
if not s:
|
|
229
|
+
raise AuthConfigError("Failed to get Auth configuration.")
|
|
230
|
+
|
|
231
|
+
s, endpoint_config = open_id.fetch_page(auth_config["oidc_config_url"])
|
|
232
|
+
if not s:
|
|
233
|
+
raise AuthConfigError("Failed to get endpoint configuration.")
|
|
234
|
+
|
|
235
|
+
s, o = open_id.refresh_token(
|
|
236
|
+
endpoint_config["token_endpoint"],
|
|
237
|
+
auth_config["client_id"],
|
|
238
|
+
auth_config["client_secret"],
|
|
239
|
+
refresh_token_string,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
if not s:
|
|
243
|
+
raise TokenRefreshError("Failed to refresh token.")
|
|
244
|
+
|
|
245
|
+
status = panda_auth_status()
|
|
246
|
+
if status:
|
|
247
|
+
exp_time = datetime.fromtimestamp(status["exp"], tz=UTC)
|
|
248
|
+
print(f"{'New expiration time:':23} {exp_time.strftime('%Y-%m-%d %H:%M:%S')} UTC")
|
|
249
|
+
print("Success to refresh token")
|
|
250
|
+
return status
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class PandaAuthError(Exception):
|
|
2
|
+
"""Base class for authentication errors."""
|
|
3
|
+
|
|
4
|
+
pass
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class TokenNotFoundError(PandaAuthError):
|
|
8
|
+
"""Raised when the token file is missing."""
|
|
9
|
+
|
|
10
|
+
pass
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TokenExpiredError(PandaAuthError):
|
|
14
|
+
"""Raised when the token has already expired."""
|
|
15
|
+
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TokenTooEarlyError(PandaAuthError):
|
|
20
|
+
"""Raised when attempting to refresh too early."""
|
|
21
|
+
|
|
22
|
+
pass
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class AuthConfigError(PandaAuthError):
|
|
26
|
+
"""Raised when fetching the auth or endpoint configuration fails."""
|
|
27
|
+
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class TokenRefreshError(PandaAuthError):
|
|
32
|
+
"""Raised when token refresh fails."""
|
|
33
|
+
|
|
34
|
+
pass
|
lsst/ctrl/bps/panda/version.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
__all__ = ["__version__"]
|
|
2
|
-
__version__ = "29.2025.
|
|
2
|
+
__version__ = "29.2025.4300"
|
{lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/RECORD
RENAMED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
lsst/ctrl/bps/panda/__init__.py,sha256=oApEOBGMuIv98uQvcDf6DLVvrbD6_8p9o0m2YPTenPY,1351
|
|
2
2
|
lsst/ctrl/bps/panda/cmd_line_embedder.py,sha256=_gyqWQQxM8ZtZzQbWlOdgjfgrotrwV3sFvwWXxe-jfQ,6778
|
|
3
3
|
lsst/ctrl/bps/panda/constants.py,sha256=hhV1CDHW9G-Z6z2wGaAc41EMlJ-yn2NN3A8psDyjTkw,1907
|
|
4
|
-
lsst/ctrl/bps/panda/panda_auth_drivers.py,sha256=
|
|
5
|
-
lsst/ctrl/bps/panda/panda_auth_utils.py,sha256=
|
|
4
|
+
lsst/ctrl/bps/panda/panda_auth_drivers.py,sha256=LoD-tP990ELmVks3Vxv76jm4a8j3h3cNRTNX2XtFGHk,3163
|
|
5
|
+
lsst/ctrl/bps/panda/panda_auth_utils.py,sha256=kJnevhvjvUegbXfAyiVcoxinONsc_TJqfK4neTmcN5k,8544
|
|
6
|
+
lsst/ctrl/bps/panda/panda_exceptions.py,sha256=HcOKWMuG79c16Y9j7IJbp990k4DBQ54e7haY1Fsl6XQ,629
|
|
6
7
|
lsst/ctrl/bps/panda/panda_service.py,sha256=5briN6eFJ9RolV2PM5Y_OguiB-7844Pu-FSBO0QyhM8,18935
|
|
7
8
|
lsst/ctrl/bps/panda/utils.py,sha256=H_dTQSHgvr3TTav97NsWM040T7DhG_57g_CIaGtIniA,41060
|
|
8
|
-
lsst/ctrl/bps/panda/version.py,sha256=
|
|
9
|
+
lsst/ctrl/bps/panda/version.py,sha256=pmH-QwBOGm7hpNEwNmgwgFuJ9J8NNZQ81N3RGqBJ3YU,55
|
|
9
10
|
lsst/ctrl/bps/panda/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
11
|
lsst/ctrl/bps/panda/cli/panda_auth.py,sha256=i54ati_HoKSlyslQRBl7QpX1w5z8MjSfHHMpT43ZeXQ,2055
|
|
11
|
-
lsst/ctrl/bps/panda/cli/cmd/__init__.py,sha256=
|
|
12
|
-
lsst/ctrl/bps/panda/cli/cmd/panda_auth_commands.py,sha256=
|
|
12
|
+
lsst/ctrl/bps/panda/cli/cmd/__init__.py,sha256=QNhn-2QmXHKVUgwmtuX7wnDv3qOUuU_30juuM_2AGaE,1413
|
|
13
|
+
lsst/ctrl/bps/panda/cli/cmd/panda_auth_commands.py,sha256=pdNpwBh9NEaMWEoMgzGC9wfqJbiEqoANuFSxtIW4Tas,2666
|
|
13
14
|
lsst/ctrl/bps/panda/conf_example/example_panda_SLAC.yaml,sha256=2ybJOm0Lmz-0QunoR-gYLptTowpr1761OKQHoGjGpVA,5855
|
|
14
15
|
lsst/ctrl/bps/panda/conf_example/pipelines_check_idf.yaml,sha256=9bfRF0y4SMhlkh6OK1VEOMOG59ytv25AZSfg-Ia8YwQ,877
|
|
15
16
|
lsst/ctrl/bps/panda/conf_example/test_idf.yaml,sha256=P-FLBEmKZ2o0QiR6w8GZ9AAAOPIQwQ_Z0IE5ttMRox0,399
|
|
@@ -18,12 +19,12 @@ lsst/ctrl/bps/panda/conf_example/test_usdf.yaml,sha256=WIbXCJZDaG7zYUHt7U96MUjUs
|
|
|
18
19
|
lsst/ctrl/bps/panda/edgenode/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
20
|
lsst/ctrl/bps/panda/edgenode/build_cmd_line_decoder.py,sha256=CjB_ESDKLK67QPlcZHWoJzfaqgC733ih_iIQrwYkiUo,3067
|
|
20
21
|
lsst/ctrl/bps/panda/edgenode/cmd_line_decoder.py,sha256=cqPeJLA7KfB7KnPTR-ykyEoHQ-_YE17h8_EfnqWA5eA,14616
|
|
21
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
22
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
23
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
24
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
25
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
26
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
27
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
28
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
29
|
-
lsst_ctrl_bps_panda-29.2025.
|
|
22
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/licenses/COPYRIGHT,sha256=5ATATZSyXxMNKoJuCJdATg4YNm56ubTwU_hDbShxIWw,116
|
|
23
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/licenses/LICENSE,sha256=pRExkS03v0MQW-neNfIcaSL6aiAnoLxYgtZoFzQ6zkM,232
|
|
24
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/licenses/bsd_license.txt,sha256=7MIcv8QRX9guUtqPSBDMPz2SnZ5swI-xZMqm_VDSfxY,1606
|
|
25
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/licenses/gpl-v3.0.txt,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
26
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/METADATA,sha256=omJhEQM4Bd2q6T_aHS41VNxzAGUdTWWCMXXJNiZw6i4,2375
|
|
27
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
28
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/top_level.txt,sha256=eUWiOuVVm9wwTrnAgiJT6tp6HQHXxIhj2QSZ7NYZH80,5
|
|
29
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/zip-safe,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
30
|
+
lsst_ctrl_bps_panda-29.2025.4300.dist-info/RECORD,,
|
{lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/WHEEL
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{lsst_ctrl_bps_panda-29.2025.4100.dist-info → lsst_ctrl_bps_panda-29.2025.4300.dist-info}/zip-safe
RENAMED
|
File without changes
|