Skip to content

Commit 872c678

Browse files
committed
fix: disable unsupported attributes in the new token manager class
Signed-off-by: Norbert Biczo <[email protected]>
1 parent 36425f9 commit 872c678

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

ibm_cloud_sdk_core/authenticators/iam_assume_authenticator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def __init__(
106106
def __getattribute__(self, name: str) -> Any:
107107
disallowed_attrs = ['set_scope', 'set_client_id_and_secret']
108108
if name in disallowed_attrs:
109-
raise AttributeError(f"'IAMAssumeAuthenticator' has no attribute '{name}'")
109+
raise AttributeError(f"'{self.__class__.__name__}' has no attribute '{name}'")
110110

111111
return super().__getattribute__(name)
112112

ibm_cloud_sdk_core/token_managers/iam_assume_token_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
from typing import Dict, Optional
17+
from typing import Any, Dict, Optional
1818

1919
from ibm_cloud_sdk_core.token_managers.iam_token_manager import IAMTokenManager
2020

@@ -114,6 +114,14 @@ def __init__(
114114
self.request_payload['grant_type'] = 'urn:ibm:params:oauth:grant-type:assume'
115115
self._set_user_agent(_build_user_agent('iam-assume-authenticator'))
116116

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+
117125
def request_token(self) -> Dict:
118126
"""Retrieves a standard IAM access token by using the IAM token manager
119127
then obtains another access token for the assumed identity.

test/test_iam_assume_token_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import urllib
2222

2323
import jwt
24+
import pytest
2425
import responses
2526

2627
from ibm_cloud_sdk_core import IAMAssumeTokenManager
@@ -190,3 +191,8 @@ def test_get_token():
190191

191192
# The final result should be the other access token, which belong to the "assume" request.
192193
assert access_token == OTHER_ACCESS_TOKEN
194+
195+
# Make sure `refresh_token` is not accessible.
196+
with pytest.raises(AttributeError) as err:
197+
assert token_manager.refresh_token == "not_available"
198+
assert str(err.value) == "'IAMAssumeTokenManager' has no attribute 'refresh_token'"

0 commit comments

Comments
 (0)