-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MRG: Merge pull request #133 from octue/release/0.1.13
Release/0.1.13
- Loading branch information
Showing
58 changed files
with
1,199 additions
and
527 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import logging | ||
|
||
from .cli import octue_cli | ||
from .logging_handlers import LOG_FORMAT | ||
from .runner import Runner | ||
|
||
|
||
__all__ = "LOG_FORMAT", "octue_cli", "Runner" | ||
__all__ = "LOG_FORMAT", "Runner" | ||
package_logger = logging.getLogger(__name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import json | ||
import logging | ||
import os | ||
import warnings | ||
from google.oauth2 import service_account | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class GCPCredentialsManager: | ||
"""A credentials manager for Google Cloud Platform (GCP) that takes a path to a service account JSON file, or a | ||
JSON string of the contents of such a service account file, from the given environment variable and instantiates | ||
a Google Cloud credentials object. | ||
:param str environment_variable_name: | ||
:return None: | ||
""" | ||
|
||
def __init__(self, environment_variable_name="GOOGLE_APPLICATION_CREDENTIALS"): | ||
self.environment_variable_name = environment_variable_name | ||
|
||
if self.environment_variable_name is None: | ||
self.service_account_json = None | ||
return | ||
|
||
try: | ||
self.service_account_json = os.environ[self.environment_variable_name] | ||
except KeyError: | ||
warnings.warn( | ||
f"No environment variable called {self.environment_variable_name!r}; resorting to default Google Cloud " | ||
f"credentials." | ||
) | ||
self.service_account_json = None | ||
|
||
def get_credentials(self): | ||
"""Get the Google OAUTH2 service account credentials. | ||
:return google.auth.service_account.Credentials: | ||
""" | ||
if self.service_account_json is None: | ||
return None | ||
|
||
# Check that the environment variable refers to a real file. | ||
if os.path.exists(self.service_account_json): | ||
return self._get_credentials_from_file() | ||
|
||
# If it doesn't, assume that it's the credentials file as a JSON string. | ||
return self._get_credentials_from_string() | ||
|
||
def _get_credentials_from_file(self): | ||
with open(self.service_account_json) as f: | ||
credentials = json.load(f) | ||
|
||
logger.debug("GCP credentials read from file.") | ||
return service_account.Credentials.from_service_account_info(credentials) | ||
|
||
def _get_credentials_from_string(self): | ||
credentials = json.loads(self.service_account_json) | ||
logger.debug("GCP credentials loaded from string.") | ||
return service_account.Credentials.from_service_account_info(credentials) |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from octue.cloud.storage import path | ||
from octue.cloud.storage.client import GoogleCloudStorageClient | ||
|
||
|
||
__all__ = ["path", "GoogleCloudStorageClient"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.