Skip to content

Commit 4cf9dec

Browse files
committed
refactor: take diracx token path from diracx
1 parent dc011c2 commit 4cf9dec

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

integration_tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def prepare_environment(
317317

318318
docker_compose_fn_final = Path(tempfile.mkdtemp()) / "ci"
319319
typer.secho("Running docker-compose to create DiracX containers", fg=c.GREEN)
320-
typer.secho(f"Will eave a folder behind: {docker_compose_fn_final}", fg=c.YELLOW)
320+
typer.secho(f"Will leave a folder behind: {docker_compose_fn_final}", fg=c.YELLOW)
321321

322322
with _gen_docker_compose(modules) as docker_compose_fn:
323323
# We cannot use the temporary directory created in the context manager because

src/DIRAC/FrameworkSystem/scripts/dirac_login.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
from DIRAC.Core.Base.Client import Client
3333

3434

35-
# token location
36-
DIRAC_TOKEN_FILE = Path.home() / ".cache" / "diracx" / "credentials.json"
37-
EXPIRES_GRACE_SECONDS = 15
38-
39-
4035
# At this point, we disable CS synchronization so that an error related
4136
# to the lack of a proxy certificate does not occur when trying to synchronize.
4237
# Synchronization will take place after passing the authorization algorithm (creating a proxy).
@@ -320,10 +315,13 @@ def loginWithCertificate(self):
320315

321316
# Get a token for use with diracx
322317
if os.getenv("DIRAC_ENABLE_DIRACX_LOGIN", "No").lower() in ("yes", "true"):
318+
from diracx.cli import EXPIRES_GRACE_SECONDS # pylint: disable=import-error
319+
from diracx.cli.utils import CREDENTIALS_PATH # pylint: disable=import-error
320+
323321
res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
324322
if not res["OK"]:
325323
return res
326-
DIRAC_TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
324+
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
327325
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
328326
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
329327
)
@@ -333,7 +331,7 @@ def loginWithCertificate(self):
333331
# TODO: "refresh_token_expires":
334332
"expires": expires.isoformat(),
335333
}
336-
DIRAC_TOKEN_FILE.write_text(json.dumps(credential_data))
334+
CREDENTIALS_PATH.write_text(json.dumps(credential_data))
337335

338336
return S_OK()
339337

src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
from pathlib import Path
2727

2828

29-
DIRAC_TOKEN_FILE = Path.home() / ".cache" / "diracx" / "credentials.json"
30-
EXPIRES_GRACE_SECONDS = 15
31-
32-
3329
class Params(ProxyGeneration.CLIParams):
3430
addVOMSExt = False
3531
uploadProxy = True
@@ -245,10 +241,13 @@ def doTheMagic(self):
245241
return resultProxyUpload
246242

247243
if os.getenv("DIRAC_ENABLE_DIRACX_LOGIN", "No").lower() in ("yes", "true"):
244+
from diracx.cli import EXPIRES_GRACE_SECONDS # pylint: disable=import-error
245+
from diracx.cli.utils import CREDENTIALS_PATH # pylint: disable=import-error
246+
248247
res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
249248
if not res["OK"]:
250249
return res
251-
DIRAC_TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
250+
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
252251
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
253252
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
254253
)
@@ -258,7 +257,7 @@ def doTheMagic(self):
258257
# TODO: "refresh_token_expires":
259258
"expires": expires.isoformat(),
260259
}
261-
DIRAC_TOKEN_FILE.write_text(json.dumps(credential_data))
260+
CREDENTIALS_PATH.write_text(json.dumps(credential_data))
262261

263262
return S_OK()
264263

0 commit comments

Comments
 (0)