Skip to content

Commit

Permalink
fix: adapt get_credentials for filepaths
Browse files Browse the repository at this point in the history
  • Loading branch information
vncsna committed Oct 9, 2023
1 parent 77110c3 commit ad2b05b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
13 changes: 10 additions & 3 deletions basedosdados_api/api/v1/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import json
from json import loads
from pathlib import Path
from time import sleep

from django import forms
Expand Down Expand Up @@ -216,8 +217,14 @@ class CoverageTableInline(admin.StackedInline):

def get_credentials():
"""Get google cloud credentials"""
credentials_dict = json.loads(settings.GOOGLE_APPLICATION_CREDENTIALS)
credentials = service_account.Credentials.from_service_account_info(credentials_dict)
creds_env = settings.GOOGLE_APPLICATION_CREDENTIALS
try:
creds_path = Path(creds_env)
assert creds_path.is_absolute() or creds_path.is_relative_to('.')
credentials = service_account.Credentials.from_service_account_file(creds_path)
except (TypeError, ValueError):
credentials_dict = loads(creds_env)
credentials = service_account.Credentials.from_service_account_info(credentials_dict)
return credentials


Expand Down
3 changes: 3 additions & 0 deletions basedosdados_api/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@

# Logging
setup_logger(level="DEBUG", serialize=False)

# Google Application Credentials
GOOGLE_APPLICATION_CREDENTIALS = getenv("GOOGLE_APPLICATION_CREDENTIALS", "")

0 comments on commit ad2b05b

Please sign in to comment.