11import logging
2+ import os
23
34from ibm_cloud_sdk_core .authenticators import IAMAuthenticator
5+ from ibm_cloud_sdk_core .authenticators import ContainerAuthenticator
46
57from 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 )
0 commit comments