From 1f6abb1e57770f5ba4fa13855904943cf4b141f0 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Tue, 6 Jan 2015 11:30:01 +0100 Subject: [PATCH 1/6] Error logging to the POST /accounts --- routes/accounts.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/routes/accounts.go b/routes/accounts.go index 824c30d..bf3ede9 100644 --- a/routes/accounts.go +++ b/routes/accounts.go @@ -85,6 +85,12 @@ func AccountsCreate(w http.ResponseWriter, r *http.Request) { if input.Username != "" { if used, err := env.Reservations.IsUsernameUsed(input.Username); err != nil || used { + if err != nil { + env.Log.WithFields(logrus.Fields{ + "error": err.Error(), + }).Error("Unable to lookup reservations for usernames") + } + utils.JSONResponse(w, 400, &AccountsCreateResponse{ Success: false, Message: "Username already reserved", @@ -93,6 +99,12 @@ func AccountsCreate(w http.ResponseWriter, r *http.Request) { } if used, err := env.Accounts.IsUsernameUsed(input.Username); err != nil || used { + if err != nil { + env.Log.WithFields(logrus.Fields{ + "error": err.Error(), + }).Error("Unable to lookup registered accounts for usernames") + } + utils.JSONResponse(w, 400, &AccountsCreateResponse{ Success: false, Message: "Username already used", From 2b533af08a092a8f5030b0c95694d53eb4ebc539 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Tue, 6 Jan 2015 11:36:51 +0100 Subject: [PATCH 2/6] Fixed database - i can't docker --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index db4f3e6..ef24573 100644 --- a/main.go +++ b/main.go @@ -49,7 +49,7 @@ var ( }(), "Address of the RethinkDB database") rethinkdbKey = flag.String("rethinkdb_key", os.Getenv("RETHINKDB_AUTHKEY"), "Authentication key of the RethinkDB database") rethinkdbDatabase = flag.String("rethinkdb_db", func() string { - database := os.Getenv("RETHINKDB_NAME") + database := os.Getenv("RETHINKDB_DB") if database == "" { database = "dev" } From 28fafd5f4f533a390d51041095d71a08ff7bcc81 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Wed, 7 Jan 2015 20:16:49 +0100 Subject: [PATCH 3/6] Changed flag package to lavab/flag --- main.go | 2 +- routes/hello.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index ef24573..763d413 100644 --- a/main.go +++ b/main.go @@ -7,7 +7,7 @@ import ( "github.com/Sirupsen/logrus" - "github.com/namsral/flag" + "github.com/lavab/flag" "github.com/zenazn/goji/graceful" "github.com/lavab/api/env" diff --git a/routes/hello.go b/routes/hello.go index 9185b48..20eb61d 100644 --- a/routes/hello.go +++ b/routes/hello.go @@ -18,7 +18,7 @@ type HelloResponse struct { func Hello(w http.ResponseWriter, r *http.Request) { utils.JSONResponse(w, 200, &HelloResponse{ Message: "Lavaboom API", - DocsURL: "http://lavaboom.readme.io/", + DocsURL: "https://docs.lavaboom.io/", Version: env.Config.APIVersion, }) } From 48cc58fab5218487f57bced079c5b87adeefa742 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 8 Jan 2015 15:40:18 +0100 Subject: [PATCH 4/6] Added etcd configuration support --- .config.toml | 2 ++ _vagrant/Vagrantfile | 20 +++++++++++++------- main.go | 6 ++++++ setup/setup.go | 45 -------------------------------------------- 4 files changed, 21 insertions(+), 52 deletions(-) create mode 100644 .config.toml diff --git a/.config.toml b/.config.toml new file mode 100644 index 0000000..23212e1 --- /dev/null +++ b/.config.toml @@ -0,0 +1,2 @@ +etcd-address http://127.0.0.1:4001 +etcd-path /settings/ diff --git a/_vagrant/Vagrantfile b/_vagrant/Vagrantfile index a540a0e..3608a75 100644 --- a/_vagrant/Vagrantfile +++ b/_vagrant/Vagrantfile @@ -19,7 +19,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| #rethinkdb.vm.provider "virtualbox" do |v| #v.memory = 2048 - #v.cpus = 4 + #v.cpus = 4y #end # load ansible playbook @@ -29,12 +29,14 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.define "docker" do |docker| docker.vm.box = "ubuntu/trusty64" - docker.vm.network "forwarded_port", guest: 4222, host: 4222 - docker.vm.network "forwarded_port", guest: 8333, host: 8333 - docker.vm.network "forwarded_port", guest: 6379, host: 6379 - docker.vm.network "forwarded_port", guest: 8080, host: 8080 - docker.vm.network "forwarded_port", guest: 28015, host: 28015 - docker.vm.network "forwarded_port", guest: 29015, host: 29015 + docker.vm.network "forwarded_port", guest: 4001, host: 4001 # etcd client + docker.vm.network "forwarded_port", guest: 4222, host: 4222 # nats #1 + docker.vm.network "forwarded_port", guest: 8333, host: 8333 # nats #2 + docker.vm.network "forwarded_port", guest: 6379, host: 6379 # redis + docker.vm.network "forwarded_port", guest: 7001, host: 7001 # etcd peer + docker.vm.network "forwarded_port", guest: 8080, host: 8080 # rethinkdb ui + docker.vm.network "forwarded_port", guest: 28015, host: 28015 # rethinkdb #1 + docker.vm.network "forwarded_port", guest: 29015, host: 29015 # rethinkdb #2 docker.vm.provider "virtualbox" do |v| v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] @@ -54,6 +56,10 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| d.pull_images "dockerfile/redis" d.run "dockerfile/redis", args: "--name redis -p 6379:6379" + + d.pull_images "quay.io/coreos/etcd:v0.4.6" + d.run "quay.io/coreos/etcd:v0.4.6", + args: "--name etcd -p 4001:4001 -p 7001:7001" end end end diff --git a/main.go b/main.go index 763d413..cb4eed3 100644 --- a/main.go +++ b/main.go @@ -68,6 +68,12 @@ var ( yubiCloudKey = flag.String("yubicloud_key", "", "YubiCloud API key") // Loggly URL logglyToken = flag.String("loggly_token", "", "Loggly token") + // etcd + etcdAddress = flag.String("etcd-address", "", "etcd peer addresses split by commas") + etcdCAFile = flag.String("etcd-ca-file", "", "etcd path to server cert's ca") + etcdCertFile = flag.String("etcd-cert-file", "", "etcd path to client cert file") + etcdKeyFile = flag.String("etcd-key-file", "", "etcd path to client key file") + etcdPath = flag.String("etcd-path", "settings/", "Path of the keys") ) func main() { diff --git a/setup/setup.go b/setup/setup.go index ecf750f..bcf241f 100644 --- a/setup/setup.go +++ b/setup/setup.go @@ -1,9 +1,7 @@ package setup import ( - "bufio" "encoding/json" - "io/ioutil" "net/http" "net/http/httptest" "strings" @@ -13,7 +11,6 @@ import ( "github.com/Sirupsen/logrus" "github.com/apcera/nats" "github.com/dancannon/gorethink" - "github.com/googollee/go-socket.io" "github.com/segmentio/go-loggly" "github.com/zenazn/goji/web" "github.com/zenazn/goji/web/middleware" @@ -369,48 +366,6 @@ func PrepareMux(flags *env.Flags) *web.Mux { mux.Get("/keys/:id", routes.KeysGet) auth.Post("/keys/:id/vote", routes.KeysVote) - // WebSockets handler - ws, err := socketio.NewServer(nil) - if err != nil { - env.Log.WithFields(logrus.Fields{ - "error": err, - }).Fatal("Unable to create a socket.io server") - } - ws.On("connection", func(so socketio.Socket) { - env.Log.WithFields(logrus.Fields{ - "id": so.Id(), - }).Info("New WebSockets connection") - - so.On("request", func(id string, method string, path string, data string, headers map[string]string) { - w := httptest.NewRecorder() - r, err := http.NewRequest(method, "http://api.lavaboom.io"+path, strings.NewReader(data)) - if err != nil { - so.Emit("error", err.Error()) - return - } - - for key, value := range headers { - r.Header.Set(key, value) - } - - mux.ServeHTTP(w, r) - - resp, err := http.ReadResponse(bufio.NewReader(w.Body), r) - if err != nil { - so.Emit("error", err.Error()) - return - } - - body, err := ioutil.ReadAll(resp.Body) - if err != nil { - so.Emit("error", err.Error()) - return - } - - so.Emit("response", id, resp.StatusCode, resp.Header, body) - }) - }) - mux.Handle("/ws/*", sockjs.NewHandler("/ws", sockjs.DefaultOptions, func(session sockjs.Session) { var subscribed string From 7404b6bd40e8c9125551556a8d915b30400deba7 Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 8 Jan 2015 17:58:39 +0100 Subject: [PATCH 5/6] Removed .config.toml --- .config.toml | 2 -- 1 file changed, 2 deletions(-) delete mode 100644 .config.toml diff --git a/.config.toml b/.config.toml deleted file mode 100644 index 23212e1..0000000 --- a/.config.toml +++ /dev/null @@ -1,2 +0,0 @@ -etcd-address http://127.0.0.1:4001 -etcd-path /settings/ From 585ef7f1c1c0c067d7c7a9874d68485ba3c77c2f Mon Sep 17 00:00:00 2001 From: Piotr Zduniak Date: Thu, 8 Jan 2015 18:07:20 +0100 Subject: [PATCH 6/6] Added AppData to accounts --- models/account.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/models/account.go b/models/account.go index a4ec101..bcb1ae5 100644 --- a/models/account.go +++ b/models/account.go @@ -39,6 +39,9 @@ type Account struct { FactorValue []string `json:"-" gorethink:"factor_value"` Status string `json:"status" gorethink:"status"` + + // AppData is used for clientside settings storage + AppData interface{} `json:"app_data" gorethink:"app_data"` } // SetPassword changes the account's password