Git Product home page Git Product logo

digital-ocean's Introduction

Digital-ocean

Clojure interface for Digital Ocean

[digitalocean "1.2"]

V2 API

Authentication

You can pass in an OAuth token directly to every function.

You can get a token from your Digital Ocean account user settings.

Getting started

(ns myproject
  (:require [digitalocean.v2.core :as do]))

(defonce token "YOURAUTHTOKEN")

Droplets

Get all droplets

(do/droplets token)

Get a droplet by ID

(do/get-droplet token 123)

Boot up a new droplet. All droplets require an image id to boot from.

Note that certain fields are required. See the Digital Ocean API V2 docs for all params

(do/create-droplet token nil
  {:name "ubuntu-s-1vcpu-2gb-lon1-01"
   :region "lon1"
   :size "s-1vcpu-2gb"
   :image "ubuntu-16-04-x64"
   :tags ["web"]
  })

Delete a droplet by ID

(do/delete-droplet token 123)

Domains

Get all

(do/domains token)

Get one domain by name

(do/get-domain token "fshionable.com")

Domain records

Get records for a domain

(do/records token "fshionable.com")

Images

Get all images

(do/images token)

Keys

;; Get all keys
(do/keys token)

;; Create a new one
(do/create-key token nil {
  :name "Blah"
  :public_key "Blah"})

Regions

Get all regions

(do/regions token)

Sizes

Get all sizes

(do/sizes token)

License

Copyright © 2014 Owain Lewis

Distributed under the Eclipse Public License, the same as Clojure.

digital-ocean's People

Contributors

behrica avatar garethr avatar owainlewis avatar teodorlu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

digital-ocean's Issues

Several methods in V1 making the API calls twice

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")

Library does not support http proxy

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:

http-kit/http-kit#75

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.

Q: Are you interested in supporting the v2 database API?

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

passing ssh_keys into create-droplet not working

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:

  • :ssh_keys [42250]
  • :ssh_keys "[42250]"
  • :ssh_keys ["42250"]
  • :ssh_keys "42250"

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 ?

Implementing "freeze" and "thaw" of droplets

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 ...)

snapshot-droplet in v1 does not work

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

Detecting wrong credentials in v1 API does not working

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.