Skip to content

Commit

Permalink
gcloud auth works in mysterious ways
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshitaB committed Oct 27, 2023
1 parent 528f2b1 commit ddd588e
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 17 deletions.
1 change: 0 additions & 1 deletion tango/integrations/beaker/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ def __init__(
self.google_token = f.read()

if self.google_token is None:
#else:
self.google_token = "default"

# Ensure entrypoint dataset exists.
Expand Down
13 changes: 0 additions & 13 deletions tango/integrations/gs/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,29 +409,20 @@ def get_credentials(credentials: Optional[Union[str, Credentials]] = None) -> Cr
"""

# BeakerExecutor uses GOOGLE_TOKEN
logger.error(f"Input credentials: {credentials}")
debug_env_var = os.environ.get("MY_DEBUG_ENV_VAR")
credentials = os.environ.get("GOOGLE_TOKEN", credentials)
logger.error(f"token: {os.environ.get('GOOGLE_TOKEN')}")
logger.error(f"Is google_token None: {os.environ.get('GOOGLE_TOKEN') is None}")
logger.error(f"Are credentials None: {credentials is None}")
logger.error(f"Debug env var: {debug_env_var}")
if credentials is not None:
# Path to the credentials file has been provided
if isinstance(credentials, str) and credentials.endswith(".json"):
with open(credentials) as file_ref:
credentials = file_ref.read()
logger.error(".json file path")
try:
# If credentials dict has been passed as a json string
credentials_dict = json.loads(credentials)
if credentials_dict.pop("type", None) == "service_account":
logger.error("service account")
credentials = ServiceAccountCredentials.from_service_account_info(credentials_dict)
else:
# sometimes the credentials dict may not contain `token` and `token_uri` keys,
# but `Credentials()` needs the parameter.
logger.error("oauth2 credentials")
token = credentials_dict.pop("token", None)
token_uri = credentials_dict.pop("token_uri", "https://oauth2.googleapis.com/token")
credentials = OAuth2Credentials(
Expand All @@ -440,11 +431,7 @@ def get_credentials(credentials: Optional[Union[str, Credentials]] = None) -> Cr
except (json.decoder.JSONDecodeError, TypeError, ValueError):
# It is not a json string.
# We use this string because BeakerExecutor cannot write a None secret.
import traceback
traceback.print_exc()
logger.error("credentials exception")
if credentials == "default":
logger.error("default credentials")
credentials = None
if not credentials:
# Infer default credentials
Expand Down
4 changes: 1 addition & 3 deletions tango/integrations/gs/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def __init__(
project: Optional[str] = None,
credentials: Optional[Union[str, Credentials]] = None,
):
credentials = credentials or get_credentials()
credentials = get_credentials(credentials)
self.client = get_client(folder_name=workspace, credentials=credentials, project=project)

self.client.NUM_CONCURRENT_WORKERS = self.NUM_CONCURRENT_WORKERS
Expand All @@ -84,8 +84,6 @@ def __init__(
project = project or self.client.storage.project or credentials.quota_project_id

self.bucket_name, self.prefix = get_bucket_and_prefix(workspace)
print(credentials)
print(f"Project: {project}")
self._ds = datastore.Client(
namespace=self.bucket_name, project=project, credentials=credentials
)
Expand Down

0 comments on commit ddd588e

Please sign in to comment.