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 authored and chrisburr committed Oct 2, 2023
1 parent 39dd9d0 commit 263e0c7
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

Check warning on line 35 in src/diracx/core/utils.py

View check run for this annotation

Codecov / codecov/patch

src/diracx/core/utils.py#L35

Added line #L35 was not covered by tests
credentials_path.parent.mkdir(parents=True, exist_ok=True)
credentials_path.write_text(json.dumps(credential_data))

0 comments on commit 263e0c7

Please sign in to comment.