Skip to content

Commit

Permalink
Allow passing google auth Credentials directly to GCS connector
Browse files Browse the repository at this point in the history
  • Loading branch information
austinweisgrau committed Oct 10, 2024
1 parent 1642d6e commit aecaa84
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions parsons/google/google_cloud_storage.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import datetime
import gzip
import petl
import logging
import time
import uuid
import zipfile
from typing import Optional
from typing import Optional, Union

import google
import petl
from google.cloud import storage, storage_transfer
from google.oauth2.credentials import Credentials

from parsons.google.utilities import (
load_google_application_credentials,
Expand Down Expand Up @@ -45,10 +46,16 @@ class GoogleCloudStorage(object):
GoogleCloudStorage Class
"""

def __init__(self, app_creds=None, project=None):
env_credentials_path = str(uuid.uuid4())
setup_google_application_credentials(app_creds, target_env_var_name=env_credentials_path)
credentials = load_google_application_credentials(env_credentials_path)
def __init__(self, app_creds: Optional[Union[str, dict, Credentials]] = None, project=None):
if isinstance(app_creds, Credentials):
credentials = app_creds
else:
env_credentials_path = str(uuid.uuid4())
setup_google_application_credentials(
app_creds, target_env_var_name=env_credentials_path
)
credentials = load_google_application_credentials(env_credentials_path)

self.project = project

# Throws an error if you pass project=None, so adding if/else statement.
Expand Down

0 comments on commit aecaa84

Please sign in to comment.