From 72e91e3d62a11cfbdb4d29fa54ea31abb5aceed4 Mon Sep 17 00:00:00 2001 From: Ojakoo Date: Sun, 31 Jul 2022 16:28:57 +0300 Subject: [PATCH] Moved google creds to .env --- .gitignore | 3 +-- sikweb/settings.py | 2 ++ webapp/utils.py | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 2d24eaf..ab0875c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,5 +11,4 @@ node_modules/ .idea/ *.code-workspace venv/ -.venv/ -google-service-cred.json +.venv/ \ No newline at end of file diff --git a/sikweb/settings.py b/sikweb/settings.py index 24fea40..d635b4b 100644 --- a/sikweb/settings.py +++ b/sikweb/settings.py @@ -15,6 +15,7 @@ import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration from sikweb.base import * from datetime import timedelta +import json load_dotenv() # loads the configs from .env @@ -81,6 +82,7 @@ DATABASES = { # Google api settings GROUP_KEY = os.getenv("GROUP_KEY", "") +GOOGLE_SERVICE_ACCOUNT = json.loads(os.getenv("GOOGLE_CREDS_JSON", "")) # JWT authentication SIMPLE_JWT = { diff --git a/webapp/utils.py b/webapp/utils.py index fb944bd..8603d27 100644 --- a/webapp/utils.py +++ b/webapp/utils.py @@ -24,6 +24,7 @@ from sikweb.settings import ( DEFAULT_EMAIL_FROM_ADDR, ENABLE_AUTOMATIC_EMAILS, GROUP_KEY, + GOOGLE_SERVICE_ACCOUNT, ) from datetime import timedelta @@ -133,8 +134,8 @@ def add_to_mailinglist(email: str): # create credentials, with subject is used to impersonate admin account # jas_manager has groups editor rights in google admin - credentials = service_account.Credentials.from_service_account_file( - filename=SERVICE_ACCOUNT_FILE, scopes=SCOPES + credentials = service_account.Credentials.from_service_account_info( + info=GOOGLE_SERVICE_ACCOUNT, scopes=SCOPES ).with_subject("jas_manager@sahkoinsinoorikilta.fi") service = build("admin", "directory_v1", credentials=credentials)