Skip to content

Commit

Permalink
Merge pull request #18 from nanopack/feature/unify-cli-server
Browse files Browse the repository at this point in the history
Feature/unify cli server
  • Loading branch information
notxarb committed Dec 29, 2015
2 parents 7844b74 + b16269a commit 9fa707c
Show file tree
Hide file tree
Showing 24 changed files with 231 additions and 239 deletions.
118 changes: 50 additions & 68 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,43 @@ Working
## Todo
- Logging
- Tests
- api
- cli
- Read configuration from file

## Server
```
Usage of ./shaman:
-address string
Listen address for DNS requests (default "127.0.0.1:8053")
-api-address string
Listen address for the API (default "127.0.0.1:8443")
-api-crt string
Path to SSL crt for API access
-api-key string
Path to SSL key for API access
-api-key-password string
Password for SSL key
-api-token string
Token for API Access
-domain string
Parent domain for requests (default "example.com")
-l1-connect string
Connection string for the l1 cache (default "map://127.0.0.1/")
-l1-expires int
TTL for the L1 Cache (0 = never expire) (default 120)
-l2-connect string
Connection string for the l2 cache (default "map://127.0.0.1/")
-l2-expires int
TTL for the L2 Cache (0 = never expire)
-log-file string
Log file (blank = log to console)
-log-level string
Log level to use (default "INFO")
-ttl int
Default TTL for DNS records (default 60)
Usage:
[flags]
[command]
Available Commands:
add Add entry into shaman database
remove Remove entry from shaman database
show Show entry in shaman database
update Update entry in shaman database
list List entries in shaman database
Flags:
-c, --api-crt="": Path to SSL crt for API access
-H, --api-host="127.0.0.1": Listen address for the API
-k, --api-key="": Path to SSL key for API access
-p, --api-key-password="": Password for SSL key
-P, --api-port="8443": Listen address for the API
-t, --api-token="": Token for API Access
-d, --domain=".": Parent domain for requests
-h, --help[=false]: help for
-O, --host="127.0.0.1": Listen address for DNS requests
-i, --insecure[=false]: Disable tls key checking
-1, --l1-connect="map://127.0.0.1/": Connection string for the l1 cache
-e, --l1-expires=120: TTL for the L1 Cache (0 = never expire)
-2, --l2-connect="map://127.0.0.1/": Connection string for the l2 cache
-E, --l2-expires=0: TTL for the L2 Cache (0 = never expire)
-l, --log-file="": Log file (blank = log to console)
-L, --log-level="INFO": Log level to use
-o, --port="8053": Listen port for DNS requests
-s, --server[=false]: Run in server mode
-T, --ttl=60: Default TTL for DNS records
Use " [command] --help" for more information about a command.
```
### L1 and L2 connection strings

Expand All @@ -62,6 +64,23 @@ The connection string looks like `redis://user:password@host:port/`. The user is
#### Scribble Cacher
The connection string looks like `scribble://localhost/path/to/data/store`. Scribble only cares about the path part of the URI to determine where it should place the files.

### Commands

#### add
`add [Record Type] [Domain] [Value]`

#### remove
`remove [Record Type] [Domain]`

#### show
`show [Record Type] [Domain]`

#### update
`update [Record Type] [Domain] [Value]`

#### list
`list`

## API
The API is a web based API. The API uses TLS and a token for security and authentication.

Expand All @@ -85,43 +104,6 @@ A `value` must be put. Currently it has to be past as a query string rather than
#### List
GET to `/records`

## CLI
```
Usage:
[command]
Available Commands:
add Add entry into shaman database
remove Remove entry from shaman database
show Show entry in shaman database
update Update entry in shaman database
list List entries in shaman database
Flags:
-A, --auth="": Shaman auth token
-h, --help[=false]: help for
-H, --host="127.0.0.1": Shaman hostname/IP
-i, --insecure[=false]: Disable tls key checking
-p, --port=8443: Shaman admin port
Use " [command] --help" for more information about a command.
```

#### add
`add [Record Type] [Domain] [Value]`

#### remove
`remove [Record Type] [Domain]`

#### show
`show [Record Type] [Domain]`

#### update
`update [Record Type] [Domain] [Value]`

#### list
`list`

### Notes

#### Using nslookup to test
Expand Down
7 changes: 5 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"net/http"

"github.com/gorilla/pat"
"github.com/miekg/dns"
nanoauth "github.com/nanobox-io/golang-nanoauth"

"github.com/nanopack/shaman/caches"
"github.com/nanopack/shaman/config"
"net/http"
)

var auth nanoauth.Auth
Expand All @@ -34,7 +36,8 @@ func StartApi() error {
}
auth.Certificate = cert
auth.Header = "X-NANOBOX-TOKEN"
return auth.ListenAndServeTLS(config.ApiAddress, config.ApiToken, routes())

