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:
Ian Tempest 2023-03-30 08:40:57 +01:00 committed by GitHub
parent d07b50f755
commit 20ea1f43ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -318,6 +318,7 @@ class Image(BaseObject):
response_object["imageId"]["imageTag"] = self.image_tag response_object["imageId"]["imageTag"] = self.image_tag
response_object["imageId"]["imageDigest"] = self.get_image_digest() response_object["imageId"]["imageDigest"] = self.get_image_digest()
response_object["imageManifest"] = self.image_manifest response_object["imageManifest"] = self.image_manifest
response_object["imageManifestMediaType"] = self.image_manifest_mediatype
response_object["repositoryName"] = self.repository response_object["repositoryName"] = self.repository
response_object["registryId"] = self.registry_id response_object["registryId"] = self.registry_id
return { return {

View File

@ -56,7 +56,10 @@ class ECRResponse(BaseResponse):
repository_str = self._get_param("repositoryName") repository_str = self._get_param("repositoryName")
image_manifest = self._get_param("imageManifest") image_manifest = self._get_param("imageManifest")
image_tag = self._get_param("imageTag") 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}) return json.dumps({"image": image.response_object})

View File

@ -350,6 +350,52 @@ def test_put_image():
response["image"]["registryId"].should.equal(ACCOUNT_ID) 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() @mock_ecr()
def test_put_manifest_list(): def test_put_manifest_list():
client = boto3.client("ecr", region_name="us-east-1") client = boto3.client("ecr", region_name="us-east-1")