Support force flag in ecr.delete_repository (#4167)
This commit is contained in:
parent
b8405b39b5
commit
cbfb450430
@ -399,10 +399,10 @@ class ECRBackend(BaseBackend):
|
|||||||
|
|
||||||
return repository
|
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)
|
repo = self._get_repository(repository_name, registry_id)
|
||||||
|
|
||||||
if repo.images:
|
if repo.images and not force:
|
||||||
raise RepositoryNotEmptyException(
|
raise RepositoryNotEmptyException(
|
||||||
repository_name, registry_id or DEFAULT_REGISTRY_ID
|
repository_name, registry_id or DEFAULT_REGISTRY_ID
|
||||||
)
|
)
|
||||||
|
@ -51,7 +51,11 @@ class ECRResponse(BaseResponse):
|
|||||||
def delete_repository(self):
|
def delete_repository(self):
|
||||||
repository_str = self._get_param("repositoryName")
|
repository_str = self._get_param("repositoryName")
|
||||||
registry_id = self._get_param("registryId")
|
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})
|
return json.dumps({"repository": repository.response_object})
|
||||||
|
|
||||||
def put_image(self):
|
def put_image(self):
|
||||||
|
@ -305,6 +305,38 @@ def test_delete_repository():
|
|||||||
response["repositories"].should.have.length_of(0)
|
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
|
@mock_ecr
|
||||||
def test_put_image():
|
def test_put_image():
|
||||||
client = boto3.client("ecr", region_name="us-east-1")
|
client = boto3.client("ecr", region_name="us-east-1")
|
||||||
|
Loading…
Reference in New Issue
Block a user