Merge pull request #2158 from santoshankr/master
[iam] create_policy_version: Fix version id calculation
This commit is contained in:
commit
549f6d5d34
@ -48,7 +48,13 @@ class Policy(BaseModel):
|
|||||||
self.description = description or ''
|
self.description = description or ''
|
||||||
self.id = random_policy_id()
|
self.id = random_policy_id()
|
||||||
self.path = path or '/'
|
self.path = path or '/'
|
||||||
self.default_version_id = default_version_id or 'v1'
|
|
||||||
|
if default_version_id:
|
||||||
|
self.default_version_id = default_version_id
|
||||||
|
self.next_version_num = int(default_version_id.lstrip('v')) + 1
|
||||||
|
else:
|
||||||
|
self.default_version_id = 'v1'
|
||||||
|
self.next_version_num = 2
|
||||||
self.versions = [PolicyVersion(self.arn, document, True)]
|
self.versions = [PolicyVersion(self.arn, document, True)]
|
||||||
|
|
||||||
self.create_datetime = datetime.now(pytz.utc)
|
self.create_datetime = datetime.now(pytz.utc)
|
||||||
@ -716,7 +722,8 @@ class IAMBackend(BaseBackend):
|
|||||||
raise IAMNotFoundException("Policy not found")
|
raise IAMNotFoundException("Policy not found")
|
||||||
version = PolicyVersion(policy_arn, policy_document, set_as_default)
|
version = PolicyVersion(policy_arn, policy_document, set_as_default)
|
||||||
policy.versions.append(version)
|
policy.versions.append(version)
|
||||||
version.version_id = 'v{0}'.format(len(policy.versions))
|
version.version_id = 'v{0}'.format(policy.next_version_num)
|
||||||
|
policy.next_version_num += 1
|
||||||
if set_as_default:
|
if set_as_default:
|
||||||
policy.default_version_id = version.version_id
|
policy.default_version_id = version.version_id
|
||||||
return version
|
return version
|
||||||
|
@ -303,8 +303,17 @@ def test_create_policy_versions():
|
|||||||
PolicyDocument='{"some":"policy"}')
|
PolicyDocument='{"some":"policy"}')
|
||||||
version = conn.create_policy_version(
|
version = conn.create_policy_version(
|
||||||
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
|
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
|
||||||
PolicyDocument='{"some":"policy"}')
|
PolicyDocument='{"some":"policy"}',
|
||||||
|
SetAsDefault=True)
|
||||||
version.get('PolicyVersion').get('Document').should.equal({'some': 'policy'})
|
version.get('PolicyVersion').get('Document').should.equal({'some': 'policy'})
|
||||||
|
version.get('PolicyVersion').get('VersionId').should.equal("v2")
|
||||||
|
conn.delete_policy_version(
|
||||||
|
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
|
||||||
|
VersionId="v1")
|
||||||
|
version = conn.create_policy_version(
|
||||||
|
PolicyArn="arn:aws:iam::123456789012:policy/TestCreatePolicyVersion",
|
||||||
|
PolicyDocument='{"some":"policy"}')
|
||||||
|
version.get('PolicyVersion').get('VersionId').should.equal("v3")
|
||||||
|
|
||||||
|
|
||||||
@mock_iam
|
@mock_iam
|
||||||
|
Loading…
Reference in New Issue
Block a user