-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42f54c7
commit b3b6d4b
Showing
2 changed files
with
27 additions
and
27 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,44 +1,44 @@ | ||
import os | ||
from distutils.util import strtobool | ||
from google.cloud import secretmanager | ||
# from distutils.util import strtobool | ||
# from google.cloud import secretmanager | ||
|
||
class IBAccount(object): | ||
# Create the Secret Manager client. | ||
__client = None | ||
|
||
@classmethod | ||
def retrieve_secret(cls, secret_id): | ||
if not cls.__client: | ||
cls.__client = secretmanager.SecretManagerServiceClient() | ||
gcp_project_id = os.environ['GCP_PROJECT_ID'] | ||
name = cls.__client.secret_version_path(gcp_project_id, secret_id, 'latest') | ||
response = cls.__client.access_secret_version(name=name) | ||
payload = response.payload.data.decode('UTF-8') | ||
return payload | ||
# @classmethod | ||
# def retrieve_secret(cls, secret_id): | ||
# if not cls.__client: | ||
# cls.__client = secretmanager.SecretManagerServiceClient() | ||
# gcp_project_id = os.environ['GCP_PROJECT_ID'] | ||
# name = cls.__client.secret_version_path(gcp_project_id, secret_id, 'latest') | ||
# response = cls.__client.access_secret_version(name=name) | ||
# payload = response.payload.data.decode('UTF-8') | ||
# return payload | ||
|
||
@staticmethod | ||
def isEnabledGCPSecret(): | ||
try: | ||
return bool(strtobool(os.environ['GCP_SECRET'])) | ||
except ValueError: | ||
return False | ||
# @staticmethod | ||
# def isEnabledGCPSecret(): | ||
# try: | ||
# return bool(strtobool(os.environ['GCP_SECRET'])) | ||
# except ValueError: | ||
# return False | ||
|
||
@classmethod | ||
def account(cls): | ||
if not cls.isEnabledGCPSecret(): | ||
return os.environ['IB_ACCOUNT'] | ||
return cls.retrieve_secret(os.environ['GCP_SECRET_IB_ACCOUNT']) | ||
# if not cls.isEnabledGCPSecret(): | ||
return os.environ['IB_ACCOUNT'] | ||
# return cls.retrieve_secret(os.environ['GCP_SECRET_IB_ACCOUNT']) | ||
|
||
@classmethod | ||
def password(cls): | ||
if not cls.isEnabledGCPSecret(): | ||
return os.environ['IB_PASSWORD'] | ||
return cls.retrieve_secret(os.environ['GCP_SECRET_IB_PASSWORD']) | ||
# if not cls.isEnabledGCPSecret(): | ||
return os.environ['IB_PASSWORD'] | ||
# return cls.retrieve_secret(os.environ['GCP_SECRET_IB_PASSWORD']) | ||
|
||
@classmethod | ||
def trade_mode(cls): | ||
if not cls.isEnabledGCPSecret(): | ||
return os.environ['TRADE_MODE'] | ||
return cls.retrieve_secret(os.environ['GCP_SECRET_IB_TRADE_MODE']) | ||
# if not cls.isEnabledGCPSecret(): | ||
return os.environ['TRADE_MODE'] | ||
# return cls.retrieve_secret(os.environ['GCP_SECRET_IB_TRADE_MODE']) | ||
|
||
|