Skip to content

Commit

Permalink
write_credetials accepts a location
Browse files Browse the repository at this point in the history
  • Loading branch information
chaen committed Sep 29, 2023
1 parent 030b46d commit 98382ae
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/diracx/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import os
import re
from datetime import datetime, timedelta, timezone
from pathlib import Path

from diracx.core.models import TokenResponse

Expand All @@ -19,7 +20,7 @@ def dotenv_files_from_environment(prefix: str) -> list[str]:
return [v for _, v in sorted(env_files.items())]


def write_credentials(token_response: TokenResponse):
def write_credentials(token_response: TokenResponse, location: Path | None = None):
"""Write credentials received in dirax_preferences.credentials_path"""
from diracx.core.preferences import get_diracx_preferences

Expand All @@ -31,6 +32,6 @@ def write_credentials(token_response: TokenResponse):
"refresh_token": token_response.refresh_token,
"expires_on": int(datetime.timestamp(expires)),
}
credentials_path = get_diracx_preferences().credentials_path
credentials_path = location or get_diracx_preferences().credentials_path
credentials_path.parent.mkdir(parents=True, exist_ok=True)
credentials_path.write_text(json.dumps(credential_data))

0 comments on commit 98382ae

Please sign in to comment.