diff --git a/.gitignore b/.gitignore index 430c7d1..d342542 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ shaman dns *.cover config.json +build/ diff --git a/.travis.yml b/.travis.yml index 6e49533..c36218e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,4 +2,4 @@ language: go go: 1.6 install: go get -t -v . -script: go test -v ./... +script: go test -cover -v ./... diff --git a/README.md b/README.md index 12ef52d..24b44b0 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ [![shaman logo](http://nano-assets.gopagoda.io/readme-headers/shaman.png)](http://nanobox.io/open-source#shaman) [![Build Status](https://travis-ci.org/nanopack/shaman.svg)](https://travis-ci.org/nanopack/shaman) [![GoDoc](https://godoc.org/github.com/nanopack/shaman?status.svg)](https://godoc.org/github.com/nanopack/shaman) +[![Go Report Card](https://goreportcard.com/badge/github.com/nanopack/shaman)](https://goreportcard.com/report/github.com/nanopack/shaman) + # Shaman @@ -210,4 +212,8 @@ Fields: - Start Server Insecure +## Contributing +Contributions to shaman are welcome and encouraged. Shaman is a [Nanobox](https://nanobox.io) project and contributions should follow the [Nanobox Contribution Process & Guidelines](https://docs.nanobox.io/contributing/). + + [![oss logo](http://nano-assets.gopagoda.io/open-src/nanobox-open-src.png)](http://nanobox.io/open-source) diff --git a/api/api.go b/api/api.go index 6a20c19..69afd4e 100644 --- a/api/api.go +++ b/api/api.go @@ -1,4 +1,4 @@ -// Package "api" provides a restful interface to manage entries in the DNS database. +// Package api provides a restful interface to manage entries in the DNS database. package api import ( @@ -25,9 +25,9 @@ type ( ) var ( - auth nanoauth.Auth - badJson = errors.New("Bad JSON syntax received in body") - bodyReadFail = errors.New("Body Read Failed") + auth nanoauth.Auth + errBadJson = errors.New("Bad JSON syntax received in body") + errBodyReadFail = errors.New("Body Read Failed") ) // Start starts shaman's http api @@ -101,14 +101,14 @@ func parseBody(req *http.Request, v interface{}) error { b, err := ioutil.ReadAll(req.Body) if err != nil { config.Log.Error(err.Error()) - return bodyReadFail + return errBodyReadFail } defer req.Body.Close() // parse body and store in v err = json.Unmarshal(b, v) if err != nil { - return badJson + return errBadJson } return nil diff --git a/build.sh b/build.sh index 4fb0dc0..7b6969a 100755 --- a/build.sh +++ b/build.sh @@ -1,12 +1,32 @@ #!/usr/bin/env bash set -e +# for versioning +getCurrCommit() { + echo `git rev-parse HEAD | tr -d "[ \r\n\']"` +} + +# for versioning +getCurrTag() { + echo `git describe --always --tags --abbrev=0 | tr -d "[v\r\n]"` +} + +# for versioning +getCurrBranch() { + echo `git rev-parse --abbrev-ref HEAD | tr -d "[\r\n ]"` +} + +# for versioning +commit=$(getCurrCommit) +branch=$(getCurrBranch) +tag=$(getCurrTag) + # try and use the correct MD5 lib (depending on user OS darwin/linux) MD5=$(which md5 || which md5sum) # build shaman echo "Building SHAMAN and uploading it to 's3://tools.nanopack.io/shaman'" -gox -osarch "linux/amd64" -output="./build/{{.OS}}/{{.Arch}}/shaman" +gox -ldflags="-X main.version=${tag} -X main.branch=${branch} -X main.commit=${commit}" -osarch "linux/amd64" -output="./build/{{.OS}}/{{.Arch}}/shaman" # look through each os/arch/file and generate an md5 for each echo "Generating md5s..." diff --git a/cache/cache.go b/cache/cache.go index 1e13c49..4213261 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -1,4 +1,4 @@ -// Package "cache" provides a pluggable backend for persistant record storage. +// Package cache provides a pluggable backend for persistent record storage. package cache import ( @@ -11,8 +11,8 @@ import ( ) var ( - storage cacher - noRecordError = errors.New("No Record Found") + storage cacher + errNoRecordError = errors.New("No Record Found") ) // The cacher interface is what all the backends [will] implement @@ -26,7 +26,7 @@ type cacher interface { listRecords() ([]shaman.Resource, error) } -// Set default cacher and initialize it +// Initialize sets default cacher and initialize it func Initialize() error { u, err := url.Parse(config.L2Connect) if err != nil { @@ -54,7 +54,7 @@ func Initialize() error { return err } -// AddRecord adds a record to the persistant cache +// AddRecord adds a record to the persistent cache func AddRecord(resource *shaman.Resource) error { if storage == nil { return nil @@ -63,7 +63,7 @@ func AddRecord(resource *shaman.Resource) error { return storage.addRecord(resource) } -// GetRecord gets a record to the persistant cache +// GetRecord gets a record to the persistent cache func GetRecord(domain string) (*shaman.Resource, error) { if storage == nil { return nil, nil @@ -73,7 +73,7 @@ func GetRecord(domain string) (*shaman.Resource, error) { return storage.getRecord(domain) } -// UpdateRecord updates a record in the persistant cache +// UpdateRecord updates a record in the persistent cache func UpdateRecord(domain string, resource *shaman.Resource) error { if storage == nil { return nil @@ -83,7 +83,7 @@ func UpdateRecord(domain string, resource *shaman.Resource) error { return storage.updateRecord(domain, resource) } -// DeleteRecord removes a record from the persistant cache +// DeleteRecord removes a record from the persistent cache func DeleteRecord(domain string) error { if storage == nil { return nil @@ -92,7 +92,7 @@ func DeleteRecord(domain string) error { return storage.deleteRecord(domain) } -// ResetRecords replaces all records in the persistant cache +// ResetRecords replaces all records in the persistent cache func ResetRecords(resources *[]shaman.Resource) error { if storage == nil { return nil @@ -104,7 +104,7 @@ func ResetRecords(resources *[]shaman.Resource) error { return storage.resetRecords(resources) } -// ListRecords lists all records in the persistant cache +// ListRecords lists all records in the persistent cache func ListRecords() ([]shaman.Resource, error) { if storage == nil { return make([]shaman.Resource, 0), nil diff --git a/cache/cache_test.go b/cache/cache_test.go index 1efa882..3b27766 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -12,8 +12,8 @@ import ( ) var ( - nanopack = shaman.Resource{Domain: "nanopack.io.", Records: []shaman.Record{shaman.Record{Address: "127.0.0.1"}}} - nanobox = shaman.Resource{Domain: "nanobox.io.", Records: []shaman.Record{shaman.Record{Address: "127.0.0.2"}}} + nanopack = shaman.Resource{Domain: "nanopack.io.", Records: []shaman.Record{{Address: "127.0.0.1"}}} + nanobox = shaman.Resource{Domain: "nanobox.io.", Records: []shaman.Record{{Address: "127.0.0.2"}}} nanoBoth = []shaman.Resource{nanopack, nanobox} ) diff --git a/cache/scribble.go b/cache/scribble.go index 12f90d4..8799b07 100644 --- a/cache/scribble.go +++ b/cache/scribble.go @@ -49,7 +49,7 @@ func (self scribbleDb) getRecord(domain string) (*shaman.Resource, error) { err := self.db.Read("hosts", domain, &resource) if err != nil { if strings.Contains(err.Error(), "no such file or directory") { - err = noRecordError + err = errNoRecordError } return nil, err } diff --git a/commands/commands.go b/commands/commands.go index 43975bf..c33eaf2 100644 --- a/commands/commands.go +++ b/commands/commands.go @@ -1,4 +1,4 @@ -// Package "commands" provides the cli functionality. +// Package commands provides the cli functionality. // Runnable commands are: // add // get @@ -76,6 +76,7 @@ var ( full bool ) +// ResetVars resets the flag vars (used for testing) func ResetVars() { resource = shaman.Resource{} record = shaman.Record{} diff --git a/core/shaman.go b/core/shaman.go index 2f63c22..b8f5b37 100644 --- a/core/shaman.go +++ b/core/shaman.go @@ -11,6 +11,7 @@ import ( sham "github.com/nanopack/shaman/core/common" ) +// Answers is the cached collection of dns records var Answers map[string]sham.Resource func init() { @@ -127,7 +128,7 @@ func AddRecord(resource *sham.Resource) error { return nil } -// returns whether or not that domain exists +// Exists returns whether or not that domain exists func Exists(domain string) bool { sham.SanitizeDomain(&domain) _, ok := Answers[domain] diff --git a/core/shaman_test.go b/core/shaman_test.go index b1e5c17..24c8fd6 100644 --- a/core/shaman_test.go +++ b/core/shaman_test.go @@ -13,9 +13,9 @@ import ( ) var ( - nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.1"}}} - nanopack2 = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.3"}}} - nanobox = sham.Resource{Domain: "nanobox.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.2"}}} + nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.1"}}} + nanopack2 = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.3"}}} + nanobox = sham.Resource{Domain: "nanobox.io.", Records: []sham.Record{{Address: "127.0.0.2"}}} nanoBoth = []sham.Resource{nanopack, nanobox} ) diff --git a/main.go b/main.go index 72aae0a..56a80a5 100644 --- a/main.go +++ b/main.go @@ -90,7 +90,7 @@ func readConfig(ccmd *cobra.Command, args []string) error { func preFlight(ccmd *cobra.Command, args []string) error { if config.Version { - fmt.Printf("shaman %s\n", VERSION) + fmt.Printf("shaman %s (git: %s %s)\n", version, branch, commit) return fmt.Errorf("") } diff --git a/server/dns.go b/server/dns.go index 1b738b4..83ce2e2 100644 --- a/server/dns.go +++ b/server/dns.go @@ -94,7 +94,6 @@ func stripSubdomain(name string) string { // prevent searching for just 'com.' (["domain", "com", ""]) if len(names) > words { return strings.Join(names[1:], ".") - } else { - return "" } + return "" } diff --git a/server/dns_test.go b/server/dns_test.go index c011a33..27102d5 100644 --- a/server/dns_test.go +++ b/server/dns_test.go @@ -15,7 +15,7 @@ import ( "github.com/nanopack/shaman/server" ) -var nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{sham.Record{Address: "127.0.0.1"}}} +var nanopack = sham.Resource{Domain: "nanopack.io.", Records: []sham.Record{{Address: "127.0.0.1"}}} func TestMain(m *testing.M) { // manually configure diff --git a/version.go b/version.go index d2a9433..e8d6cfc 100644 --- a/version.go +++ b/version.go @@ -1,3 +1,9 @@ package main -const VERSION = "0.0.3" +// shaman version information (populated by go linker) +// -ldflags="-X main.version=${tag} -X main.branch=${branch} -X main.commit=${commit}" +var ( + version string + branch string + commit string +)