Skip to content

Commit 3fdef9a

Browse files
committed
Initial work to add TP support
1 parent a975107 commit 3fdef9a

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import logging
2+
import os
23

34
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
5+
from ibm_cloud_sdk_core.authenticators import ContainerAuthenticator
46

57
from cloud_governance.main.environment_variables import environment_variables
68

@@ -14,12 +16,21 @@ class IBMAuthenticator:
1416
def __init__(self):
1517
logging.disable(logging.DEBUG)
1618
self.env_config = environment_variables
17-
if hasattr(self.env_config, 'IBM_ACCOUNT_ID'):
18-
self.account_id = self.env_config.IBM_ACCOUNT_ID
19+
# if hasattr(self.env_config, 'IBM_ACCOUNT_ID'):
20+
# self.account_id = self.env_config.IBM_ACCOUNT_ID
21+
# else:
22+
# self.account_id = self.env_config.environment_variables_dict.get('IBM_ACCOUNT_ID')
23+
# if hasattr(self.env_config, 'IBM_CLOUD_API_KEY'):
24+
# self.__api_key = self.env_config.IBM_CLOUD_API_KEY
25+
# else:
26+
# self.__api_key = self.env_config.environment_variables_dict.get('IBM_CLOUD_API_KEY')
27+
# self.iam_authenticator = IAMAuthenticator(self.__api_key)
28+
29+
if hasattr(self.env_config, 'TRUSTED_PROFILE_NAME'):
30+
self.__trusted_profile_name = self.env_config.TRUSTED_PROFILE_NAME
1931
else:
20-
self.account_id = self.env_config.environment_variables_dict.get('IBM_ACCOUNT_ID')
21-
if hasattr(self.env_config, 'IBM_CLOUD_API_KEY'):
22-
self.__api_key = self.env_config.IBM_CLOUD_API_KEY
23-
else:
24-
self.__api_key = self.env_config.environment_variables_dict.get('IBM_CLOUD_API_KEY')
25-
self.iam_authenticator = IAMAuthenticator(self.__api_key)
32+
self.__trusted_profile_name = self.env_config.environment_variables_dict.get('TRUSTED_PROFILE_NAME')
33+
34+
35+
# create an authenticator based on a trusted profile
36+
self.iam_authenticator = ContainerAuthenticator(iam_profile_name=self.__trusted_profile_name)

cloud_governance/main/environment_variables.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ def __init__(self):
170170
'')
171171
self._environment_variables_dict['IBM_CLOUD_API_KEY'] = EnvironmentVariables.get_env('IBM_CLOUD_API_KEY', '')
172172

173+
self._environment_variables_dict['TRUSTED_PROFILE_NAME'] = EnvironmentVariables.get_env('TRUSTED_PROFILE_NAME',
174+
'')
175+
173176
if (self._environment_variables_dict['USAGE_REPORTS_APIKEY'] or
174177
self._environment_variables_dict['IBM_CLOUD_API_KEY'] or
175178
hasattr(self, "IBM_CLOUD_API_KEY")):

0 commit comments

Comments
 (0)