From a8feb005322a570719c4ebffcba3f2efda3662b8 Mon Sep 17 00:00:00 2001 From: Alexander Loechel Date: Tue, 23 Apr 2024 03:32:08 +0200 Subject: [PATCH] make credential_file depended on a path --- src/edutap/wallet_google/session.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/edutap/wallet_google/session.py b/src/edutap/wallet_google/session.py index 8ff97c2..a53de25 100644 --- a/src/edutap/wallet_google/session.py +++ b/src/edutap/wallet_google/session.py @@ -2,6 +2,7 @@ from dotenv import load_dotenv from google.auth.transport.requests import AuthorizedSession from google.oauth2.service_account import Credentials +from pathlib import Path from requests.adapters import HTTPAdapter import json @@ -59,8 +60,19 @@ def save_url(self) -> str: return self._save_url @property - def credentials_file(self) -> str | None: - return os.environ.get("EDUTAP_WALLET_GOOGLE_CREDENTIALS_FILE") + def credentials_file(self) -> Path | None: + if os.environ.get("EDUTAP_WALLET_GOOGLE_CREDENTIALS_FILE"): + path = Path( + Path(os.environ.get("CREDENTIAL_PATH", ".")) + / Path( + os.environ.get( + "EDUTAP_WALLET_GOOGLE_CREDENTIALS_FILE", "credential_file.json" + ) + ) + ) + if path.exists(): + return path + return None @property def credentials_info(self) -> dict[str, str]: