Skip to content

Commit acce4d9

Browse files
pyrookarmkeezer
andcommitted
chore: address issues #1
Co-authored-by: Matthew Keezer <[email protected]>
1 parent 0795efa commit acce4d9

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

ibm_cloud_sdk_core/token_managers/vpc_instance_token_manager.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,9 @@ def request_token(self) -> dict:
8080
url = self.url + '/instance_identity/v1/iam_token'
8181

8282
if self.iam_profile_crn:
83-
request_payload = {
84-
'trusted_profile': '{{"crn": "{0}"}}'.format(self.iam_profile_crn)}
83+
request_payload = {'trusted_profile': {'crn': self.iam_profile_crn}}
8584
if self.iam_profile_id:
86-
request_payload = {
87-
'trusted_profile': '{{"id": "{0}"}}'.format(self.iam_profile_id)}
85+
request_payload = {'trusted_profile': {'id': self.iam_profile_id}}
8886

8987
headers = {
9088
'Content-Type': 'application/json',
@@ -133,7 +131,6 @@ def retrieve_instance_identity_token(self) -> str:
133131
url = self.url + '/instance_identity/v1/token'
134132

135133
headers = {
136-
'version': self.METADATA_SERVICE_VERSION,
137134
'Content-type': 'application/json',
138135
'Accept': 'application/json',
139136
'Metadata-Flavor': 'ibm',
@@ -147,6 +144,7 @@ def retrieve_instance_identity_token(self) -> str:
147144
method='PUT',
148145
url=url,
149146
headers=headers,
147+
params={'version': self.METADATA_SERVICE_VERSION},
150148
data=json.dumps(request_body))
151149
logging.debug('Returned from VPC \'create_access_token\' operation."')
152150

test/test_vpc_instance_token_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ def test_retrieve_instance_identity_token(caplog):
7676

7777
ii_token = token_manager.retrieve_instance_identity_token()
7878
assert len(responses.calls) == 1
79-
assert responses.calls[0].request.headers['version'] == '2021-09-20'
8079
assert responses.calls[0].request.headers['Content-Type'] == 'application/json'
8180
assert responses.calls[0].request.headers['Accept'] == 'application/json'
8281
assert responses.calls[0].request.headers['Metadata-Flavor'] == 'ibm'
82+
assert responses.calls[0].request.params['version'] == '2021-09-20'
8383
assert responses.calls[0].request.body == '{"expires_in": 300}'
8484
assert ii_token == TEST_TOKEN
8585
# Check the logs.
@@ -138,7 +138,7 @@ def mock_retrieve_instance_identity_token():
138138
assert responses.calls[0].request.headers['Content-Type'] == 'application/json'
139139
assert responses.calls[0].request.headers['Accept'] == 'application/json'
140140
assert responses.calls[0].request.headers['Authorization'] == 'Bearer ' + TEST_TOKEN
141-
assert responses.calls[0].request.body == '{"trusted_profile": "{\\"crn\\": \\"crn:iam-profile:123\\"}"}'
141+
assert responses.calls[0].request.body == '{"trusted_profile": {"crn": "crn:iam-profile:123"}}'
142142
assert responses.calls[0].request.params['version'] == '2021-09-20'
143143
# Check the logs.
144144
#pylint: disable=line-too-long
@@ -171,7 +171,7 @@ def mock_retrieve_instance_identity_token():
171171
assert responses.calls[0].request.headers['Content-Type'] == 'application/json'
172172
assert responses.calls[0].request.headers['Accept'] == 'application/json'
173173
assert responses.calls[0].request.headers['Authorization'] == 'Bearer ' + TEST_TOKEN
174-
assert responses.calls[0].request.body == '{"trusted_profile": "{\\"id\\": \\"iam-id-123\\"}"}'
174+
assert responses.calls[0].request.body == '{"trusted_profile": {"id": "iam-id-123"}}'
175175
assert responses.calls[0].request.params['version'] == '2021-09-20'
176176
# Check the logs.
177177
#pylint: disable=line-too-long

0 commit comments

Comments
 (0)