Skip to content

Commit

Permalink
Accept Hetzner API 404 for delete_key as success
Browse files Browse the repository at this point in the history
If it is gone, there's no need to halt execution.  This can cause CI
runs to fail, in the case where a key was deleted but, for one reason
or another, the deletion success was not recorded.

Perhaps our API should not inflict a similar damage on the consumer,
see
#597 (comment)
  • Loading branch information
fdr committed Dec 15, 2023
1 parent 41be4d0 commit 3c3dd8e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hosting/hetzner_apis.rb
Expand Up @@ -47,7 +47,7 @@ def delete_key(key)
user: @host.user,
password: @host.password,
headers: {"Content-Type" => "application/x-www-form-urlencoded"})
connection.delete(path: "/key/#{fingerprint}", expects: 200)
connection.delete(path: "/key/#{fingerprint}", expects: [200, 404])

nil
end
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/hosting/hetzner_apis_spec.rb
Expand Up @@ -64,6 +64,12 @@
Excon.stub({path: "/key/8003339382ac5baa3637f813becce5e4", method: :delete}, {status: 500, body: ""})
expect { hetzner_apis.delete_key(key_data) }.to raise_error Excon::Error::InternalServerError
end

it "regards a missing key as deleted" do
key_data = "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDQ8Z9Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0Z0"
Excon.stub({path: "/key/8003339382ac5baa3637f813becce5e4", method: :delete}, {status: 404, body: ""})
expect { hetzner_apis.delete_key(key_data) }.to be_nil
end
end

describe "get_main_ip4" do
Expand Down

0 comments on commit 3c3dd8e

Please sign in to comment.