Skip to content

Commit

Permalink
add start garbage collection and delete repository to the container r…
Browse files Browse the repository at this point in the history
…egistry API
  • Loading branch information
gregmolnar committed Oct 19, 2024
1 parent 2a7e6e1 commit 5644b00
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class ContainerRegistryRepositoryResource < ResourceKit::Resource
handler(204) { |response| true }
handler(400) { |response| ErrorMapping.fail_with(FailedDelete, response.body) }
end

action :delete, 'DELETE /v2/registry/:registry_name/repositories/:repository' do
handler(204) { |response| true }
handler(400) { |response| ErrorMapping.fail_with(FailedDelete, response.body) }
end
end

def all(*args)
Expand Down
4 changes: 4 additions & 0 deletions lib/droplet_kit/resources/container_registry_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class ContainerRegistryResource < ResourceKit::Resource
action :docker_credentials, 'GET /v2/registry/docker-credentials' do
handler(200) { |response| response.body }
end

action :start_garbage_collection, 'POST /v2/registry/garbage-collection' do
handler(201) { |response| response.body }
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@
expect(response).to be(true)
end
end

describe '#delete' do
it 'sends a delete request a repository' do
request = stub_do_api('/v2/registry/my-registry/repositories/my-repo', :delete).to_return(status: 204)
response = resource.delete(registry_name: 'my-registry', repository: 'my-repo')

expect(request).to have_been_made
expect(response).to be(true)
end
end
end
10 changes: 10 additions & 0 deletions spec/lib/droplet_kit/resources/container_registry_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,14 @@
)
end
end

describe '#start_garbage_collection' do
it 'sends a start garbage collection request for a registry' do
request = stub_do_api('/v2/registry/garbage-collection', :post).to_return(status: 201)
response = resource.start_garbage_collection

expect(request).to have_been_made
expect(response).to be_a(String)
end
end
end

0 comments on commit 5644b00

Please sign in to comment.