owainlewis / digital-ocean Goto Github PK
View Code? Open in Web Editor NEWIdiomatic Clojure client for Digital Ocean that makes it easy to boot virtual servers from your REPL
Idiomatic Clojure client for Digital Ocean that makes it easy to boot virtual servers from your REPL
Hello!
Thanks for a great, simple library. It was a breeze to get started with, and I really like how extensible you've been able to make this.
I'm interested in spinning up a PostgreSQL cluster and managing it with the DigitalOcean API (see the API docs for managing databases). From my testing, retrieving available databases and a single one by ID works just as you've done for droplets:
;; in the bottom of digitalocean/v2/core.clj
(def databases
"Get all databases"
(generic :get :databases))
(def get-database
"Get a single database by ID"
databases)
Are you interested in supporting managing databases? If so, what are your requirements?
Teodor
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.
I would need this method https://developers.digitalocean.com/v1/events/
to automatically poll, if certain actions on the droplet finished.
(snapshotting, shutdown)
I use v2 librarz now, and want to pass ssh keys into the new-droplet method, like this:
(create-droplet "my tokem" nil {:name "test123":region "ams3" :size "512mb" :image 6373176 :ssh_keys [42250]})
{:id "unprocessable_entity", :message "You specified invalid ssh key ids for Droplet creation."}
but I always get the same error. It works with curl:
curl -X POST "https://api.digitalocean.com/v2/droplets" -d'{"name":"My-Droplet","region":"ams3","size":"512mb","image":6373176,"ssh_keys":[42550]}' -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json"
I tried all possible ways to encode the array of key ids, such as:
but without success. Using fingerprints does not work neither.
An idea what could be wrong ? Do you have a working example setting the ssh-keys ?
While debugging the code, I noticed that the "get-for" methods is calling the "request" method twice each time.
I cannot really judge the code, but I think the "->>>" macro calls "request" method twice, as the (request x y z) form gets assigned to ~response. So on evaluation of ~response (which appears twice in the macro for each execution path) it calls each time (request x y z) , which results in 2 requests to DigitalOcean
I know very little on clojure macros, but after putting debug output into the "request" method, I noticed that it gets called twice, by for example calling:
(get-for "droplets" "a" "b")
I noticed that it does not work with a http proxy.
I investigated a bit, a it seems that httpkit does not support a proxy at all:
and won´t do so in the near future.
This is for me a killer argument... All corporate environments use http proxies these days, so does mine.
So any web services / REST client API should support it.
As described here: http://blog.burkeware.com/2014/04/freezing-and-thawing-droplets-in-a-digitalocean/
This allows to have a single method which does the "freeze" of a droplet (including snapshotting) and "unfreeze" from a snapshot (including waiting)
I could eventually contribute this.
I would then have some questions to you:
1.) Would you agree to add this functionality to this project ?. In a certain sense it is a "higher level" API, as implementing "thaw" and "freeze" would be calling several low level methods.
2.) If 1. is yes, how would you suggest to make it work with "v1" and "v2" version of the API ? Or should we forget "V1" ?
3.) If 1. is "no" (which could be justified), we needed then to add one or two low-level API calls at least.
I did not check in details, but we might need look at the "Actions" API call to find out if a Snapshot is going on already. Eventually "waiting" for a state to arrive might need to be added as well. This is because I thought to implement "freeze" and "thaw" as synchronous methods, so they only come back if the action has finished, which can take minutes. (or is this a very bad idea ? I am a Clojure newbie ...)
Its called "destroy-droplet"
(def destroy-droplet (image-id-action "destroy"))
Should be probably "destroy-image".
calling it like this gives an error:
(snapshot-droplet client-id api-key 2611305 "gate-4")
UnknownFormatConversionException Conversion = '/' java.util.Formatter.checkText (Formatter.java:2547)
Looking at the code I saw that the syntax of the "format" string is wrong.
I'll send a PR
In this line
https://github.com/owainlewis/digital-ocean/blob/master/src/digitalocean/droplet.clj#L52
There is a pair of parentheses which creates an error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.