Support filtering by image id or image tag when describing ecr images
This commit is contained in:
parent
b67e10d5c9
commit
3f20ad2c13
3 changed files with 71 additions and 5 deletions
|
|
@ -193,16 +193,27 @@ class ECRBackend(BaseBackend):
|
|||
images.append(image)
|
||||
return images
|
||||
|
||||
def describe_images(self, repository_name, registry_id=None, image_id=None):
|
||||
def describe_images(self, repository_name, registry_id=None, image_ids=None):
|
||||
|
||||
if repository_name in self.repositories:
|
||||
repository = self.repositories[repository_name]
|
||||
else:
|
||||
raise Exception("{0} is not a repository".format(repository_name))
|
||||
|
||||
response = []
|
||||
for image in repository.images:
|
||||
response.append(image)
|
||||
if image_ids:
|
||||
response = set()
|
||||
for image_id in image_ids:
|
||||
if 'imageDigest' in image_id:
|
||||
desired_digest = image_id['imageDigest']
|
||||
response.update([i for i in repository.images if i.get_image_digest() == desired_digest])
|
||||
if 'imageTag' in image_id:
|
||||
desired_tag = image_id['imageTag']
|
||||
response.update([i for i in repository.images if i.image_tag == desired_tag])
|
||||
else:
|
||||
response = []
|
||||
for image in repository.images:
|
||||
response.append(image)
|
||||
|
||||
return response
|
||||
|
||||
def put_image(self, repository_name, image_manifest, image_tag):
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ class ECRResponse(BaseResponse):
|
|||
def describe_images(self):
|
||||
repository_str = self._get_param('repositoryName')
|
||||
registry_id = self._get_param('registryId')
|
||||
images = self.ecr_backend.describe_images(repository_str, registry_id)
|
||||
image_ids = self._get_param('imageIds')
|
||||
images = self.ecr_backend.describe_images(repository_str, registry_id, image_ids)
|
||||
return json.dumps({
|
||||
'imageDetails': [image.response_describe_object for image in images],
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue