Skip to content

Commit

Permalink
refactor: take diracx token path from diracx
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Sep 5, 2023
1 parent 669de7e commit 5293e0d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def prepare_environment(

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

with _gen_docker_compose(modules) as docker_compose_fn:
# We cannot use the temporary directory created in the context manager because
Expand Down
12 changes: 5 additions & 7 deletions src/DIRAC/FrameworkSystem/scripts/dirac_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
from DIRAC.Core.Base.Client import Client


# token location
DIRAC_TOKEN_FILE = Path.home() / ".cache" / "diracx" / "credentials.json"
EXPIRES_GRACE_SECONDS = 15


# At this point, we disable CS synchronization so that an error related
# to the lack of a proxy certificate does not occur when trying to synchronize.
# Synchronization will take place after passing the authorization algorithm (creating a proxy).
Expand Down Expand Up @@ -320,10 +315,13 @@ def loginWithCertificate(self):

# Get a token for use with diracx
if os.getenv("DIRAC_ENABLE_DIRACX_LOGIN", "No").lower() in ("yes", "true"):
from diracx.cli import EXPIRES_GRACE_SECONDS
from diracx.cli.utils import CREDENTIALS_PATH

res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
if not res["OK"]:
return res
DIRAC_TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
)
Expand All @@ -333,7 +331,7 @@ def loginWithCertificate(self):
# TODO: "refresh_token_expires":
"expires": expires.isoformat(),
}
DIRAC_TOKEN_FILE.write_text(json.dumps(credential_data))
CREDENTIALS_PATH.write_text(json.dumps(credential_data))

return S_OK()

Expand Down
11 changes: 5 additions & 6 deletions src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
from pathlib import Path


DIRAC_TOKEN_FILE = Path.home() / ".cache" / "diracx" / "credentials.json"
EXPIRES_GRACE_SECONDS = 15


class Params(ProxyGeneration.CLIParams):
addVOMSExt = False
uploadProxy = True
Expand Down Expand Up @@ -245,10 +241,13 @@ def doTheMagic(self):
return resultProxyUpload

if os.getenv("DIRAC_ENABLE_DIRACX_LOGIN", "No").lower() in ("yes", "true"):
from diracx.cli import EXPIRES_GRACE_SECONDS
from diracx.cli.utils import CREDENTIALS_PATH

res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
if not res["OK"]:
return res
DIRAC_TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
)
Expand All @@ -258,7 +257,7 @@ def doTheMagic(self):
# TODO: "refresh_token_expires":
"expires": expires.isoformat(),
}
DIRAC_TOKEN_FILE.write_text(json.dumps(credential_data))
CREDENTIALS_PATH.write_text(json.dumps(credential_data))

return S_OK()

Expand Down

0 comments on commit 5293e0d

Please sign in to comment.