return auth.ListenAndServeTLS(fmt.Sprintf("%s:%s", config.ApiHost, config.ApiPort), config.ApiToken, routes())
}

func routes() *pat.Router {
Expand Down
3 changes: 2 additions & 1 deletion caches/caches.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ package caches

import (
"fmt"
"github.com/nanopack/shaman/config"
"net/url"

"github.com/nanopack/shaman/config"
)

type Cacher interface {
Expand Down
6 changes: 4 additions & 2 deletions caches/caches_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package caches_test

import (
"os"
"testing"

"github.com/golang/mock/gomock"
"github.com/jcelliott/lumber"

"github.com/nanopack/shaman/caches"
"github.com/nanopack/shaman/caches/mock_caches"
"github.com/nanopack/shaman/config"
"os"
"testing"
)

func TestMain(m *testing.M) {
Expand Down
7 changes: 5 additions & 2 deletions caches/map_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ package caches
// - test
// - add routine for removing old data

import "time"
import "github.com/nanopack/shaman/config"
import (
"time"

"github.com/nanopack/shaman/config"
)

type mapCacher struct {
expires int
Expand Down
3 changes: 2 additions & 1 deletion caches/map_cacher_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package caches_test

import (
"github.com/nanopack/shaman/caches"
"testing"
"time"

"github.com/nanopack/shaman/caches"
)

func initializeMapCacher(expires int) caches.Cacher {
Expand Down
4 changes: 3 additions & 1 deletion caches/postgresql_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ package caches

import (
"database/sql"
"time"

_ "github.com/lib/pq"

"github.com/nanopack/shaman/config"
"time"
)

type postgresqlCacher struct {
Expand Down
3 changes: 2 additions & 1 deletion caches/postgresql_cacher_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package caches_test

import (
"github.com/nanopack/shaman/caches"
"testing"
"time"

"github.com/nanopack/shaman/caches"
)

func initializePostgresqlCacher(t *testing.T, expires int) caches.Cacher {
Expand Down
3 changes: 2 additions & 1 deletion caches/redis_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ package caches
// - test

import (
"github.com/garyburd/redigo/redis"
"net/url"
"time"

"github.com/garyburd/redigo/redis"
)

type redisCacher struct {
Expand Down
3 changes: 2 additions & 1 deletion caches/redis_cacher_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package caches_test

import (
"github.com/nanopack/shaman/caches"
"testing"
"time"

"github.com/nanopack/shaman/caches"
)

func initializeRedisCacher(t *testing.T, expires int) caches.Cacher {
Expand Down
6 changes: 4 additions & 2 deletions caches/scribble_cacher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ package caches

import (
"encoding/json"
scribble "github.com/nanobox-io/golang-scribble"
"github.com/nanopack/shaman/config"
"net/url"
"time"

scribble "github.com/nanobox-io/golang-scribble"

"github.com/nanopack/shaman/config"
)

type scribbleCacher struct {
Expand Down
3 changes: 2 additions & 1 deletion caches/scribble_cacher_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package caches_test

import (
"github.com/nanopack/shaman/caches"
"testing"
"time"

"github.com/nanopack/shaman/caches"
)

func initializeScribbleCacher(t *testing.T, expires int) caches.Cacher {
Expand Down
27 changes: 0 additions & 27 deletions cli/commands/commands.go

This file was deleted.

12 changes: 0 additions & 12 deletions cli/config/config.go

This file was deleted.

13 changes: 0 additions & 13 deletions cli/main.go

This file was deleted.

10 changes: 6 additions & 4 deletions cli/commands/add.go → commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"bytes"
"crypto/tls"
"fmt"
"github.com/nanopack/shaman/cli/config"
"github.com/spf13/cobra"
"io/ioutil"
"net/http"
"net/url"
"os"

"github.com/spf13/cobra"

"github.com/nanopack/shaman/config"
)

var addCmd = &cobra.Command{
Expand Down Expand Up @@ -45,14 +47,14 @@ func add(ccmd *cobra.Command, args []string) {
data := url.Values{}
data.Set("value", value)

uri := fmt.Sprintf("https://%s:%d/records/%s/%s?%s", config.Host, config.Port, rtype, domain, data.Encode())
uri := fmt.Sprintf("https://%s:%s/records/%s/%s?%s", config.ApiHost, config.ApiPort, rtype, domain, data.Encode())
fmt.Println(uri)
req, err := http.NewRequest("POST", uri, bytes.NewBufferString(data.Encode()))
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
os.Exit(1)
}
req.Header.Add("X-NANOBOX-TOKEN", config.AuthToken)
req.Header.Add("X-NANOBOX-TOKEN", config.ApiToken)
res, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
Expand Down
Loading

0 comments on commit 9fa707c

Please sign in to comment.