diff --git a/Makefile b/Makefile deleted file mode 100644 index f0ef9e5ec6322965484b8b93cfbc53f3fd7d656a..0000000000000000000000000000000000000000 --- a/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -REBAR_VERSION := $(shell rebar3 --version 2>/dev/null) -ifdef REBAR_VERSION -REBAR := rebar3 -else -REBAR := $(CURDIR)/rebar3 -$(shell if ! [ -e "$(REBAR)" ]; then curl -jksSL -o $(REBAR) https://s3.amazonaws.com/rebar3/rebar3; chmod +x $(REBAR); fi) -endif - -all: eunit - -compile: - @$(REBAR) compile - -eunit: - $(REBAR) as test do eunit --cover --application=consul_proxy --dir=apps/consul_proxy/test, cover --verbose - -dialyzer: - @$(REBAR) dialyzer - -release: - @$(REBAR) release - -tarball: - @$(REBAR) as production do tar - -image: tarball - @REL_VSN=$(shell relinfo.escript -vsn _build/production/rel/consul_proxy/releases/RELEASES) envsubst '$$REL_VSN' < apps/consul_proxy/priv/Dockerfile > _build/production/Dockerfile - @docker build -t erlangninja/consul_proxy -f _build/production/Dockerfile _build/production - -edoc: - @$(REBAR) edoc - -clean: - @$(REBAR) clean - -distclean: - @rm -rf _build log $(REBAR) - -shell: - @$(REBAR) shell --config=config/test-sys.config - -genpasswd: - @go get golang.org/x/crypto/pbkdf2 - @go build -o _build/genpasswd scripts/genpasswd.go - -consul-backup: - @go get github.com/hashicorp/consul/api - @go get github.com/docopt/docopt-go - @go build -o _build/consul-backup scripts/consul-backup.go diff --git a/scripts/consul-backup.go b/scripts/consul-backup.go deleted file mode 100644 index 7c9cf0316b45e08c5cff82e5e69b3bec8d527729..0000000000000000000000000000000000000000 --- a/scripts/consul-backup.go +++ /dev/null @@ -1,173 +0,0 @@ -package main - -import ( - "fmt" - "sort" - "os" - "io/ioutil" - "strings" - "github.com/hashicorp/consul/api" - "github.com/docopt/docopt-go" - "encoding/base64" -) - - -//type KVPair struct { -// Key string -// CreateIndex uint64 -// ModifyIndex uint64 -// LockIndex uint64 -// Flags uint64 -// Value []byte -// Session string -//} - -type ByCreateIndex api.KVPairs - -func (a ByCreateIndex) Len() int { - return len(a) -} -func (a ByCreateIndex) Swap(i, j int) { - a[i], a[j] = a[j], a[i] -} -//Sort the KVs by createIndex -func (a ByCreateIndex) Less(i, j int) bool { - return a[i].CreateIndex < a[j].CreateIndex -} - -func backup(ipaddress string, token string, outfile string) { - - config := api.DefaultConfig() - config.Address = ipaddress - config.Token = token - - client, _ := api.NewClient(config) - kv := client.KV() - - pairs, _, err := kv.List("/", nil) - if err != nil { - panic(err) - } - - sort.Sort(ByCreateIndex(pairs)) - - outstring := "" - for _, element := range pairs { - encoded_value := base64.StdEncoding.EncodeToString(element.Value) - outstring += fmt.Sprintf("%s:%s\n", element.Key, encoded_value) - } - - file, err := os.Create(outfile) - if err != nil { - panic(err) - } - - if _, err := file.Write([]byte(outstring)[:]); err != nil { - panic(err) - } -} - -func backupAcls(ipaddress string, token string, outfile string) { - - config := api.DefaultConfig() - config.Address = ipaddress - config.Token = token - - client, _ := api.NewClient(config) - acl := client.ACL() - - tokens, _, err := acl.List(nil) - if err != nil { - panic(err) - } - // sort.Sort(ByCreateIndex(tokens)) - - outstring := "" - for _, element := range tokens { - // outstring += fmt.Sprintf("%s:%s:%s:%s\n", element.ID, element.Name, element.Type, element.Rules) - outstring += fmt.Sprintf("====\nID: %s\nName: %s\nType: %s\nRules:\n%s\n", element.ID, element.Name, element.Type, element.Rules) - } - - file, err := os.Create(outfile) - if err != nil { - panic(err) - } - - if _, err := file.Write([]byte(outstring)[:]); err != nil { - panic(err) - } -} - -/* File needs to be in the following format: - KEY1:VALUE1 - KEY2:VALUE2 -*/ -func restore(ipaddress string, token string, infile string) { - - config := api.DefaultConfig() - config.Address = ipaddress - config.Token = token - - data, err := ioutil.ReadFile(infile) - if err != nil { - panic(err) - } - - client, _ := api.NewClient(config) - kv := client.KV() - - for _, element := range strings.Split(string(data), "\n") { - kvp := strings.Split(element, ":") - - if len(kvp) > 1 { - decoded_value, decode_err := base64.StdEncoding.DecodeString(kvp[1]) - if decode_err != nil { - panic(decode_err) - } - - p := &api.KVPair{Key: kvp[0], Value: decoded_value} - _, err := kv.Put(p, nil) - if err != nil { - panic(err) - } - } - } -} - -func main() { - - usage := `Consul KV and ACL Backup with KV Restore tool. - -Usage: - consul-backup [-i IP:PORT] [-t TOKEN] [--aclbackup] [--aclbackupfile ACLBACKUPFILE] [--restore] <filename> - consul-backup -h | --help - consul-backup --version - -Options: - -h --help Show this screen. - --version Show version. - -i, --address=IP:PORT The HTTP endpoint of Consul [default: 127.0.0.1:8500]. - -t, --token=TOKEN An ACL Token with proper permissions in Consul [default: ]. - -a, --aclbackup Backup ACLs, does nothing in restore mode. ACL restore not available at this time. - -b, --aclbackupfile=ACLBACKUPFILE ACL Backup Filename [default: acl.bkp]. - -r, --restore Activate restore mode` - - arguments, _ := docopt.Parse(usage, nil, true, "consul-backup 1.0", false) - fmt.Println(arguments) - - if arguments["--restore"] == true { - fmt.Println("Restore mode:") - fmt.Printf("Warning! This will overwrite existing kv. Press [enter] to continue; CTL-C to exit") - fmt.Scanln() - fmt.Println("Restoring KV from file: ", arguments["<filename>"].(string)) - restore(arguments["--address"].(string), arguments["--token"].(string), arguments["<filename>"].(string)) - } else { - fmt.Println("Backup mode:") - fmt.Println("KV store will be backed up to file: ", arguments["<filename>"].(string)) - backup(arguments["--address"].(string), arguments["--token"].(string), arguments["<filename>"].(string)) - if arguments["--aclbackup"] == true { - fmt.Println("ACL Tokens will be backed up to file: ", arguments["--aclbackupfile"].(string)) - backupAcls(arguments["--address"].(string), arguments["--token"].(string), arguments["--aclbackupfile"].(string)) - } - } -} diff --git a/scripts/genpasswd.escript b/scripts/genpasswd.escript deleted file mode 100755 index 53e853889047717c7a6ac78c89db070ef7362b20..0000000000000000000000000000000000000000 --- a/scripts/genpasswd.escript +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env escript -%%! -pa ../_build/default/lib/pbkdf2/ebin -Wall - --define(PBKDF2_SALT_LENGTH, 16). --define(PBKDF2_ITERATIONS, 4096). --define(PBKDF2_DERIVED_LENGTH, 32). - --export([main/1]). - -main([Username, Password]) -> - try - Hash = base64:encode(hash(Password)), - io:format("~s:~s\n", [Username, Hash]) - catch - _:_ -> - usage() - end; - -main(_) -> - usage(). - -usage() -> - io:format("usage: genpasswd.escript username password\n"), - halt(1). - -hash(Password) when is_list(Password) -> - hash(list_to_binary(Password)); - -hash(Password) -> - Salt = crypto:strong_rand_bytes(?PBKDF2_SALT_LENGTH), - {ok, Hash} = pbkdf2:pbkdf2(sha512, Password, Salt, ?PBKDF2_ITERATIONS, ?PBKDF2_DERIVED_LENGTH), - <<Salt/binary, Hash/binary>>. diff --git a/scripts/genpasswd.go b/scripts/genpasswd.go deleted file mode 100644 index d8d81576c33977364407ea4c9ddaebeaf5c94b39..0000000000000000000000000000000000000000 --- a/scripts/genpasswd.go +++ /dev/null @@ -1,50 +0,0 @@ -package main - -import ( - "os" - "fmt" - "flag" - "crypto/rand" - "crypto/sha512" - "encoding/base64" - "golang.org/x/crypto/pbkdf2" -) - -func GenerateRandomBytes(n int) ([]byte, error) { - b := make([]byte, n) - _, err := rand.Read(b) - if err != nil { - return nil, err - } - return b, nil -} - -func main() { - - flag.Usage = func() { - fmt.Printf("Usage of %s:\n", os.Args[0]) - fmt.Printf(" genpasswd username passwd\n") - flag.PrintDefaults() - } - - flag.Parse() - if flag.NArg() == 0 { - flag.Usage() - os.Exit(1) - } - - username := []byte(os.Args[1]) - password := []byte(os.Args[2]) - salt, err := GenerateRandomBytes(16) - - if err != nil { - fmt.Printf("Failed to generate salt\n") - os.Exit(1) - } - - hash := pbkdf2.Key(password, salt, 4096, 32, sha512.New) - output := base64.StdEncoding.EncodeToString(append(salt,hash...)) - - fmt.Printf("%s:%s\n", username, output) - -}