ecr.put_image - Support imageManifestMediaType parameter (issue 6135) (#6136)
* ecr.put_image - Support imageManifestMediaType parameter (issue 6135) * test_put_image_without_mediatype alternative error raised in server mode * Fix indentation in test_put_image_without_mediatype
This commit is contained in:
parent
d07b50f755
commit
20ea1f43ac
@ -318,6 +318,7 @@ class Image(BaseObject):
|
||||
response_object["imageId"]["imageTag"] = self.image_tag
|
||||
response_object["imageId"]["imageDigest"] = self.get_image_digest()
|
||||
response_object["imageManifest"] = self.image_manifest
|
||||
response_object["imageManifestMediaType"] = self.image_manifest_mediatype
|
||||
response_object["repositoryName"] = self.repository
|
||||
response_object["registryId"] = self.registry_id
|
||||
return {
|
||||
|
@ -56,7 +56,10 @@ class ECRResponse(BaseResponse):
|
||||
repository_str = self._get_param("repositoryName")
|
||||
image_manifest = self._get_param("imageManifest")
|
||||
image_tag = self._get_param("imageTag")
|
||||
image = self.ecr_backend.put_image(repository_str, image_manifest, image_tag)
|
||||
image_manifest_media_type = self._get_param("imageManifestMediaType")
|
||||
image = self.ecr_backend.put_image(
|
||||
repository_str, image_manifest, image_tag, image_manifest_media_type
|
||||
)
|
||||
|
||||
return json.dumps({"image": image.response_object})
|
||||
|
||||
|
@ -350,6 +350,52 @@ def test_put_image():
|
||||
response["image"]["registryId"].should.equal(ACCOUNT_ID)
|
||||
|
||||
|
||||
@mock_ecr
|
||||
def test_put_image_without_mediatype():
|
||||
client = boto3.client("ecr", region_name="us-east-1")
|
||||
_ = client.create_repository(repositoryName="test_repository")
|
||||
|
||||
image_manifest = _create_image_manifest()
|
||||
_ = image_manifest.pop("mediaType")
|
||||
|
||||
if os.environ.get("TEST_SERVER_MODE", "false").lower() == "true":
|
||||
with pytest.raises(ClientError):
|
||||
client.put_image(
|
||||
repositoryName="test_repository",
|
||||
imageManifest=json.dumps(image_manifest),
|
||||
imageTag="latest",
|
||||
)
|
||||
else:
|
||||
error_msg = "image manifest mediatype not provided in manifest or parameter"
|
||||
client.put_image.when.called_with(
|
||||
repositoryName="test_repository",
|
||||
imageManifest=json.dumps(image_manifest),
|
||||
imageTag="latest",
|
||||
).should.throw(Exception, error_msg)
|
||||
|
||||
|
||||
@mock_ecr
|
||||
def test_put_image_with_imagemanifestmediatype():
|
||||
client = boto3.client("ecr", region_name="us-east-1")
|
||||
_ = client.create_repository(repositoryName="test_repository")
|
||||
|
||||
image_manifest = _create_image_manifest()
|
||||
media_type = image_manifest.pop("mediaType")
|
||||
|
||||
response = client.put_image(
|
||||
repositoryName="test_repository",
|
||||
imageManifest=json.dumps(image_manifest),
|
||||
imageManifestMediaType=media_type,
|
||||
imageTag="latest",
|
||||
)
|
||||
|
||||
response["image"]["imageId"]["imageTag"].should.equal("latest")
|
||||
response["image"]["imageId"]["imageDigest"].should.contain("sha")
|
||||
response["image"]["repositoryName"].should.equal("test_repository")
|
||||
response["image"]["imageManifestMediaType"].should.equal(media_type)
|
||||
response["image"]["registryId"].should.equal(ACCOUNT_ID)
|
||||
|
||||
|
||||
@mock_ecr()
|
||||
def test_put_manifest_list():
|
||||
client = boto3.client("ecr", region_name="us-east-1")
|
||||
|
Loading…
Reference in New Issue
Block a user