Skip to content

Commit

Permalink
google auth: rename env var to GOOGLE_CREDENTIALS_FILE
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Oct 7, 2024
1 parent 007536e commit 4207dd3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
24 changes: 12 additions & 12 deletions automon/integrations/google/auth/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def Credentials(self):
except:
pass

raise Exception(f'Missing GOOGLE_CREDENTIALS or GOOGLE_CREDENTIALS_BASE64')
raise Exception(f'Missing GOOGLE_CREDENTIALS_FILE or GOOGLE_CREDENTIALS_BASE64')

@property
def _GOOGLE_CREDENTIALS(self):
"""env var GOOGLE_CREDENTIALS"""
return environ('GOOGLE_CREDENTIALS')
def _GOOGLE_CREDENTIALS_FILE(self):
"""env var GOOGLE_CREDENTIALS_FILE"""
return environ('GOOGLE_CREDENTIALS_FILE')

@property
def _GOOGLE_CREDENTIALS_BASE64(self):
Expand All @@ -72,10 +72,10 @@ def _GOOGLE_CREDENTIALS_BASE64(self):

def CredentialsFile(self) -> google.oauth2.credentials.Credentials:
"""return Credentials object for web auth from file"""
if self._GOOGLE_CREDENTIALS:
if os.path.exists(self._GOOGLE_CREDENTIALS):
if self._GOOGLE_CREDENTIALS_FILE:
if os.path.exists(self._GOOGLE_CREDENTIALS_FILE):
return google.oauth2.credentials.Credentials.from_authorized_user_file(
self._GOOGLE_CREDENTIALS
self._GOOGLE_CREDENTIALS_FILE
)

def CredentialsInfo(self) -> google.oauth2.credentials.Credentials:
Expand All @@ -87,10 +87,10 @@ def CredentialsInfo(self) -> google.oauth2.credentials.Credentials:

def CredentialsServiceAccountFile(self) -> google.oauth2.service_account.Credentials:
"""return Credentials object for service account from file"""
if self._GOOGLE_CREDENTIALS:
if os.path.exists(self._GOOGLE_CREDENTIALS):
if self._GOOGLE_CREDENTIALS_FILE:
if os.path.exists(self._GOOGLE_CREDENTIALS_FILE):
return google.oauth2.service_account.Credentials.from_service_account_file(
self._GOOGLE_CREDENTIALS
self._GOOGLE_CREDENTIALS_FILE
)

def CredentialsServiceAccountInfo(self) -> google.oauth2.service_account.Credentials:
Expand All @@ -112,8 +112,8 @@ def base64_to_dict(self, base64_str: str = None) -> dict:

def file_to_base64(self, path: str = None):
"""convert file to base64"""
if not path and self._GOOGLE_CREDENTIALS:
path = self._GOOGLE_CREDENTIALS
if not path and self._GOOGLE_CREDENTIALS_FILE:
path = self._GOOGLE_CREDENTIALS_FILE

with open(path, 'rb') as f:
return base64.b64encode(f.read()).decode()
Expand Down
4 changes: 4 additions & 0 deletions env-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ GOOGLE_TOKEN_URI=
GOOGLE_PROJECT_ID=
GOOGLE_REFRESH_TOKEN=

GOOGLE_CREDENTIALS_FILE=
GOOGLE_CREDENTIALS_BASE64=
GOOGLE_SHEET_ID=

# Instagram
INSTAGRAM_LOGIN=
INSTAGRAM_PASSWORD=
Expand Down

0 comments on commit 4207dd3

Please sign in to comment.