diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..1f5f329 --- /dev/null +++ b/.drone.yml @@ -0,0 +1,32 @@ +image: registry.lavaboom.io/lavaboom/wrapper +env: + - GOPATH=/var/cache/drone +services: + - redis + - apcera/gnatsd + - dockerfile/rethinkdb +script: +# - sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 +# - sudo sh -c "echo deb https://get.docker.com/ubuntu docker main > /etc/apt/sources.list.d/docker.list" +# - sudo apt-get update +# - sudo apt-get install lxc-docker +# - sudo service docker start + - go get -t -v ./... + - go get golang.org/x/tools/cmd/cover + - go get github.com/mattn/goveralls + - GOMAXPROCS=4 go test -v github.com/lavab/api/setup + - GOMAXPROCS=4 go test -v -covermode=count -coverprofile=coverage.out github.com/lavab/api/routes + - /var/cache/drone/bin/goveralls -coverprofile=coverage.out -service=lavadrone -repotoken $COVERALLS_TOKEN + - "if [ \"$DRONE_BRANCH\" = \"master\" ]; then export CONTAINER_NAME=api-master; export CONTAINER_PORT=10000; fi" + - "if [ \"$DRONE_BRANCH\" = \"staging\" ]; then export CONTAINER_NAME=api-staging; export CONTAINER_PORT=10001; fi" + - "if [ \"$DRONE_BRANCH\" = \"develop\" ]; then export CONTAINER_NAME=api-develop; export CONTAINER_PORT=10002; fi" + - "if [ -n $CONTAINER_NAME ]; then chmod +x ./.drone/build.sh && ./.drone/build.sh; fi" + - "if [ -n $CONTAINER_NAME ]; then ssh -p 36412 root@lisa.lavaboom.io \"/opt/deploy/$CONTAINER_NAME.sh\"; fi" +notify: + slack: + - webhook_url: $$SLACK_URL + - channel: $$SLACK_CHANNEL + - username: lavadrone + - on_started: true + - on_success: true + - on_failure: true \ No newline at end of file diff --git a/.drone/build.sh b/.drone/build.sh new file mode 100644 index 0000000..3a50ee9 --- /dev/null +++ b/.drone/build.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -e + +wrapdocker & +sleep 5 + +docker login -e circleci@lavaboom.io -u $DOCKER_USER -p $DOCKER_PASS https://registry.lavaboom.io +docker build -t registry.lavaboom.io/lavaboom/$CONTAINER_NAME . +docker push registry.lavaboom.io/lavaboom/$CONTAINER_NAME \ No newline at end of file diff --git a/README.md b/README.md index 0750088..cbdb5a2 100644 --- a/README.md +++ b/README.md @@ -4,10 +4,8 @@ To install: ``` go get github.com/lavab/api -api -curl --data "username=abc&password=def" localhost:5000/signup -curl --data "username=abc&password=def" localhost:5000/login -curl --header "Auth: " localhost:5000/me +./api +curl localhost:5000 ``` ## Configuration variables @@ -15,23 +13,34 @@ curl --header "Auth: " localhost:5000/me You can use either commandline flags: ``` { api } master » ./api -help -Usage of api: +Usage of api + -api_version="v0": Shown API version -bind=":5000": Network address used to bind - -classic_registration=false: Classic registration enabled? + -config="": config file to load + -email_domain="lavaboom.io": Domain of the default email service + -etcd_address="": etcd peer addresses split by commas + -etcd_ca_file="": etcd path to server cert's ca + -etcd_cert_file="": etcd path to client cert file + -etcd_key_file="": etcd path to client key file + -etcd_path="settings/": Path of the keys -force_colors=false: Force colored prompt? -log="text": Log formatter type. Either "json" or "text" + -loggly_token="": Loggly token + -nats_address="nats://127.0.0.1:4222": Address of the NATS server + -redis_address="127.0.0.1:6379": Address of the redis server + -redis_db=0: Index of redis database to use + -redis_password="": Password of the redis server + -rethinkdb_address="127.0.0.1:28015": Address of the RethinkDB database -rethinkdb_db="dev": Database name on the RethinkDB server -rethinkdb_key="": Authentication key of the RethinkDB database - -rethinkdb_url="localhost:28015": Address of the RethinkDB database -session_duration=72: Session duration expressed in hours - -version="v0": Shown API version + -yubicloud_id="": YubiCloud API id + -yubicloud_key="": YubiCloud API key ``` Or environment variables: ``` -{ api } master » BIND=127.0.0.1:5000 CLASSIC_REGISTRATION=false \ -FORCE_COLORS=false LOG=text RETHINKDB_DB=dev RETHINKDB_KEY="" \ -RETHINKDB_URL=localhost:28015 SESSION_DURATION=72 VERSION=v0 ./api +{ api } master » BIND=127.0.0.1:6000 VERSION=v1 ./api ``` Or configuration files: @@ -39,7 +48,6 @@ Or configuration files: { api } master » cat api.conf # lines beggining with a "#" character are treated as comments bind :5000 -classic_registration false force_colors false log text @@ -54,6 +62,33 @@ version=v0 { api } master » ./api -config api.conf ``` +## Flags list + +| Flag or config variable name | Environment variable name | Default value | Description | +|:---------------------------- | ------------------------- | --------| ----- | +| api_version | `API_VERSION` | v0 | Shown API version | +| bind | `BIND` | 0.0.0.0:5000 | Network address used to bind | +| config | `CONFIG` | _empty_ | Config file to load | +| email_domain | `EMAIL_DOMAIN` | lavaboom.io | Domain of the default email service | +| etcd_address | `ETCD_ADDRESS` | _empty_ | etcd peer addresses split by commas | +| etcd_ca_file | `ETCD_CA_FILE` | _empty_ | etcd path to server cert's ca | +| etcd_cert_file | `ETCD_CERT_FILE` | _empty_ | etcd path to client cert file | +| etcd_key_file | `ETCD_KEY_FILE` | _empty_ | etcd path to client key file | +| etcd_path | `ETCD_PATH` | _empty_ | Path of the keys | +| force_colors | `FORCE_COLORS` | false | Force colored prompt? | +| log | `LOG` | text | Log formatter type. Either "json" or "text". | +| loggly_token | `LOGGLY_TOKEN` | _empty_ | Token used to connect to Loggly | +| nats_address | `NATS_ADDRESS` | nats://127.0.0.1:4222 | Address of the NATS server | +| redis_address | `REDIS_ADDRESS` | 127.0.0.1:6379 | Address of the redis server | +| redis_db | `REDIS_DB` | 0 | Index of redis database to use | +| redis_password | `REDIS_PASSWORD` | _empty_ | Password of the redis server | +| rethinkdb_address | `RETHINKDB_ADDRESS` | 127.0.0.1:28015 | Address of the RethinkDB database | +| rethinkdb_db | `RETHINKDB_DB` | dev |Database name on the RethinkDB server | +| rethinkdb_key | `RETHINKDB_KEY` | _empty_ | Authentication key of the RethinkDB database | +| session_duration | `SESSION_DURATION` | 72 | Session duration expressed in hours | +| yubicloud_id | `YUBICLOUD_ID` | _empty_ | YubiCloud API ID. | +| yubicloud_key | `YUBICLOUD_KEY` | _empty_ | YubiCloud API key. | + ## Build status: - `master` - [![Circle CI](https://circleci.com/gh/lavab/api/tree/master.svg?style=svg&circle-token=4a52d619a03d0249906195d6447ceb60a475c0c5)](https://circleci.com/gh/lavab/api/tree/master) [![Coverage Status](https://coveralls.io/repos/lavab/api/badge.svg?branch=master)](https://coveralls.io/r/lavab/api?branch=master) diff --git a/env/config.go b/env/config.go index 474ef19..311dd89 100644 --- a/env/config.go +++ b/env/config.go @@ -8,9 +8,7 @@ type Flags struct { ForceColors bool EmailDomain string - SessionDuration int - ClassicRegistration bool - UsernameReservation bool + SessionDuration int RedisAddress string RedisDatabase int diff --git a/main.go b/main.go index 4761cc8..60244ee 100644 --- a/main.go +++ b/main.go @@ -27,9 +27,7 @@ var ( forceColors = flag.Bool("force_colors", false, "Force colored prompt?") emailDomain = flag.String("email_domain", "lavaboom.io", "Domain of the default email service") // Registration settings - sessionDuration = flag.Int("session_duration", 72, "Session duration expressed in hours") - classicRegistration = flag.Bool("classic_registration", false, "Classic registration enabled?") - usernameReservation = flag.Bool("username_reservation", false, "Username reservation enabled?") + sessionDuration = flag.Int("session_duration", 72, "Session duration expressed in hours") // Cache-related flags redisAddress = flag.String("redis_address", func() string { address := os.Getenv("REDIS_PORT_6379_TCP_ADDR") @@ -70,11 +68,11 @@ var ( // 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") + 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() { @@ -89,9 +87,7 @@ func main() { ForceColors: *forceColors, EmailDomain: *emailDomain, - SessionDuration: *sessionDuration, - ClassicRegistration: *classicRegistration, - UsernameReservation: *usernameReservation, + SessionDuration: *sessionDuration, RedisAddress: *redisAddress, RedisDatabase: *redisDatabase, diff --git a/routes/init_test.go b/routes/init_test.go index d5619f7..c7b461b 100644 --- a/routes/init_test.go +++ b/routes/init_test.go @@ -23,9 +23,7 @@ func init() { LogFormatterType: "text", ForceColors: true, - SessionDuration: 72, - ClassicRegistration: true, - UsernameReservation: true, + SessionDuration: 72, RedisAddress: "127.0.0.1:6379", diff --git a/setup/setup_test.go b/setup/setup_test.go_ similarity index 90% rename from setup/setup_test.go rename to setup/setup_test.go_ index c455a0c..c10f95d 100644 --- a/setup/setup_test.go +++ b/setup/setup_test.go_ @@ -15,8 +15,7 @@ func TestSetup(t *testing.T) { LogFormatterType: "text", ForceColors: true, - SessionDuration: 72, - ClassicRegistration: true, + SessionDuration: 72, RedisAddress: "127.0.0.1:6379",