Skip to content

Commit 1c62ef6

Browse files
authored
Revert "Include role path in get_execution_role() result (#268)"
This reverts commit 7c2073c.
1 parent 7c2073c commit 1c62ef6

File tree

3 files changed

+6
-36
lines changed

3 files changed

+6
-36
lines changed

CHANGELOG.rst

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
CHANGELOG
33
=========
44

5-
1.5.3dev
6-
========
7-
8-
* bug-fix: Session: include role path in ``get_execution_role()`` result
9-
105
1.5.2
116
=====
127

src/sagemaker/session.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,6 @@ def get_caller_identity_arn(self):
697697
return role
698698

699699
role = re.sub(r'^(.+)sts::(\d+):assumed-role/(.+?)/.*$', r'\1iam::\2:role/\3', assumed_role)
700-
701-
# Call IAM to get the role's path
702-
role_name = role[role.rfind('/') + 1:]
703-
role = self.boto_session.client('iam').get_role(RoleName=role_name)['Role']['Arn']
704-
705700
return role
706701

707702
def logs_for_job(self, job_name, wait=False, poll=10): # noqa: C901 - suppress complexity warning for this method

tests/unit/test_session.py

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_get_execution_role():
4141
assert actual == 'arn:aws:iam::369233609183:role/SageMakerRole'
4242

4343

44-
def test_get_execution_role_works_with_service_role():
44+
def test_get_execution_role_works_with_servie_role():
4545
session = Mock()
4646
session.get_caller_identity_arn.return_value = \
4747
'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
@@ -61,9 +61,7 @@ def test_get_execution_role_throws_exception_if_arn_is_not_role():
6161

6262
def test_get_caller_identity_arn_from_an_user(boto_session):
6363
sess = Session(boto_session)
64-
arn = 'arn:aws:iam::369233609183:user/mia'
65-
sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn}
66-
sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': arn}}
64+
sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': 'arn:aws:iam::369233609183:user/mia'}
6765

6866
actual = sess.get_caller_identity_arn()
6967
assert actual == 'arn:aws:iam::369233609183:user/mia'
@@ -74,37 +72,19 @@ def test_get_caller_identity_arn_from_a_role(boto_session):
7472
arn = 'arn:aws:sts::369233609183:assumed-role/SageMakerRole/6d009ef3-5306-49d5-8efc-78db644d8122'
7573
sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn}
7674

77-
expected_role = 'arn:aws:iam::369233609183:role/SageMakerRole'
78-
sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': expected_role}}
79-
8075
actual = sess.get_caller_identity_arn()
81-
assert actual == expected_role
76+
assert actual == 'arn:aws:iam::369233609183:role/SageMakerRole'
8277

8378

8479
def test_get_caller_identity_arn_from_a_execution_role(boto_session):
8580
sess = Session(boto_session)
8681
arn = 'arn:aws:sts::369233609183:assumed-role/AmazonSageMaker-ExecutionRole-20171129T072388/SageMaker'
8782
sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': arn}
88-
sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': arn}}
8983

9084
actual = sess.get_caller_identity_arn()
9185
assert actual == 'arn:aws:iam::369233609183:role/service-role/AmazonSageMaker-ExecutionRole-20171129T072388'
9286

9387

94-
def test_get_caller_identity_arn_from_role_with_path(boto_session):
95-
sess = Session(boto_session)
96-
arn_prefix = 'arn:aws:iam::369233609183:role'
97-
role_name = 'name'
98-
sess.boto_session.client('sts').get_caller_identity.return_value = {'Arn': '/'.join([arn_prefix, role_name])}
99-
100-
role_path = 'path'
101-
role_with_path = '/'.join([arn_prefix, role_path, role_name])
102-
sess.boto_session.client('iam').get_role.return_value = {'Role': {'Arn': role_with_path}}
103-
104-
actual = sess.get_caller_identity_arn()
105-
assert actual == role_with_path
106-
107-
10888
def test_delete_endpoint(boto_session):
10989
sess = Session(boto_session)
11090
sess.delete_endpoint('my_endpoint')
@@ -115,15 +95,15 @@ def test_delete_endpoint(boto_session):
11595
def test_s3_input_all_defaults():
11696
prefix = 'pre'
11797
actual = s3_input(s3_data=prefix)
118-
expected = {
119-
'DataSource': {
98+
expected = \
99+
{'DataSource': {
120100
'S3DataSource': {
121101
'S3DataDistributionType': 'FullyReplicated',
122102
'S3DataType': 'S3Prefix',
123103
'S3Uri': prefix
124104
}
125105
}
126-
}
106+
}
127107
assert actual.config == expected
128108

129109

0 commit comments

Comments
 (0)