Implement UserIds for Snapshot Attributes (#3192)
* implement register_image * format code * add user_ids to snapshot model * implement register_image * format code * add user_ids to snapshot model * trying to un-deprecate tests * Write tests and finalize implementation * Add region parameter to boto3 resource call * fixed test error
This commit is contained in:
parent
9a9a1d8413
commit
06ed67a8e5
4 changed files with 220 additions and 47 deletions
|
|
@ -2488,6 +2488,7 @@ class Snapshot(TaggedEC2Resource):
|
|||
self.description = description
|
||||
self.start_time = utc_date_and_time()
|
||||
self.create_volume_permission_groups = set()
|
||||
self.create_volume_permission_userids = set()
|
||||
self.ec2_backend = ec2_backend
|
||||
self.status = "completed"
|
||||
self.encrypted = encrypted
|
||||
|
|
@ -2652,28 +2653,32 @@ class EBSBackend(object):
|
|||
snapshot = self.get_snapshot(snapshot_id)
|
||||
return snapshot.create_volume_permission_groups
|
||||
|
||||
def add_create_volume_permission(self, snapshot_id, user_id=None, group=None):
|
||||
if user_id:
|
||||
self.raise_not_implemented_error(
|
||||
"The UserId parameter for ModifySnapshotAttribute"
|
||||
)
|
||||
|
||||
if group != "all":
|
||||
raise InvalidAMIAttributeItemValueError("UserGroup", group)
|
||||
def get_create_volume_permission_userids(self, snapshot_id):
|
||||
snapshot = self.get_snapshot(snapshot_id)
|
||||
snapshot.create_volume_permission_groups.add(group)
|
||||
return snapshot.create_volume_permission_userids
|
||||
|
||||
def add_create_volume_permission(self, snapshot_id, user_ids=None, groups=None):
|
||||
snapshot = self.get_snapshot(snapshot_id)
|
||||
if user_ids:
|
||||
snapshot.create_volume_permission_userids.update(user_ids)
|
||||
|
||||
if groups and groups != ["all"]:
|
||||
raise InvalidAMIAttributeItemValueError("UserGroup", groups)
|
||||
else:
|
||||
snapshot.create_volume_permission_groups.update(groups)
|
||||
|
||||
return True
|
||||
|
||||
def remove_create_volume_permission(self, snapshot_id, user_id=None, group=None):
|
||||
if user_id:
|
||||
self.raise_not_implemented_error(
|
||||
"The UserId parameter for ModifySnapshotAttribute"
|
||||
)
|
||||
|
||||
if group != "all":
|
||||
raise InvalidAMIAttributeItemValueError("UserGroup", group)
|
||||
def remove_create_volume_permission(self, snapshot_id, user_ids=None, groups=None):
|
||||
snapshot = self.get_snapshot(snapshot_id)
|
||||
snapshot.create_volume_permission_groups.discard(group)
|
||||
if user_ids:
|
||||
snapshot.create_volume_permission_userids.difference_update(user_ids)
|
||||
|
||||
if groups and groups != ["all"]:
|
||||
raise InvalidAMIAttributeItemValueError("UserGroup", groups)
|
||||
else:
|
||||
snapshot.create_volume_permission_groups.difference_update(groups)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -116,22 +116,23 @@ class ElasticBlockStore(BaseResponse):
|
|||
def describe_snapshot_attribute(self):
|
||||
snapshot_id = self._get_param("SnapshotId")
|
||||
groups = self.ec2_backend.get_create_volume_permission_groups(snapshot_id)
|
||||
user_ids = self.ec2_backend.get_create_volume_permission_userids(snapshot_id)
|
||||
template = self.response_template(DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE)
|
||||
return template.render(snapshot_id=snapshot_id, groups=groups)
|
||||
return template.render(snapshot_id=snapshot_id, groups=groups, userIds=user_ids)
|
||||
|
||||
def modify_snapshot_attribute(self):
|
||||
snapshot_id = self._get_param("SnapshotId")
|
||||
operation_type = self._get_param("OperationType")
|
||||
group = self._get_param("UserGroup.1")
|
||||
user_id = self._get_param("UserId.1")
|
||||
groups = self._get_multi_param("UserGroup")
|
||||
user_ids = self._get_multi_param("UserId")
|
||||
if self.is_not_dryrun("ModifySnapshotAttribute"):
|
||||
if operation_type == "add":
|
||||
self.ec2_backend.add_create_volume_permission(
|
||||
snapshot_id, user_id=user_id, group=group
|
||||
snapshot_id, user_ids=user_ids, groups=groups
|
||||
)
|
||||
elif operation_type == "remove":
|
||||
self.ec2_backend.remove_create_volume_permission(
|
||||
snapshot_id, user_id=user_id, group=group
|
||||
snapshot_id, user_ids=user_ids, groups=groups
|
||||
)
|
||||
return MODIFY_SNAPSHOT_ATTRIBUTE_RESPONSE
|
||||
|
||||
|
|
@ -311,18 +312,18 @@ DESCRIBE_SNAPSHOT_ATTRIBUTES_RESPONSE = """
|
|||
<DescribeSnapshotAttributeResponse xmlns="http://ec2.amazonaws.com/doc/2013-10-15/">
|
||||
<requestId>a9540c9f-161a-45d8-9cc1-1182b89ad69f</requestId>
|
||||
<snapshotId>snap-a0332ee0</snapshotId>
|
||||
{% if not groups %}
|
||||
<createVolumePermission/>
|
||||
{% endif %}
|
||||
{% if groups %}
|
||||
<createVolumePermission>
|
||||
{% for group in groups %}
|
||||
<item>
|
||||
<group>{{ group }}</group>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</createVolumePermission>
|
||||
{% endif %}
|
||||
<createVolumePermission>
|
||||
{% for group in groups %}
|
||||
<item>
|
||||
<group>{{ group }}</group>
|
||||
</item>
|
||||
{% endfor %}
|
||||
{% for userId in userIds %}
|
||||
<item>
|
||||
<userId>{{ userId }}</userId>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</createVolumePermission>
|
||||
</DescribeSnapshotAttributeResponse>
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue