14
14
# See the License for the specific language governing permissions and
15
15
# limitations under the License.
16
16
17
- from typing import Any , Dict , Optional
17
+ from typing import Dict , Optional
18
18
19
19
from ibm_cloud_sdk_core .token_managers .iam_token_manager import IAMTokenManager
20
20
21
21
from .iam_request_based_token_manager import IAMRequestBasedTokenManager
22
22
from ..private_helpers import _build_user_agent
23
23
24
24
25
+ # pylint: disable=too-many-instance-attributes
25
26
class IAMAssumeTokenManager (IAMRequestBasedTokenManager ):
26
27
"""The IAMAssumeTokenManager takes an api key and information about a trusted profile then performs the necessary
27
28
interactions with the IAM token service to obtain and store a suitable bearer token. This token "assumes" the
@@ -84,12 +85,9 @@ def __init__(
84
85
) -> None :
85
86
super ().__init__ (
86
87
url = url ,
87
- client_id = client_id ,
88
- client_secret = client_secret ,
89
88
disable_ssl_verification = disable_ssl_verification ,
90
89
headers = headers ,
91
90
proxies = proxies ,
92
- scope = scope ,
93
91
)
94
92
95
93
self .iam_profile_id = iam_profile_id
@@ -114,14 +112,6 @@ def __init__(
114
112
self .request_payload ['grant_type' ] = 'urn:ibm:params:oauth:grant-type:assume'
115
113
self ._set_user_agent (_build_user_agent ('iam-assume-authenticator' ))
116
114
117
- # Remove unsupported attributes, inherited from the parent class.
118
- def __getattribute__ (self , name : str ) -> Any :
119
- disallowed_attrs = ['refresh_token' , 'client_id' , 'client_secret' ]
120
- if name in disallowed_attrs :
121
- raise AttributeError (f"'{ self .__class__ .__name__ } ' has no attribute '{ name } '" )
122
-
123
- return super ().__getattribute__ (name )
124
-
125
115
def request_token (self ) -> Dict :
126
116
"""Retrieves a standard IAM access token by using the IAM token manager
127
117
then obtains another access token for the assumed identity.
@@ -140,4 +130,14 @@ def request_token(self) -> Dict:
140
130
self .request_payload ['profile_name' ] = self .iam_profile_name
141
131
self .request_payload ['account' ] = self .iam_account_id
142
132
133
+ # Make sure that the unsupported attributes will never be included in the requests.
134
+ self .client_id = None
135
+ self .client_secret = None
136
+ self .scope = None
137
+
143
138
return super ().request_token ()
139
+
140
+ def _save_token_info (self , token_response : Dict ) -> None :
141
+ super ()._save_token_info (token_response )
142
+ # Set refresh token to None unconditionally.
143
+ self .refresh_token = None
0 commit comments