Skip to content

Commit 7c6372e

Browse files
committed
fix: use write_credentials() from diracx
1 parent 21634fb commit 7c6372e

File tree

3 files changed

+20
-25
lines changed

3 files changed

+20
-25
lines changed

src/DIRAC/FrameworkSystem/Service/ProxyManagerHandler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,6 @@ def export_exchangeProxyForToken(self):
440440
TokenResponse(
441441
access_token=create_token(payload, authSettings),
442442
expires_in=authSettings.access_token_expire_minutes * 60,
443-
state="None",
444443
).dict()
445444
)
446445
except Exception as e:

src/DIRAC/FrameworkSystem/scripts/dirac_login.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -315,23 +315,21 @@ def loginWithCertificate(self):
315315

316316
# Get a token for use with diracx
317317
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
318+
from diracx.core.utils import write_credentials # pylint: disable=import-error
319+
from diracx.core.models import TokenResponse # pylint: disable=import-error
320320

321321
res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
322322
if not res["OK"]:
323323
return res
324-
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
325-
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
326-
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
324+
token_content = res["Value"]
325+
write_credentials(
326+
TokenResponse(
327+
access_token=token_content["access_token"],
328+
expires_in=token_content["expires_in"],
329+
token_type=token_content.get("token_type"),
330+
refresh_token=token_content.get("refresh_token"),
331+
)
327332
)
328-
credential_data = {
329-
"access_token": res["Value"]["access_token"],
330-
# TODO: "refresh_token":
331-
# TODO: "refresh_token_expires":
332-
"expires": expires.isoformat(),
333-
}
334-
CREDENTIALS_PATH.write_text(json.dumps(credential_data))
335333

336334
return S_OK()
337335

src/DIRAC/FrameworkSystem/scripts/dirac_proxy_init.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,21 @@ def doTheMagic(self):
241241
return resultProxyUpload
242242

243243
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
244+
from diracx.core.utils import write_credentials # pylint: disable=import-error
245+
from diracx.core.models import TokenResponse # pylint: disable=import-error
246246

247247
res = Client(url="Framework/ProxyManager").exchangeProxyForToken()
248248
if not res["OK"]:
249249
return res
250-
CREDENTIALS_PATH.parent.mkdir(parents=True, exist_ok=True)
251-
expires = datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(
252-
seconds=res["Value"]["expires_in"] - EXPIRES_GRACE_SECONDS
250+
token_content = res["Value"]
251+
write_credentials(
252+
TokenResponse(
253+
access_token=token_content["access_token"],
254+
expires_in=token_content["expires_in"],
255+
token_type=token_content.get("token_type"),
256+
refresh_token=token_content.get("refresh_token"),
257+
)
253258
)
254-
credential_data = {
255-
"access_token": res["Value"]["access_token"],
256-
# TODO: "refresh_token":
257-
# TODO: "refresh_token_expires":
258-
"expires": expires.isoformat(),
259-
}
260-
CREDENTIALS_PATH.write_text(json.dumps(credential_data))
261259

262260
return S_OK()
263261

0 commit comments

Comments
 (0)