digital-ocean icon indicating copy to clipboard operation
digital-ocean copied to clipboard

Detecting wrong credentials in v1 API does not working

Open behrica opened this issue 11 years ago • 2 comments

Calling the methods (all probably) with wrong client id or api-key does not give an error, but returns nil. Example:

(images "wrong" "credentials")
=> nil

I debugged this and it looks like the eror detection does not work. In the case of wrong credentials the "error" variable is nil, as there is no "error" key in the "resp" response:

{:opts {:url https://api.digitalocean.com/images?client_id=asdadasd&api_key=asdasdasda, :method :get}, :body {"status":"ERROR","error_message":"Access Denied","message":"Access Denied"}, :headers {:status 401 Unauthorized, :cf-ray 16944c251322091a-CDG, :date Sat, 13 Sep 2014 12:20:12 GMT, :server cloudflare-nginx, :set-cookie __cfduid=d0b327a4dd476fc65c01880514eaf694b1410610811696; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.digitalocean.com; HttpOnly, :connection keep-alive, :cache-control no-cache, :x-request-id 4996bdea865b3983954dee40f509f5b5, :content-type application/json; charset=utf-8, :x-rack-cache miss, :x-runtime 0.009625, :transfer-encoding chunked}, :status 401}

This error could be detected by checking for http status 401.

behrica avatar Sep 13 '14 12:09 behrica

I went a bit more in detail.

This does not affect "all methods". It affects all methods which use the "get-for" methods. And those methods are the ones returning full list of ressources, so:

domains droplets all-images sizes ssh-keys

(not "regions", it does not use get-for)

The get-for method only returns an error, in case of low-level http errors (= Java exceptions during the call) In case of wrong credentials there is no Exception, just an http code of != 200.

behrica avatar Sep 13 '14 16:09 behrica

I am not sure, how the methods returning lists should behave in case of http != 200 errors.

In case of http Exceptions they return a map, with a key "error"

{:error #<UnknownHostException java.net.UnknownHostException: aaaapi.digitalocean.com>}

the other methods return a map like this:

{:status "ERROR", :error_message "Access Denied", :message "Access Denied"}

which is the direct response from digital ocean API.

behrica avatar Sep 13 '14 17:09 behrica