Change google creds format. Ugly but works.

This commit is contained in:
Ojakoo
2022-09-12 22:38:18 +03:00
parent 37a9750d4d
commit f0179c1840
5 changed files with 72 additions and 16 deletions
+8 -4
View File
@@ -25,7 +25,7 @@ from sikweb.settings import (
DEFAULT_EMAIL_FROM_ADDR,
ENABLE_AUTOMATIC_EMAILS,
GROUP_KEY,
GOOGLE_CREDS_JSON,
GOOGLE_CREDS,
)
from datetime import timedelta
@@ -136,13 +136,17 @@ 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_info(
info=GOOGLE_CREDS_JSON, scopes=SCOPES
info=GOOGLE_CREDS, scopes=SCOPES
).with_subject("jas_manager@sahkoinsinoorikilta.fi")
service = build("admin", "directory_v1", credentials=credentials)
service.members().insert(groupKey=GROUP_KEY, body={"email": email}).execute()
except HttpError as err:
# Already in list, do nothing
print()
print(err)
print()
if err.status_code == 409:
pass
else:
@@ -157,7 +161,7 @@ def add_to_mailinglist(email: str):
)
send_email(to, subject, body)
except ValueError as err:
""" except ValueError as err:
logging.exception("Formatting of google credentials is incorrect")
if DEPLOY_ENV == "production":
@@ -167,4 +171,4 @@ def add_to_mailinglist(email: str):
email
)
send_email(to, subject, body)
send_email(to, subject, body) """