Support force flag in ecr.delete_repository (#4167)

This commit is contained in:
Anton Grübel 2021-08-12 14:08:28 +09:00 committed by GitHub
parent b8405b39b5
commit cbfb450430
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 3 deletions

View File

@ -399,10 +399,10 @@ class ECRBackend(BaseBackend):
return repository
def delete_repository(self, repository_name, registry_id=None):
def delete_repository(self, repository_name, registry_id=None, force=False):
repo = self._get_repository(repository_name, registry_id)
if repo.images:
if repo.images and not force:
raise RepositoryNotEmptyException(
repository_name, registry_id or DEFAULT_REGISTRY_ID
)

View File

@ -51,7 +51,11 @@ class ECRResponse(BaseResponse):
def delete_repository(self):
repository_str = self._get_param("repositoryName")
registry_id = self._get_param("registryId")
repository = self.ecr_backend.delete_repository(repository_str, registry_id)
force = self._get_param("force")
repository = self.ecr_backend.delete_repository(
repository_str, registry_id, force
)
return json.dumps({"repository": repository.response_object})
def put_image(self):

View File

@ -305,6 +305,38 @@ def test_delete_repository():
response["repositories"].should.have.length_of(0)
@mock_ecr
def test_delete_repository_with_force():
client = boto3.client("ecr", region_name="us-east-1")
repo_name = "test-repo"
client.create_repository(repositoryName=repo_name)
client.put_image(
repositoryName=repo_name,
imageManifest=json.dumps(_create_image_manifest()),
imageTag="latest",
)
# when
# when
response = client.delete_repository(repositoryName=repo_name, force=True)
# then
repo = response["repository"]
repo["repositoryName"].should.equal(repo_name)
repo["repositoryArn"].should.equal(
f"arn:aws:ecr:us-east-1:{ACCOUNT_ID}:repository/{repo_name}"
)
repo["registryId"].should.equal(ACCOUNT_ID)
repo["repositoryUri"].should.equal(
f"{ACCOUNT_ID}.dkr.ecr.us-east-1.amazonaws.com/{repo_name}"
)
repo["createdAt"].should.be.a(datetime)
repo["imageTagMutability"].should.equal("MUTABLE")
response = client.describe_repositories()
response["repositories"].should.have.length_of(0)
@mock_ecr
def test_put_image():
client = boto3.client("ecr", region_name="us-east-1")