Skip to content

Commit

Permalink
Pass credentials explicitly to GoogleSheets connector
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau committed Apr 22, 2024
1 parent a1c5267 commit 1183f86
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions parsons/google/google_sheets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import json
import logging

from parsons.etl.table import Table
from parsons.google.utilities import setup_google_application_credentials
import uuid

import gspread
from google.oauth2.service_account import Credentials

from parsons.etl.table import Table
from parsons.google.utilities import (
load_google_application_credentials,
setup_google_application_credentials,
)

logger = logging.getLogger(__name__)

Expand All @@ -32,14 +33,15 @@ def __init__(self, google_keyfile_dict=None, subject=None):
"https://www.googleapis.com/auth/drive",
]

setup_google_application_credentials(google_keyfile_dict, "GOOGLE_DRIVE_CREDENTIALS")
google_credential_file = open(os.environ["GOOGLE_DRIVE_CREDENTIALS"])
credentials_dict = json.load(google_credential_file)

credentials = Credentials.from_service_account_info(
credentials_dict, scopes=scope, subject=subject
env_credentials_path = str(uuid.uuid4())
setup_google_application_credentials(
google_keyfile_dict, "GOOGLE_DRIVE_CREDENTIAL", target_env_var_name=env_credentials_path
)

credentials = load_google_application_credentials(env_credentials_path)
credentials = credentials.with_scopes(scope)
credentials = credentials.with_subject(subject)

self.gspread_client = gspread.authorize(credentials)

def _get_worksheet(self, spreadsheet_id, worksheet=0):
Expand Down

0 comments on commit 1183f86

Please sign in to comment.