Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions .drone/build.sh
Original file line number Diff line number Diff line change
@@ -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
59 changes: 47 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,50 @@ 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: <token>" localhost:5000/me
./api
curl localhost:5000
```

## Configuration variables

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:
```
{ api } master » cat api.conf
# lines beggining with a "#" character are treated as comments
bind :5000
classic_registration false
force_colors false
log text

Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions env/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ type Flags struct {
ForceColors bool
EmailDomain string

SessionDuration int
ClassicRegistration bool
UsernameReservation bool
SessionDuration int

RedisAddress string
RedisDatabase int
Expand Down
18 changes: 7 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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() {
Expand All @@ -89,9 +87,7 @@ func main() {
ForceColors: *forceColors,
EmailDomain: *emailDomain,

SessionDuration: *sessionDuration,
ClassicRegistration: *classicRegistration,
UsernameReservation: *usernameReservation,
SessionDuration: *sessionDuration,

RedisAddress: *redisAddress,
RedisDatabase: *redisDatabase,
Expand Down
4 changes: 1 addition & 3 deletions routes/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func init() {
LogFormatterType: "text",
ForceColors: true,

SessionDuration: 72,
ClassicRegistration: true,
UsernameReservation: true,
SessionDuration: 72,

RedisAddress: "127.0.0.1:6379",

Expand Down
3 changes: 1 addition & 2 deletions setup/setup_test.go → setup/setup_test.go_
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Expand Down