diff --git a/lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb b/lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb new file mode 100644 index 000000000..876c823c1 --- /dev/null +++ b/lib/fog/digitalocean/requests/compute/destroy_ssh_key.rb @@ -0,0 +1,37 @@ +module Fog + module Compute + class DigitalOcean + class Real + + # + # Delete a SSH public key from your account + # + # @see https://www.digitalocean.com/api#ssh_keys + # + def destroy_ssh_key(id) + request( + :expects => [200], + :method => 'GET', + :path => "ssh_keys/#{id}/destroy" + ) + end + + end + + class Mock + + def destroy_ssh_key(id) + response = Excon::Response.new + response.status = 200 + if self.data[:ssh_keys].reject! { |k| k['id'] == id } + response.body = { "status" => "OK" } + else + response.body = { "status" => "ERROR" } + end + response + end + + end + end + end +end diff --git a/tests/digitalocean/requests/compute/destroy_ssh_key_tests.rb b/tests/digitalocean/requests/compute/destroy_ssh_key_tests.rb new file mode 100644 index 000000000..7e0388a77 --- /dev/null +++ b/tests/digitalocean/requests/compute/destroy_ssh_key_tests.rb @@ -0,0 +1,23 @@ +Shindo.tests('Fog::Compute[:digitalocean] | destroy_ssh_key request', ['digitalocean', 'compute']) do + + service = Fog::Compute[:digitalocean] + + tests('success') do + + test('#destroy_ssh_key') do + key = service.create_ssh_key 'fookey', 'fookey' + service.destroy_ssh_key(key.body['ssh_key']['id']).body['status'] == 'OK' + end + + end + + tests('failures') do + test 'delete invalid key' do + # DigitalOcean API returns 500 with this sometimes + # so mark it as pending in real mode + pending unless Fog.mocking? + service.destroy_ssh_key('00000000000').body['status'] == 'ERROR' + end + end + +end