├── .gitignore ├── .travis.yml ├── Dockerfile ├── README.md ├── cmd ├── export.go ├── import.go └── json.go ├── go.mod ├── go.sum ├── it └── integration_test.go ├── main.go ├── makefile ├── vault └── client.go └── vendor ├── github.com ├── fatih │ └── structs │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── field.go │ │ ├── structs.go │ │ └── tags.go ├── golang │ └── snappy │ │ ├── .gitignore │ │ ├── AUTHORS │ │ ├── CONTRIBUTORS │ │ ├── LICENSE │ │ ├── README │ │ ├── decode.go │ │ ├── decode_amd64.go │ │ ├── decode_amd64.s │ │ ├── decode_other.go │ │ ├── encode.go │ │ ├── encode_amd64.go │ │ ├── encode_amd64.s │ │ ├── encode_other.go │ │ └── snappy.go ├── hashicorp │ ├── errwrap │ │ ├── LICENSE │ │ ├── README.md │ │ └── errwrap.go │ ├── go-cleanhttp │ │ ├── LICENSE │ │ ├── README.md │ │ ├── cleanhttp.go │ │ ├── doc.go │ │ └── handlers.go │ ├── go-multierror │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── append.go │ │ ├── flatten.go │ │ ├── format.go │ │ ├── multierror.go │ │ └── prefix.go │ ├── go-rootcerts │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── doc.go │ │ ├── rootcerts.go │ │ ├── rootcerts_base.go │ │ └── rootcerts_darwin.go │ ├── hcl │ │ ├── .gitignore │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── Makefile │ │ ├── README.md │ │ ├── appveyor.yml │ │ ├── decoder.go │ │ ├── hcl.go │ │ ├── hcl │ │ │ ├── ast │ │ │ │ ├── ast.go │ │ │ │ └── walk.go │ │ │ ├── parser │ │ │ │ ├── error.go │ │ │ │ └── parser.go │ │ │ ├── scanner │ │ │ │ └── scanner.go │ │ │ ├── strconv │ │ │ │ └── quote.go │ │ │ └── token │ │ │ │ ├── position.go │ │ │ │ └── token.go │ │ ├── json │ │ │ ├── parser │ │ │ │ ├── flatten.go │ │ │ │ └── parser.go │ │ │ ├── scanner │ │ │ │ └── scanner.go │ │ │ └── token │ │ │ │ ├── position.go │ │ │ │ └── token.go │ │ ├── lex.go │ │ └── parse.go │ └── vault │ │ ├── LICENSE │ │ ├── api │ │ ├── auth.go │ │ ├── auth_token.go │ │ ├── client.go │ │ ├── help.go │ │ ├── logical.go │ │ ├── renewer.go │ │ ├── request.go │ │ ├── response.go │ │ ├── secret.go │ │ ├── ssh.go │ │ ├── ssh_agent.go │ │ ├── sys.go │ │ ├── sys_audit.go │ │ ├── sys_auth.go │ │ ├── sys_capabilities.go │ │ ├── sys_config_cors.go │ │ ├── sys_generate_root.go │ │ ├── sys_health.go │ │ ├── sys_init.go │ │ ├── sys_leader.go │ │ ├── sys_leases.go │ │ ├── sys_mounts.go │ │ ├── sys_policy.go │ │ ├── sys_rekey.go │ │ ├── sys_rotate.go │ │ ├── sys_seal.go │ │ └── sys_stepdown.go │ │ └── helper │ │ ├── compressutil │ │ └── compress.go │ │ ├── jsonutil │ │ └── json.go │ │ └── parseutil │ │ └── parseutil.go ├── mitchellh │ ├── go-homedir │ │ ├── LICENSE │ │ ├── README.md │ │ └── homedir.go │ └── mapstructure │ │ ├── .travis.yml │ │ ├── LICENSE │ │ ├── README.md │ │ ├── decode_hooks.go │ │ ├── error.go │ │ └── mapstructure.go └── sethgrid │ └── pester │ ├── LICENSE.md │ ├── README.md │ └── pester.go ├── golang.org └── x │ ├── net │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── http │ │ └── httpguts │ │ │ ├── guts.go │ │ │ └── httplex.go │ ├── http2 │ │ ├── .gitignore │ │ ├── Dockerfile │ │ ├── Makefile │ │ ├── README │ │ ├── ciphers.go │ │ ├── client_conn_pool.go │ │ ├── configure_transport.go │ │ ├── databuffer.go │ │ ├── errors.go │ │ ├── flow.go │ │ ├── frame.go │ │ ├── go111.go │ │ ├── go16.go │ │ ├── go17.go │ │ ├── go17_not18.go │ │ ├── go18.go │ │ ├── go19.go │ │ ├── gotrack.go │ │ ├── headermap.go │ │ ├── hpack │ │ │ ├── encode.go │ │ │ ├── hpack.go │ │ │ ├── huffman.go │ │ │ └── tables.go │ │ ├── http2.go │ │ ├── not_go111.go │ │ ├── not_go16.go │ │ ├── not_go17.go │ │ ├── not_go18.go │ │ ├── not_go19.go │ │ ├── pipe.go │ │ ├── server.go │ │ ├── transport.go │ │ ├── write.go │ │ ├── writesched.go │ │ ├── writesched_priority.go │ │ └── writesched_random.go │ └── idna │ │ ├── idna.go │ │ ├── punycode.go │ │ ├── tables.go │ │ ├── trie.go │ │ └── trieval.go │ └── text │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ ├── secure │ └── bidirule │ │ ├── bidirule.go │ │ ├── bidirule10.0.0.go │ │ └── bidirule9.0.0.go │ ├── transform │ └── transform.go │ └── unicode │ ├── bidi │ ├── bidi.go │ ├── bracket.go │ ├── core.go │ ├── gen.go │ ├── gen_ranges.go │ ├── gen_trieval.go │ ├── prop.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ └── trieval.go │ └── norm │ ├── composition.go │ ├── forminfo.go │ ├── input.go │ ├── iter.go │ ├── maketables.go │ ├── normalize.go │ ├── readwriter.go │ ├── tables10.0.0.go │ ├── tables9.0.0.go │ ├── transform.go │ ├── trie.go │ └── triegen.go └── modules.txt /.gitignore: -------------------------------------------------------------------------------- 1 | bin/* 2 | *.json 3 | vault-backend-migrator 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | sudo: required 3 | 4 | os: 5 | - linux 6 | - osx 7 | 8 | go: 9 | - 1.12.x 10 | - 1.13.x 11 | 12 | matrix: 13 | fast_finish: true 14 | 15 | script: 16 | - make ci 17 | 18 | services: 19 | - docker 20 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | COPY bin/vault-backend-migrator-linux-amd64 /bin/vault-backend-migrator 3 | ENTRYPOINT ["/bin/vault-backend-migrator"] 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## vault-backend-migrator 2 | 3 | `vault-backend-migrator` is a tool to export and import (migrate) data across vault clusters. 4 | 5 | Right now this tool really only supports the `secret`/`kv` backend (version 1 in particular, although version 2 works too). Other mount points might work, but many create dynamic secrets behind the scenes or don't support all operations (i.e. LIST). 6 | 7 | ### Usage 8 | 9 | ##### Setup 10 | 11 | You'll want to `go get -f -u github.com/adamdecaf/vault-backend-migrator` this project. It will pull down the vault source code to your GOPATH too. 12 | 13 | There's also a [docker image](https://hub.docker.com/r/adamdecaf/vault-backend-migrator): `docker pull adamdecaf/vault-backend-migrator` 14 | 15 | ##### Exporting 16 | 17 | After pulling the code it's helpful to set a few environment variables. (These may not all be required for your setup.) These variables will be for the vault you're exporting from. 18 | 19 | ``` 20 | export VAULT_ADDR=http://127.0.0.1:8200/ 21 | export VAULT_CAPATH= 22 | export VAULT_TOKEN= 23 | ``` 24 | 25 | Note: You'll need to make sure the VAULT_TOKEN has permissions to list and read all vault paths. 26 | 27 | Then you should be able to run an export command: 28 | 29 | ``` 30 | $ ./vault-backend-migrator -export secret/ -file secrets.json 31 | ``` 32 | 33 | If you are using the version 2 of the backend and want all the data in there: 34 | 35 | ``` 36 | $ ./vault-backend-migrator -export secret/data/ -metadata secret/metadata/ -file secrets.json -ver 2 37 | ``` 38 | 39 | This will create a file called `secrets.json` that has all the keys and paths. (Note: This is literally all the secrets from the generic backend. Don't share this file with anyone! The secret data is **encoded** in base64, but there's no protection over this file.) 40 | 41 | ##### Importing 42 | 43 | Once you've created an export you are able to reconfigure the vault environment variables (`VAULT_ADDR` and `VAULT_TOKEN` usually) to run an import command (remember to specify `-ver 2` in the command line when importing to a version 2 backend). 44 | 45 | ``` 46 | $ ./vault-backend-migrator -import secret/ -file secrets.json 47 | ``` 48 | 49 | This will output each key the tool is writing to. After that a simple `vault list` command off the vault cli will show the secrets there. 50 | 51 | Note: It's recommended that you now delete `secrets.json` if you don't need it. If you can install a tool like `srm` to really delete this file. 52 | - OSX: `brew install srm` 53 | - Ubuntu: `apt-get install secure-delete` 54 | 55 | ### Configuration 56 | 57 | This tool reads all the `VAULT_*` environment variables as the vault cli does. You likely need to specify those for the address, CA certs, etc. 58 | 59 | ## Dependencies 60 | 61 | This project uses [Go Modules](https://github.com/golang/go/wiki/Modules) and thus requires Go 1.11+. 62 | 63 | ## Releases 64 | 65 | There are various makefile commands for building parts of the release `make release` builds and pushes everything. 66 | 67 | You can run `make docker` to build a tagged docker image. 68 | -------------------------------------------------------------------------------- /cmd/export.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "os" 9 | "path" 10 | "path/filepath" 11 | "strings" 12 | 13 | "github.com/adamdecaf/vault-backend-migrator/vault" 14 | ) 15 | 16 | const ( 17 | OutputFileMode = 0644 18 | ) 19 | 20 | func Export(path, file, metad, ver string) error { 21 | v, err := vault.NewClient() 22 | if v == nil || err != nil { 23 | if err != nil { 24 | return err 25 | } 26 | return errors.New("Unable to create vault client") 27 | } 28 | 29 | // Make sure path has a trailing slash 30 | if !strings.HasSuffix(path, "/") { 31 | path = path + "/" 32 | } 33 | 34 | if ver == "2" { 35 | if !strings.HasSuffix(metad, "/") { 36 | metad = metad + "/" 37 | } 38 | } 39 | 40 | // Get all nested keys 41 | fmt.Printf("Reading all keys under %s\n", path) 42 | var all []string 43 | 44 | if ver == "2" { 45 | accumulate(&all, *v, metad, path) 46 | } else { 47 | accumulate(&all, *v, path, path) 48 | } 49 | 50 | // Read each key's value 51 | fmt.Println("Reading all secrets") 52 | var items []Item 53 | for _, p := range all { 54 | kvs := v.Read(p) 55 | if kvs == nil { 56 | fmt.Printf("invalid read on %s\n", p) 57 | continue 58 | } 59 | 60 | var pairs []Pair 61 | for k, v := range kvs { 62 | if str, ok := v.(string); ok { 63 | pairs = append(pairs, Pair{Key: k, Value: str}) 64 | } 65 | } 66 | items = append(items, Item{Path: p, Pairs: pairs}) 67 | } 68 | 69 | // Convert to json and write to a file 70 | export := Wrap{Data: items} 71 | out, err := json.Marshal(&export) 72 | if err != nil { 73 | fmt.Println(err) 74 | } 75 | abs, err := filepath.Abs(file) 76 | if err != nil { 77 | fmt.Println(err) 78 | } 79 | 80 | // Create the output file if it's not there 81 | if _, err := os.Stat(abs); err != nil { 82 | f, err := os.Create(abs) 83 | defer f.Close() 84 | if err != nil { 85 | fmt.Println(err) 86 | } 87 | } 88 | 89 | // Write json to the file 90 | err = ioutil.WriteFile(abs, out, OutputFileMode) 91 | if err != nil { 92 | fmt.Println(err) 93 | } 94 | fmt.Printf("Wrote %s\n", abs) 95 | 96 | return nil 97 | } 98 | 99 | func accumulate(acc *[]string, v vault.Vault, basep string, accump string) { 100 | res := v.List(basep) 101 | if res == nil { // We ran into a leaf 102 | *acc = append(*acc, accump) 103 | return 104 | } 105 | for _, k := range res { 106 | accumulate(acc, v, path.Join(basep, k), path.Join(accump, k)) 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /cmd/import.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "fmt" 7 | "io/ioutil" 8 | "os" 9 | "path/filepath" 10 | 11 | "github.com/adamdecaf/vault-backend-migrator/vault" 12 | ) 13 | 14 | func Import(path, file, ver string) error { 15 | abs, err := filepath.Abs(file) 16 | if err != nil { 17 | return err 18 | } 19 | 20 | // Check the input file exists 21 | if _, err := os.Stat(abs); err != nil { 22 | f, err := os.Create(abs) 23 | defer f.Close() 24 | if err != nil { 25 | return err 26 | } 27 | } 28 | 29 | // Read input file 30 | b, err := ioutil.ReadFile(abs) 31 | if err != nil { 32 | return err 33 | } 34 | 35 | // Parse data 36 | var wrap Wrap 37 | err = json.Unmarshal(b, &wrap) 38 | if err != nil { 39 | return err 40 | } 41 | 42 | // Setup vault client 43 | v, err := vault.NewClient() 44 | if v == nil || err != nil { 45 | if err != nil { 46 | return err 47 | } 48 | return errors.New("Unable to create vault client") 49 | } 50 | 51 | // Write each keypair to vault 52 | for _, item := range wrap.Data { 53 | data := make(map[string]string) 54 | for _, kv := range item.Pairs { 55 | data[kv.Key] = kv.Value 56 | } 57 | fmt.Printf("Writing %s\n", item.Path) 58 | if err := v.Write(item.Path, data, ver); err != nil { 59 | fmt.Printf("Error %s\n", err) 60 | } 61 | } 62 | 63 | return nil 64 | } 65 | -------------------------------------------------------------------------------- /cmd/json.go: -------------------------------------------------------------------------------- 1 | package cmd 2 | 3 | // Json formatting for export and import 4 | type Wrap struct { 5 | Data []Item `json:"data"` 6 | } 7 | type Item struct { 8 | Path string `json:"path"` 9 | Pairs []Pair `json:"pairs"` 10 | } 11 | type Pair struct { 12 | Key string `json:"key"` 13 | Value string `json:"value"` 14 | } 15 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/adamdecaf/vault-backend-migrator 2 | 3 | require ( 4 | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect 5 | github.com/Jeffail/gabs v1.1.1 // indirect 6 | github.com/Microsoft/go-winio v0.4.11 // indirect 7 | github.com/Nvveen/Gotty v0.0.0-20120604004816-cd527374f1e5 // indirect 8 | github.com/SAP/go-hdb v0.13.1 // indirect 9 | github.com/SermoDigital/jose v0.9.1 // indirect 10 | github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da // indirect 11 | github.com/armon/go-radix v1.0.0 // indirect 12 | github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf // indirect 13 | github.com/bitly/go-hostpool v0.0.0-20171023180738-a3a6125de932 // indirect 14 | github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect 15 | github.com/cenkalti/backoff v2.0.0+incompatible // indirect 16 | github.com/containerd/continuity v0.0.0-20181027224239-bea7585dbfac // indirect 17 | github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f // indirect 18 | github.com/docker/go-connections v0.4.0 // indirect 19 | github.com/docker/go-units v0.3.3 // indirect 20 | github.com/duosecurity/duo_api_golang v0.0.0-20181024123116-92fea9203dbc // indirect 21 | github.com/fatih/structs v1.0.0 // indirect 22 | github.com/go-sql-driver/mysql v1.4.0 // indirect 23 | github.com/gocql/gocql v0.0.0-20181106112037-68ae1e384be4 // indirect 24 | github.com/gogo/protobuf v1.1.1 // indirect 25 | github.com/google/go-cmp v0.2.0 // indirect 26 | github.com/google/go-github v17.0.0+incompatible // indirect 27 | github.com/google/go-querystring v1.0.0 // indirect 28 | github.com/gotestyourself/gotestyourself v2.1.0+incompatible // indirect 29 | github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce // indirect 30 | github.com/hashicorp/go-cleanhttp v0.0.0-20171218145408-d5fe4b57a186 // indirect 31 | github.com/hashicorp/go-hclog v0.0.0-20181001195459-61d530d6c27f // indirect 32 | github.com/hashicorp/go-immutable-radix v1.0.0 // indirect 33 | github.com/hashicorp/go-memdb v0.0.0-20180223233045-1289e7fffe71 // indirect 34 | github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874 // indirect 35 | github.com/hashicorp/go-plugin v0.0.0-20181030172320-54b6ff97d818 // indirect 36 | github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 // indirect 37 | github.com/hashicorp/go-version v1.0.0 // indirect 38 | github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb // indirect 39 | github.com/hashicorp/vault v0.9.3 40 | github.com/jefferai/jsonx v0.0.0-20160721235117-9cc31c3135ee // indirect 41 | github.com/keybase/go-crypto v0.0.0-20181031135447-f919bfda4fc1 // indirect 42 | github.com/kr/pretty v0.1.0 // indirect 43 | github.com/lib/pq v1.0.0 // indirect 44 | github.com/mattn/go-colorable v0.0.9 // indirect 45 | github.com/mattn/go-isatty v0.0.4 // indirect 46 | github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect 47 | github.com/mgutz/logxi v0.0.0-20161027140823-aebf8a7d67ab // indirect 48 | github.com/mitchellh/copystructure v1.0.0 // indirect 49 | github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 // indirect 50 | github.com/mitchellh/go-testing-interface v1.0.0 // indirect 51 | github.com/mitchellh/mapstructure v0.0.0-20180111000720-b4575eea38cc // indirect 52 | github.com/opencontainers/go-digest v1.0.0-rc1 // indirect 53 | github.com/opencontainers/image-spec v1.0.1 // indirect 54 | github.com/opencontainers/runc v0.1.1 // indirect 55 | github.com/ory/dockertest v3.3.2+incompatible // indirect 56 | github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c // indirect 57 | github.com/patrickmn/go-cache v2.1.0+incompatible // indirect 58 | github.com/pkg/errors v0.8.0 // indirect 59 | github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735 // indirect 60 | github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048 // indirect 61 | github.com/sirupsen/logrus v1.2.0 // indirect 62 | golang.org/x/crypto v0.0.0-20181106171534-e4dc69e5b2fd // indirect 63 | golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 // indirect 64 | golang.org/x/sys v0.0.0-20181106135930-3a76605856fd // indirect 65 | google.golang.org/grpc v1.16.0 // indirect 66 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect 67 | gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect 68 | gopkg.in/ory-am/dockertest.v3 v3.3.2 // indirect 69 | gopkg.in/yaml.v2 v2.2.1 // indirect 70 | gotest.tools v2.1.0+incompatible // indirect 71 | ) 72 | -------------------------------------------------------------------------------- /it/integration_test.go: -------------------------------------------------------------------------------- 1 | package it 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "os" 8 | "os/exec" 9 | "regexp" 10 | "strings" 11 | "testing" 12 | "time" 13 | 14 | commands "github.com/adamdecaf/vault-backend-migrator/cmd" 15 | "github.com/adamdecaf/vault-backend-migrator/vault" 16 | ) 17 | 18 | var ( 19 | vaultVersion = "0.9.1" 20 | ) 21 | 22 | func hasDocker() bool { 23 | err := exec.Command("docker", "version").Run() 24 | return err == nil 25 | } 26 | 27 | // Quick sanity check 28 | func TestMigrator__integration(t *testing.T) { 29 | if !hasDocker() { 30 | t.Skip("docker isn't installed / running") 31 | } 32 | 33 | // Start vault container 34 | cmd := exec.Command("docker", "run", "-d", "-p", "8200:8200", "-t", fmt.Sprintf("vault:%s", vaultVersion)) 35 | var stdout bytes.Buffer 36 | cmd.Stdout = &stdout 37 | err := cmd.Run() 38 | if err != nil { 39 | t.Fatal(err) 40 | } 41 | 42 | // Grab root token 43 | r := regexp.MustCompile(`Root Token: ([a-f0-9]{8}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{4}\-[a-f0-9]{12})`) 44 | id := strings.TrimSpace(stdout.String()) 45 | defer func() { 46 | err = exec.Command("docker", "kill", id).Run() 47 | if err != nil { 48 | t.Fatal(err) 49 | } 50 | }() 51 | var token string 52 | for { 53 | out, err := exec.Command("docker", "logs", id).CombinedOutput() 54 | if err != nil { 55 | t.Fatal(err) 56 | break 57 | } 58 | loc := r.FindIndex(out) 59 | if len(loc) > 0 { 60 | s := string(out[loc[0]:loc[1]]) 61 | token = strings.TrimPrefix(s, "Root Token: ") 62 | break 63 | } 64 | time.Sleep(1 * time.Second) 65 | } 66 | 67 | if token == "" { 68 | t.Fatal("empty token") 69 | } 70 | 71 | // Write a couple values into secret/, export, delete and import 72 | data := []struct { 73 | path string 74 | key string 75 | value string 76 | }{ 77 | {"secret/foo", "foo", "YmFyCg=="}, // bar 78 | {"secret/bar/baz", "username", "YWRhbQo="}, // adam 79 | } 80 | os.Setenv("VAULT_ADDR", "http://127.0.0.1:8200") 81 | os.Setenv("VAULT_TOKEN", token) 82 | client, err := vault.NewClient() 83 | if err != nil { 84 | t.Fatal(err) 85 | } 86 | 87 | // write values 88 | for i := range data { 89 | client.Write(data[i].path, map[string]string{ 90 | data[i].key: data[i].value, 91 | }, "1") 92 | kv := client.Read(data[i].path) 93 | if kv[data[i].key] != data[i].value { 94 | t.Fatalf("path=%q, kv[%s]=%q, value=%q, err=%v", data[i].path, data[i].key, kv[data[i].key], data[i].value, err) 95 | } 96 | } 97 | 98 | // export 99 | tmp, err := ioutil.TempFile("", "vault-backend-migrator") 100 | if err != nil { 101 | t.Fatal(err) 102 | } 103 | defer os.Remove(tmp.Name()) 104 | err = commands.Export("secret/", tmp.Name(), "", "1") 105 | if err != nil { 106 | t.Fatal(err) 107 | } 108 | 109 | // delete 110 | for i := range data { 111 | client.Client().Logical().Delete(data[i].path) 112 | // read to verify it's gone 113 | kv, err := client.Client().Logical().Read(data[i].path) 114 | if err == nil && kv != nil { 115 | t.Fatalf("path=%q, kv=%v", data[i].path, kv) 116 | } 117 | } 118 | 119 | // import 120 | err = commands.Import("secret/", tmp.Name(), "1") 121 | if err != nil { 122 | t.Fatal(err) 123 | } 124 | for i := range data { 125 | kv := client.Read(data[i].path) 126 | if kv[data[i].key] != data[i].value { 127 | t.Fatalf("path=%q, kv[%s]=%q, value=%q, err=%v", data[i].path, data[i].key, kv[data[i].key], data[i].value, err) 128 | } 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "strings" 8 | 9 | "github.com/adamdecaf/vault-backend-migrator/cmd" 10 | ) 11 | 12 | var ( 13 | // Actions 14 | ex = flag.String("export", "", "The vault path to export") 15 | im = flag.String("import", "", "The vault path to import data into") 16 | vr = flag.String("ver", "", "KV version") 17 | md = flag.String("metadata", "", "Metadata path") 18 | 19 | // Required during export or import 20 | file = flag.String("file", "", "The local file location to use") 21 | 22 | // Output the version 23 | version = flag.Bool("version", false, "Output the version number") 24 | ) 25 | 26 | const Version = "0.2.1-dev" 27 | 28 | func main() { 29 | flag.Parse() 30 | 31 | // Import 32 | if im != nil && *im != "" { 33 | if empty(im, file) { 34 | exit() 35 | } 36 | err := cmd.Import(*im, *file, *vr) 37 | if err != nil { 38 | fmt.Println(err) 39 | os.Exit(1) 40 | } 41 | return 42 | } 43 | 44 | // Export 45 | if ex != nil && *ex != "" { 46 | if empty(ex, file) { 47 | exit() 48 | } 49 | err := cmd.Export(*ex, *file, *md, *vr) 50 | if err != nil { 51 | fmt.Println(err) 52 | os.Exit(1) 53 | } 54 | return 55 | } 56 | 57 | // Version 58 | if version != nil && *version { 59 | fmt.Println(Version) 60 | os.Exit(1) 61 | } 62 | 63 | // No commands, print help. 64 | flag.Usage() 65 | os.Exit(1) 66 | } 67 | 68 | // Do we have any empty strings? 69 | func empty(s ...*string) bool { 70 | for _, v := range s { 71 | if v == nil || len(strings.TrimSpace(*v)) == 0 { 72 | return true 73 | } 74 | } 75 | return false 76 | } 77 | 78 | func exit() { 79 | fmt.Println("There was an error reading your config flags, please fix") 80 | flag.Usage() 81 | os.Exit(1) 82 | } 83 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | VERSION := $(shell grep -Eo '(\d\.\d\.\d)(-dev)?' main.go) 2 | 3 | .PHONY: build check test mkrel upload 4 | 5 | linux: linux_amd64 6 | linux_amd64: 7 | CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/vault-backend-migrator-linux-amd64 github.com/adamdecaf/vault-backend-migrator 8 | 9 | osx: osx_amd64 10 | osx_amd64: 11 | CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o bin/vault-backend-migrator-osx-amd64 github.com/adamdecaf/vault-backend-migrator 12 | 13 | win: win_64 14 | win_64: 15 | CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -o bin/vault-backend-migrator-amd64.exe github.com/adamdecaf/vault-backend-migrator 16 | 17 | dist: build linux osx win 18 | 19 | check: 20 | go vet ./... 21 | go fmt ./... 22 | 23 | test: check dist 24 | go test -v ./... 25 | 26 | ci: check dist test 27 | 28 | build: check 29 | go build -o vault-backend-migrator github.com/adamdecaf/vault-backend-migrator 30 | @chmod +x vault-backend-migrator 31 | 32 | docker: dist 33 | docker build -t adamdecaf/vault-backend-migrator:$(VERSION) . 34 | 35 | dockerpush: docker 36 | docker push adamdecaf/vault-backend-migrator:$(VERSION) 37 | 38 | release: ci docker dockerpush mkrel upload 39 | 40 | tag: 41 | git tag $(VERSION) 42 | git push --tags origin $(VERSION) 43 | 44 | mkrel: tag 45 | ifeq ($(DEV), ) 46 | $(shell gothub release -u adamdecaf -r vault-backend-migrator -t $(VERSION) --name $(VERSION) --pre-release) 47 | else 48 | $(shell gothub release -u adamdecaf -r vault-backend-migrator -t $(VERSION) --name $(VERSION)) 49 | endif 50 | 51 | upload: 52 | gothub upload -u adamdecaf -r vault-backend-migrator -t $(VERSION) --name "vault-backend-migrator-linux" --file bin/vault-backend-migrator-linux-amd64 53 | gothub upload -u adamdecaf -r vault-backend-migrator -t $(VERSION) --name "vault-backend-migrator-osx" --file bin/vault-backend-migrator-osx-amd64 54 | gothub upload -u adamdecaf -r vault-backend-migrator -t $(VERSION) --name "vault-backend-migrator.exe" --file bin/vault-backend-migrator-amd64.exe 55 | -------------------------------------------------------------------------------- /vault/client.go: -------------------------------------------------------------------------------- 1 | package vault 2 | 3 | import ( 4 | "encoding/base64" 5 | "fmt" 6 | "os" 7 | 8 | "github.com/hashicorp/vault/api" 9 | ) 10 | 11 | type Vault struct { 12 | c *api.Client 13 | } 14 | 15 | func (v *Vault) Client() *api.Client { 16 | return v.c 17 | } 18 | 19 | func NewClient() (*Vault, error) { 20 | cfg := api.DefaultConfig() 21 | 22 | // Read vault env variables 23 | cfg.ReadEnvironment() 24 | 25 | client, err := api.NewClient(cfg) 26 | if err != nil { 27 | return nil, err 28 | } 29 | 30 | // Sanity checks 31 | if v := os.Getenv(api.EnvVaultAddress); v == "" { 32 | fmt.Println("Did you mean to use localhost vault? Try setting VAULT_ADDR") 33 | } 34 | 35 | return &Vault{ 36 | c: client, 37 | }, nil 38 | } 39 | 40 | // List the keys at at given vault path. This has only been tested on the generic backend. 41 | // It will return nil if something goes wrong. 42 | func (v *Vault) List(path string) []string { 43 | secret, err := v.c.Logical().List(path) 44 | if secret == nil { 45 | return nil 46 | } 47 | if err != nil { 48 | fmt.Printf("Unable to read path %q, err=%v\n", path, err) 49 | return nil 50 | } 51 | 52 | r, ok := secret.Data["keys"].([]interface{}) 53 | if ok { 54 | out := make([]string, len(r)) 55 | for i := range r { 56 | out[i] = r[i].(string) 57 | } 58 | return out 59 | } 60 | return nil 61 | } 62 | 63 | // Read accepts a vault path to read the data out of. It will return a map 64 | // of base64 encoded values. 65 | func (v *Vault) Read(path string) map[string]interface{} { 66 | out := make(map[string]interface{}) 67 | 68 | s, err := v.c.Logical().Read(path) 69 | if err != nil { 70 | fmt.Printf("Error reading secrets, err=%v", err) 71 | return nil 72 | } 73 | 74 | // Encode all k,v pairs 75 | if s == nil || s.Data == nil { 76 | fmt.Printf("No data to read at path, %s\n", path) 77 | return out 78 | } 79 | for k, v := range s.Data { 80 | switch t := v.(type) { 81 | case string: 82 | out[k] = base64.StdEncoding.EncodeToString([]byte(t)) 83 | case map[string]interface{}: 84 | if k == "data" { 85 | for x, y := range t { 86 | if z, ok := y.(string); ok { 87 | out[x] = base64.StdEncoding.EncodeToString([]byte(z)) 88 | } 89 | } 90 | } 91 | default: 92 | fmt.Printf("error reading value at %s, key=%s, type=%T\n", path, k, v) 93 | } 94 | } 95 | 96 | return out 97 | } 98 | 99 | // Write takes in a vault path and base64 encoded data to be written at that path. 100 | func (v *Vault) Write(path string, data map[string]string, ver string) error { 101 | body := make(map[string]interface{}) 102 | 103 | // Decode the base64 values 104 | for k, v := range data { 105 | b, err := base64.StdEncoding.DecodeString(v) 106 | if err != nil { 107 | return err 108 | } 109 | body[k] = string(b) 110 | } 111 | 112 | var err error 113 | 114 | if ver == "2" { 115 | d := make(map[string]interface{}) 116 | d["data"] = body 117 | _, err = v.c.Logical().Write(path, d) 118 | } else { 119 | _, err = v.c.Logical().Write(path, body) 120 | } 121 | 122 | return err 123 | } 124 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.7.x 4 | - tip 5 | sudo: false 6 | before_install: 7 | - go get github.com/axw/gocov/gocov 8 | - go get github.com/mattn/goveralls 9 | - if ! go get github.com/golang/tools/cmd/cover; then go get golang.org/x/tools/cmd/cover; fi 10 | script: 11 | - $HOME/gopath/bin/goveralls -service=travis-ci 12 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Fatih Arslan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/field.go: -------------------------------------------------------------------------------- 1 | package structs 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "reflect" 7 | ) 8 | 9 | var ( 10 | errNotExported = errors.New("field is not exported") 11 | errNotSettable = errors.New("field is not settable") 12 | ) 13 | 14 | // Field represents a single struct field that encapsulates high level 15 | // functions around the field. 16 | type Field struct { 17 | value reflect.Value 18 | field reflect.StructField 19 | defaultTag string 20 | } 21 | 22 | // Tag returns the value associated with key in the tag string. If there is no 23 | // such key in the tag, Tag returns the empty string. 24 | func (f *Field) Tag(key string) string { 25 | return f.field.Tag.Get(key) 26 | } 27 | 28 | // Value returns the underlying value of the field. It panics if the field 29 | // is not exported. 30 | func (f *Field) Value() interface{} { 31 | return f.value.Interface() 32 | } 33 | 34 | // IsEmbedded returns true if the given field is an anonymous field (embedded) 35 | func (f *Field) IsEmbedded() bool { 36 | return f.field.Anonymous 37 | } 38 | 39 | // IsExported returns true if the given field is exported. 40 | func (f *Field) IsExported() bool { 41 | return f.field.PkgPath == "" 42 | } 43 | 44 | // IsZero returns true if the given field is not initialized (has a zero value). 45 | // It panics if the field is not exported. 46 | func (f *Field) IsZero() bool { 47 | zero := reflect.Zero(f.value.Type()).Interface() 48 | current := f.Value() 49 | 50 | return reflect.DeepEqual(current, zero) 51 | } 52 | 53 | // Name returns the name of the given field 54 | func (f *Field) Name() string { 55 | return f.field.Name 56 | } 57 | 58 | // Kind returns the fields kind, such as "string", "map", "bool", etc .. 59 | func (f *Field) Kind() reflect.Kind { 60 | return f.value.Kind() 61 | } 62 | 63 | // Set sets the field to given value v. It returns an error if the field is not 64 | // settable (not addressable or not exported) or if the given value's type 65 | // doesn't match the fields type. 66 | func (f *Field) Set(val interface{}) error { 67 | // we can't set unexported fields, so be sure this field is exported 68 | if !f.IsExported() { 69 | return errNotExported 70 | } 71 | 72 | // do we get here? not sure... 73 | if !f.value.CanSet() { 74 | return errNotSettable 75 | } 76 | 77 | given := reflect.ValueOf(val) 78 | 79 | if f.value.Kind() != given.Kind() { 80 | return fmt.Errorf("wrong kind. got: %s want: %s", given.Kind(), f.value.Kind()) 81 | } 82 | 83 | f.value.Set(given) 84 | return nil 85 | } 86 | 87 | // Zero sets the field to its zero value. It returns an error if the field is not 88 | // settable (not addressable or not exported). 89 | func (f *Field) Zero() error { 90 | zero := reflect.Zero(f.value.Type()).Interface() 91 | return f.Set(zero) 92 | } 93 | 94 | // Fields returns a slice of Fields. This is particular handy to get the fields 95 | // of a nested struct . A struct tag with the content of "-" ignores the 96 | // checking of that particular field. Example: 97 | // 98 | // // Field is ignored by this package. 99 | // Field *http.Request `structs:"-"` 100 | // 101 | // It panics if field is not exported or if field's kind is not struct 102 | func (f *Field) Fields() []*Field { 103 | return getFields(f.value, f.defaultTag) 104 | } 105 | 106 | // Field returns the field from a nested struct. It panics if the nested struct 107 | // is not exported or if the field was not found. 108 | func (f *Field) Field(name string) *Field { 109 | field, ok := f.FieldOk(name) 110 | if !ok { 111 | panic("field not found") 112 | } 113 | 114 | return field 115 | } 116 | 117 | // FieldOk returns the field from a nested struct. The boolean returns whether 118 | // the field was found (true) or not (false). 119 | func (f *Field) FieldOk(name string) (*Field, bool) { 120 | value := &f.value 121 | // value must be settable so we need to make sure it holds the address of the 122 | // variable and not a copy, so we can pass the pointer to strctVal instead of a 123 | // copy (which is not assigned to any variable, hence not settable). 124 | // see "https://blog.golang.org/laws-of-reflection#TOC_8." 125 | if f.value.Kind() != reflect.Ptr { 126 | a := f.value.Addr() 127 | value = &a 128 | } 129 | v := strctVal(value.Interface()) 130 | t := v.Type() 131 | 132 | field, ok := t.FieldByName(name) 133 | if !ok { 134 | return nil, false 135 | } 136 | 137 | return &Field{ 138 | field: field, 139 | value: v.FieldByName(name), 140 | }, true 141 | } 142 | -------------------------------------------------------------------------------- /vendor/github.com/fatih/structs/tags.go: -------------------------------------------------------------------------------- 1 | package structs 2 | 3 | import "strings" 4 | 5 | // tagOptions contains a slice of tag options 6 | type tagOptions []string 7 | 8 | // Has returns true if the given optiton is available in tagOptions 9 | func (t tagOptions) Has(opt string) bool { 10 | for _, tagOpt := range t { 11 | if tagOpt == opt { 12 | return true 13 | } 14 | } 15 | 16 | return false 17 | } 18 | 19 | // parseTag splits a struct field's tag into its name and a list of options 20 | // which comes after a name. A tag is in the form of: "name,option1,option2". 21 | // The name can be neglectected. 22 | func parseTag(tag string) (string, tagOptions) { 23 | // tag is one of followings: 24 | // "" 25 | // "name" 26 | // "name,opt" 27 | // "name,opt,opt2" 28 | // ",opt" 29 | 30 | res := strings.Split(tag, ",") 31 | return res[0], res[1:] 32 | } 33 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/.gitignore: -------------------------------------------------------------------------------- 1 | cmd/snappytool/snappytool 2 | testdata/bench 3 | 4 | # These explicitly listed benchmark data files are for an obsolete version of 5 | # snappy_test.go. 6 | testdata/alice29.txt 7 | testdata/asyoulik.txt 8 | testdata/fireworks.jpeg 9 | testdata/geo.protodata 10 | testdata/html 11 | testdata/html_x_4 12 | testdata/kppkn.gtb 13 | testdata/lcet10.txt 14 | testdata/paper-100k.pdf 15 | testdata/plrabn12.txt 16 | testdata/urls.10K 17 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of Snappy-Go authors for copyright purposes. 2 | # This file is distinct from the CONTRIBUTORS files. 3 | # See the latter for an explanation. 4 | 5 | # Names should be added to this file as 6 | # Name or Organization 7 | # The email address is not required for organizations. 8 | 9 | # Please keep the list sorted. 10 | 11 | Damian Gryski 12 | Google Inc. 13 | Jan Mercl <0xjnml@gmail.com> 14 | Rodolfo Carvalho 15 | Sebastien Binet 16 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This is the official list of people who can contribute 2 | # (and typically have contributed) code to the Snappy-Go repository. 3 | # The AUTHORS file lists the copyright holders; this file 4 | # lists people. For example, Google employees are listed here 5 | # but not in AUTHORS, because Google holds the copyright. 6 | # 7 | # The submission process automatically checks to make sure 8 | # that people submitting code are listed in this file (by email address). 9 | # 10 | # Names should be added to this file only after verifying that 11 | # the individual or the individual's organization has agreed to 12 | # the appropriate Contributor License Agreement, found here: 13 | # 14 | # http://code.google.com/legal/individual-cla-v1.0.html 15 | # http://code.google.com/legal/corporate-cla-v1.0.html 16 | # 17 | # The agreement for individuals can be filled out on the web. 18 | # 19 | # When adding J Random Contributor's name to this file, 20 | # either J's name or J's organization's name should be 21 | # added to the AUTHORS file, depending on whether the 22 | # individual or corporate CLA was used. 23 | 24 | # Names should be added to this file like so: 25 | # Name 26 | 27 | # Please keep the list sorted. 28 | 29 | Damian Gryski 30 | Jan Mercl <0xjnml@gmail.com> 31 | Kai Backman 32 | Marc-Antoine Ruel 33 | Nigel Tao 34 | Rob Pike 35 | Rodolfo Carvalho 36 | Russ Cox 37 | Sebastien Binet 38 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011 The Snappy-Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/README: -------------------------------------------------------------------------------- 1 | The Snappy compression format in the Go programming language. 2 | 3 | To download and install from source: 4 | $ go get github.com/golang/snappy 5 | 6 | Unless otherwise noted, the Snappy-Go source files are distributed 7 | under the BSD-style license found in the LICENSE file. 8 | 9 | 10 | 11 | Benchmarks. 12 | 13 | The golang/snappy benchmarks include compressing (Z) and decompressing (U) ten 14 | or so files, the same set used by the C++ Snappy code (github.com/google/snappy 15 | and note the "google", not "golang"). On an "Intel(R) Core(TM) i7-3770 CPU @ 16 | 3.40GHz", Go's GOARCH=amd64 numbers as of 2016-05-29: 17 | 18 | "go test -test.bench=." 19 | 20 | _UFlat0-8 2.19GB/s ± 0% html 21 | _UFlat1-8 1.41GB/s ± 0% urls 22 | _UFlat2-8 23.5GB/s ± 2% jpg 23 | _UFlat3-8 1.91GB/s ± 0% jpg_200 24 | _UFlat4-8 14.0GB/s ± 1% pdf 25 | _UFlat5-8 1.97GB/s ± 0% html4 26 | _UFlat6-8 814MB/s ± 0% txt1 27 | _UFlat7-8 785MB/s ± 0% txt2 28 | _UFlat8-8 857MB/s ± 0% txt3 29 | _UFlat9-8 719MB/s ± 1% txt4 30 | _UFlat10-8 2.84GB/s ± 0% pb 31 | _UFlat11-8 1.05GB/s ± 0% gaviota 32 | 33 | _ZFlat0-8 1.04GB/s ± 0% html 34 | _ZFlat1-8 534MB/s ± 0% urls 35 | _ZFlat2-8 15.7GB/s ± 1% jpg 36 | _ZFlat3-8 740MB/s ± 3% jpg_200 37 | _ZFlat4-8 9.20GB/s ± 1% pdf 38 | _ZFlat5-8 991MB/s ± 0% html4 39 | _ZFlat6-8 379MB/s ± 0% txt1 40 | _ZFlat7-8 352MB/s ± 0% txt2 41 | _ZFlat8-8 396MB/s ± 1% txt3 42 | _ZFlat9-8 327MB/s ± 1% txt4 43 | _ZFlat10-8 1.33GB/s ± 1% pb 44 | _ZFlat11-8 605MB/s ± 1% gaviota 45 | 46 | 47 | 48 | "go test -test.bench=. -tags=noasm" 49 | 50 | _UFlat0-8 621MB/s ± 2% html 51 | _UFlat1-8 494MB/s ± 1% urls 52 | _UFlat2-8 23.2GB/s ± 1% jpg 53 | _UFlat3-8 1.12GB/s ± 1% jpg_200 54 | _UFlat4-8 4.35GB/s ± 1% pdf 55 | _UFlat5-8 609MB/s ± 0% html4 56 | _UFlat6-8 296MB/s ± 0% txt1 57 | _UFlat7-8 288MB/s ± 0% txt2 58 | _UFlat8-8 309MB/s ± 1% txt3 59 | _UFlat9-8 280MB/s ± 1% txt4 60 | _UFlat10-8 753MB/s ± 0% pb 61 | _UFlat11-8 400MB/s ± 0% gaviota 62 | 63 | _ZFlat0-8 409MB/s ± 1% html 64 | _ZFlat1-8 250MB/s ± 1% urls 65 | _ZFlat2-8 12.3GB/s ± 1% jpg 66 | _ZFlat3-8 132MB/s ± 0% jpg_200 67 | _ZFlat4-8 2.92GB/s ± 0% pdf 68 | _ZFlat5-8 405MB/s ± 1% html4 69 | _ZFlat6-8 179MB/s ± 1% txt1 70 | _ZFlat7-8 170MB/s ± 1% txt2 71 | _ZFlat8-8 189MB/s ± 1% txt3 72 | _ZFlat9-8 164MB/s ± 1% txt4 73 | _ZFlat10-8 479MB/s ± 1% pb 74 | _ZFlat11-8 270MB/s ± 1% gaviota 75 | 76 | 77 | 78 | For comparison (Go's encoded output is byte-for-byte identical to C++'s), here 79 | are the numbers from C++ Snappy's 80 | 81 | make CXXFLAGS="-O2 -DNDEBUG -g" clean snappy_unittest.log && cat snappy_unittest.log 82 | 83 | BM_UFlat/0 2.4GB/s html 84 | BM_UFlat/1 1.4GB/s urls 85 | BM_UFlat/2 21.8GB/s jpg 86 | BM_UFlat/3 1.5GB/s jpg_200 87 | BM_UFlat/4 13.3GB/s pdf 88 | BM_UFlat/5 2.1GB/s html4 89 | BM_UFlat/6 1.0GB/s txt1 90 | BM_UFlat/7 959.4MB/s txt2 91 | BM_UFlat/8 1.0GB/s txt3 92 | BM_UFlat/9 864.5MB/s txt4 93 | BM_UFlat/10 2.9GB/s pb 94 | BM_UFlat/11 1.2GB/s gaviota 95 | 96 | BM_ZFlat/0 944.3MB/s html (22.31 %) 97 | BM_ZFlat/1 501.6MB/s urls (47.78 %) 98 | BM_ZFlat/2 14.3GB/s jpg (99.95 %) 99 | BM_ZFlat/3 538.3MB/s jpg_200 (73.00 %) 100 | BM_ZFlat/4 8.3GB/s pdf (83.30 %) 101 | BM_ZFlat/5 903.5MB/s html4 (22.52 %) 102 | BM_ZFlat/6 336.0MB/s txt1 (57.88 %) 103 | BM_ZFlat/7 312.3MB/s txt2 (61.91 %) 104 | BM_ZFlat/8 353.1MB/s txt3 (54.99 %) 105 | BM_ZFlat/9 289.9MB/s txt4 (66.26 %) 106 | BM_ZFlat/10 1.2GB/s pb (19.68 %) 107 | BM_ZFlat/11 527.4MB/s gaviota (37.72 %) 108 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/decode_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | // +build gc 7 | // +build !noasm 8 | 9 | package snappy 10 | 11 | // decode has the same semantics as in decode_other.go. 12 | // 13 | //go:noescape 14 | func decode(dst, src []byte) int 15 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/decode_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !amd64 appengine !gc noasm 6 | 7 | package snappy 8 | 9 | // decode writes the decoding of src to dst. It assumes that the varint-encoded 10 | // length of the decompressed bytes has already been read, and that len(dst) 11 | // equals that length. 12 | // 13 | // It returns 0 on success or a decodeErrCodeXxx error code on failure. 14 | func decode(dst, src []byte) int { 15 | var d, s, offset, length int 16 | for s < len(src) { 17 | switch src[s] & 0x03 { 18 | case tagLiteral: 19 | x := uint32(src[s] >> 2) 20 | switch { 21 | case x < 60: 22 | s++ 23 | case x == 60: 24 | s += 2 25 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 26 | return decodeErrCodeCorrupt 27 | } 28 | x = uint32(src[s-1]) 29 | case x == 61: 30 | s += 3 31 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 32 | return decodeErrCodeCorrupt 33 | } 34 | x = uint32(src[s-2]) | uint32(src[s-1])<<8 35 | case x == 62: 36 | s += 4 37 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 38 | return decodeErrCodeCorrupt 39 | } 40 | x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16 41 | case x == 63: 42 | s += 5 43 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 44 | return decodeErrCodeCorrupt 45 | } 46 | x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24 47 | } 48 | length = int(x) + 1 49 | if length <= 0 { 50 | return decodeErrCodeUnsupportedLiteralLength 51 | } 52 | if length > len(dst)-d || length > len(src)-s { 53 | return decodeErrCodeCorrupt 54 | } 55 | copy(dst[d:], src[s:s+length]) 56 | d += length 57 | s += length 58 | continue 59 | 60 | case tagCopy1: 61 | s += 2 62 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 63 | return decodeErrCodeCorrupt 64 | } 65 | length = 4 + int(src[s-2])>>2&0x7 66 | offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1])) 67 | 68 | case tagCopy2: 69 | s += 3 70 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 71 | return decodeErrCodeCorrupt 72 | } 73 | length = 1 + int(src[s-3])>>2 74 | offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8) 75 | 76 | case tagCopy4: 77 | s += 5 78 | if uint(s) > uint(len(src)) { // The uint conversions catch overflow from the previous line. 79 | return decodeErrCodeCorrupt 80 | } 81 | length = 1 + int(src[s-5])>>2 82 | offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24) 83 | } 84 | 85 | if offset <= 0 || d < offset || length > len(dst)-d { 86 | return decodeErrCodeCorrupt 87 | } 88 | // Copy from an earlier sub-slice of dst to a later sub-slice. Unlike 89 | // the built-in copy function, this byte-by-byte copy always runs 90 | // forwards, even if the slices overlap. Conceptually, this is: 91 | // 92 | // d += forwardCopy(dst[d:d+length], dst[d-offset:]) 93 | for end := d + length; d != end; d++ { 94 | dst[d] = dst[d-offset] 95 | } 96 | } 97 | if d != len(dst) { 98 | return decodeErrCodeCorrupt 99 | } 100 | return 0 101 | } 102 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/encode_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !appengine 6 | // +build gc 7 | // +build !noasm 8 | 9 | package snappy 10 | 11 | // emitLiteral has the same semantics as in encode_other.go. 12 | // 13 | //go:noescape 14 | func emitLiteral(dst, lit []byte) int 15 | 16 | // emitCopy has the same semantics as in encode_other.go. 17 | // 18 | //go:noescape 19 | func emitCopy(dst []byte, offset, length int) int 20 | 21 | // extendMatch has the same semantics as in encode_other.go. 22 | // 23 | //go:noescape 24 | func extendMatch(src []byte, i, j int) int 25 | 26 | // encodeBlock has the same semantics as in encode_other.go. 27 | // 28 | //go:noescape 29 | func encodeBlock(dst, src []byte) (d int) 30 | -------------------------------------------------------------------------------- /vendor/github.com/golang/snappy/snappy.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Snappy-Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package snappy implements the snappy block-based compression format. 6 | // It aims for very high speeds and reasonable compression. 7 | // 8 | // The C++ snappy implementation is at https://github.com/google/snappy 9 | package snappy // import "github.com/golang/snappy" 10 | 11 | import ( 12 | "hash/crc32" 13 | ) 14 | 15 | /* 16 | Each encoded block begins with the varint-encoded length of the decoded data, 17 | followed by a sequence of chunks. Chunks begin and end on byte boundaries. The 18 | first byte of each chunk is broken into its 2 least and 6 most significant bits 19 | called l and m: l ranges in [0, 4) and m ranges in [0, 64). l is the chunk tag. 20 | Zero means a literal tag. All other values mean a copy tag. 21 | 22 | For literal tags: 23 | - If m < 60, the next 1 + m bytes are literal bytes. 24 | - Otherwise, let n be the little-endian unsigned integer denoted by the next 25 | m - 59 bytes. The next 1 + n bytes after that are literal bytes. 26 | 27 | For copy tags, length bytes are copied from offset bytes ago, in the style of 28 | Lempel-Ziv compression algorithms. In particular: 29 | - For l == 1, the offset ranges in [0, 1<<11) and the length in [4, 12). 30 | The length is 4 + the low 3 bits of m. The high 3 bits of m form bits 8-10 31 | of the offset. The next byte is bits 0-7 of the offset. 32 | - For l == 2, the offset ranges in [0, 1<<16) and the length in [1, 65). 33 | The length is 1 + m. The offset is the little-endian unsigned integer 34 | denoted by the next 2 bytes. 35 | - For l == 3, this tag is a legacy format that is no longer issued by most 36 | encoders. Nonetheless, the offset ranges in [0, 1<<32) and the length in 37 | [1, 65). The length is 1 + m. The offset is the little-endian unsigned 38 | integer denoted by the next 4 bytes. 39 | */ 40 | const ( 41 | tagLiteral = 0x00 42 | tagCopy1 = 0x01 43 | tagCopy2 = 0x02 44 | tagCopy4 = 0x03 45 | ) 46 | 47 | const ( 48 | checksumSize = 4 49 | chunkHeaderSize = 4 50 | magicChunk = "\xff\x06\x00\x00" + magicBody 51 | magicBody = "sNaPpY" 52 | 53 | // maxBlockSize is the maximum size of the input to encodeBlock. It is not 54 | // part of the wire format per se, but some parts of the encoder assume 55 | // that an offset fits into a uint16. 56 | // 57 | // Also, for the framing format (Writer type instead of Encode function), 58 | // https://github.com/google/snappy/blob/master/framing_format.txt says 59 | // that "the uncompressed data in a chunk must be no longer than 65536 60 | // bytes". 61 | maxBlockSize = 65536 62 | 63 | // maxEncodedLenOfMaxBlockSize equals MaxEncodedLen(maxBlockSize), but is 64 | // hard coded to be a const instead of a variable, so that obufLen can also 65 | // be a const. Their equivalence is confirmed by 66 | // TestMaxEncodedLenOfMaxBlockSize. 67 | maxEncodedLenOfMaxBlockSize = 76490 68 | 69 | obufHeaderLen = len(magicChunk) + checksumSize + chunkHeaderSize 70 | obufLen = obufHeaderLen + maxEncodedLenOfMaxBlockSize 71 | ) 72 | 73 | const ( 74 | chunkTypeCompressedData = 0x00 75 | chunkTypeUncompressedData = 0x01 76 | chunkTypePadding = 0xfe 77 | chunkTypeStreamIdentifier = 0xff 78 | ) 79 | 80 | var crcTable = crc32.MakeTable(crc32.Castagnoli) 81 | 82 | // crc implements the checksum specified in section 3 of 83 | // https://github.com/google/snappy/blob/master/framing_format.txt 84 | func crc(b []byte) uint32 { 85 | c := crc32.Update(0, crcTable, b) 86 | return uint32(c>>15|c<<17) + 0xa282ead8 87 | } 88 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/errwrap/README.md: -------------------------------------------------------------------------------- 1 | # errwrap 2 | 3 | `errwrap` is a package for Go that formalizes the pattern of wrapping errors 4 | and checking if an error contains another error. 5 | 6 | There is a common pattern in Go of taking a returned `error` value and 7 | then wrapping it (such as with `fmt.Errorf`) before returning it. The problem 8 | with this pattern is that you completely lose the original `error` structure. 9 | 10 | Arguably the _correct_ approach is that you should make a custom structure 11 | implementing the `error` interface, and have the original error as a field 12 | on that structure, such [as this example](http://golang.org/pkg/os/#PathError). 13 | This is a good approach, but you have to know the entire chain of possible 14 | rewrapping that happens, when you might just care about one. 15 | 16 | `errwrap` formalizes this pattern (it doesn't matter what approach you use 17 | above) by giving a single interface for wrapping errors, checking if a specific 18 | error is wrapped, and extracting that error. 19 | 20 | ## Installation and Docs 21 | 22 | Install using `go get github.com/hashicorp/errwrap`. 23 | 24 | Full documentation is available at 25 | http://godoc.org/github.com/hashicorp/errwrap 26 | 27 | ## Usage 28 | 29 | #### Basic Usage 30 | 31 | Below is a very basic example of its usage: 32 | 33 | ```go 34 | // A function that always returns an error, but wraps it, like a real 35 | // function might. 36 | func tryOpen() error { 37 | _, err := os.Open("/i/dont/exist") 38 | if err != nil { 39 | return errwrap.Wrapf("Doesn't exist: {{err}}", err) 40 | } 41 | 42 | return nil 43 | } 44 | 45 | func main() { 46 | err := tryOpen() 47 | 48 | // We can use the Contains helpers to check if an error contains 49 | // another error. It is safe to do this with a nil error, or with 50 | // an error that doesn't even use the errwrap package. 51 | if errwrap.Contains(err, ErrNotExist) { 52 | // Do something 53 | } 54 | if errwrap.ContainsType(err, new(os.PathError)) { 55 | // Do something 56 | } 57 | 58 | // Or we can use the associated `Get` functions to just extract 59 | // a specific error. This would return nil if that specific error doesn't 60 | // exist. 61 | perr := errwrap.GetType(err, new(os.PathError)) 62 | } 63 | ``` 64 | 65 | #### Custom Types 66 | 67 | If you're already making custom types that properly wrap errors, then 68 | you can get all the functionality of `errwraps.Contains` and such by 69 | implementing the `Wrapper` interface with just one function. Example: 70 | 71 | ```go 72 | type AppError { 73 | Code ErrorCode 74 | Err error 75 | } 76 | 77 | func (e *AppError) WrappedErrors() []error { 78 | return []error{e.Err} 79 | } 80 | ``` 81 | 82 | Now this works: 83 | 84 | ```go 85 | err := &AppError{Err: fmt.Errorf("an error")} 86 | if errwrap.ContainsType(err, fmt.Errorf("")) { 87 | // This will work! 88 | } 89 | ``` 90 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/README.md: -------------------------------------------------------------------------------- 1 | # cleanhttp 2 | 3 | Functions for accessing "clean" Go http.Client values 4 | 5 | ------------- 6 | 7 | The Go standard library contains a default `http.Client` called 8 | `http.DefaultClient`. It is a common idiom in Go code to start with 9 | `http.DefaultClient` and tweak it as necessary, and in fact, this is 10 | encouraged; from the `http` package documentation: 11 | 12 | > The Client's Transport typically has internal state (cached TCP connections), 13 | so Clients should be reused instead of created as needed. Clients are safe for 14 | concurrent use by multiple goroutines. 15 | 16 | Unfortunately, this is a shared value, and it is not uncommon for libraries to 17 | assume that they are free to modify it at will. With enough dependencies, it 18 | can be very easy to encounter strange problems and race conditions due to 19 | manipulation of this shared value across libraries and goroutines (clients are 20 | safe for concurrent use, but writing values to the client struct itself is not 21 | protected). 22 | 23 | Making things worse is the fact that a bare `http.Client` will use a default 24 | `http.Transport` called `http.DefaultTransport`, which is another global value 25 | that behaves the same way. So it is not simply enough to replace 26 | `http.DefaultClient` with `&http.Client{}`. 27 | 28 | This repository provides some simple functions to get a "clean" `http.Client` 29 | -- one that uses the same default values as the Go standard library, but 30 | returns a client that does not share any state with other clients. 31 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/cleanhttp.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "net" 5 | "net/http" 6 | "runtime" 7 | "time" 8 | ) 9 | 10 | // DefaultTransport returns a new http.Transport with similar default values to 11 | // http.DefaultTransport, but with idle connections and keepalives disabled. 12 | func DefaultTransport() *http.Transport { 13 | transport := DefaultPooledTransport() 14 | transport.DisableKeepAlives = true 15 | transport.MaxIdleConnsPerHost = -1 16 | return transport 17 | } 18 | 19 | // DefaultPooledTransport returns a new http.Transport with similar default 20 | // values to http.DefaultTransport. Do not use this for transient transports as 21 | // it can leak file descriptors over time. Only use this for transports that 22 | // will be re-used for the same host(s). 23 | func DefaultPooledTransport() *http.Transport { 24 | transport := &http.Transport{ 25 | Proxy: http.ProxyFromEnvironment, 26 | DialContext: (&net.Dialer{ 27 | Timeout: 30 * time.Second, 28 | KeepAlive: 30 * time.Second, 29 | DualStack: true, 30 | }).DialContext, 31 | MaxIdleConns: 100, 32 | IdleConnTimeout: 90 * time.Second, 33 | TLSHandshakeTimeout: 10 * time.Second, 34 | ExpectContinueTimeout: 1 * time.Second, 35 | MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1, 36 | } 37 | return transport 38 | } 39 | 40 | // DefaultClient returns a new http.Client with similar default values to 41 | // http.Client, but with a non-shared Transport, idle connections disabled, and 42 | // keepalives disabled. 43 | func DefaultClient() *http.Client { 44 | return &http.Client{ 45 | Transport: DefaultTransport(), 46 | } 47 | } 48 | 49 | // DefaultPooledClient returns a new http.Client with similar default values to 50 | // http.Client, but with a shared Transport. Do not use this function for 51 | // transient clients as it can leak file descriptors over time. Only use this 52 | // for clients that will be re-used for the same host(s). 53 | func DefaultPooledClient() *http.Client { 54 | return &http.Client{ 55 | Transport: DefaultPooledTransport(), 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/doc.go: -------------------------------------------------------------------------------- 1 | // Package cleanhttp offers convenience utilities for acquiring "clean" 2 | // http.Transport and http.Client structs. 3 | // 4 | // Values set on http.DefaultClient and http.DefaultTransport affect all 5 | // callers. This can have detrimental effects, esepcially in TLS contexts, 6 | // where client or root certificates set to talk to multiple endpoints can end 7 | // up displacing each other, leading to hard-to-debug issues. This package 8 | // provides non-shared http.Client and http.Transport structs to ensure that 9 | // the configuration will not be overwritten by other parts of the application 10 | // or dependencies. 11 | // 12 | // The DefaultClient and DefaultTransport functions disable idle connections 13 | // and keepalives. Without ensuring that idle connections are closed before 14 | // garbage collection, short-term clients/transports can leak file descriptors, 15 | // eventually leading to "too many open files" errors. If you will be 16 | // connecting to the same hosts repeatedly from the same client, you can use 17 | // DefaultPooledClient to receive a client that has connection pooling 18 | // semantics similar to http.DefaultClient. 19 | // 20 | package cleanhttp 21 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-cleanhttp/handlers.go: -------------------------------------------------------------------------------- 1 | package cleanhttp 2 | 3 | import ( 4 | "net/http" 5 | "strings" 6 | "unicode" 7 | ) 8 | 9 | // HandlerInput provides input options to cleanhttp's handlers 10 | type HandlerInput struct { 11 | ErrStatus int 12 | } 13 | 14 | // PrintablePathCheckHandler is a middleware that ensures the request path 15 | // contains only printable runes. 16 | func PrintablePathCheckHandler(next http.Handler, input *HandlerInput) http.Handler { 17 | // Nil-check on input to make it optional 18 | if input == nil { 19 | input = &HandlerInput{ 20 | ErrStatus: http.StatusBadRequest, 21 | } 22 | } 23 | 24 | // Default to http.StatusBadRequest on error 25 | if input.ErrStatus == 0 { 26 | input.ErrStatus = http.StatusBadRequest 27 | } 28 | 29 | return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 30 | // Check URL path for non-printable characters 31 | idx := strings.IndexFunc(r.URL.Path, func(c rune) bool { 32 | return !unicode.IsPrint(c) 33 | }) 34 | 35 | if idx != -1 { 36 | w.WriteHeader(input.ErrStatus) 37 | return 38 | } 39 | 40 | next.ServeHTTP(w, r) 41 | return 42 | }) 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.x 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | script: make test testrace 13 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/Makefile: -------------------------------------------------------------------------------- 1 | TEST?=./... 2 | 3 | default: test 4 | 5 | # test runs the test suite and vets the code. 6 | test: generate 7 | @echo "==> Running tests..." 8 | @go list $(TEST) \ 9 | | grep -v "/vendor/" \ 10 | | xargs -n1 go test -timeout=60s -parallel=10 ${TESTARGS} 11 | 12 | # testrace runs the race checker 13 | testrace: generate 14 | @echo "==> Running tests (race)..." 15 | @go list $(TEST) \ 16 | | grep -v "/vendor/" \ 17 | | xargs -n1 go test -timeout=60s -race ${TESTARGS} 18 | 19 | # updatedeps installs all the dependencies needed to run and build. 20 | updatedeps: 21 | @sh -c "'${CURDIR}/scripts/deps.sh' '${NAME}'" 22 | 23 | # generate runs `go generate` to build the dynamically generated source files. 24 | generate: 25 | @echo "==> Generating..." 26 | @find . -type f -name '.DS_Store' -delete 27 | @go list ./... \ 28 | | grep -v "/vendor/" \ 29 | | xargs -n1 go generate 30 | 31 | .PHONY: default test testrace updatedeps generate 32 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/README.md: -------------------------------------------------------------------------------- 1 | # go-multierror 2 | 3 | [![Build Status](http://img.shields.io/travis/hashicorp/go-multierror.svg?style=flat-square)][travis] 4 | [![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs] 5 | 6 | [travis]: https://travis-ci.org/hashicorp/go-multierror 7 | [godocs]: https://godoc.org/github.com/hashicorp/go-multierror 8 | 9 | `go-multierror` is a package for Go that provides a mechanism for 10 | representing a list of `error` values as a single `error`. 11 | 12 | This allows a function in Go to return an `error` that might actually 13 | be a list of errors. If the caller knows this, they can unwrap the 14 | list and access the errors. If the caller doesn't know, the error 15 | formats to a nice human-readable format. 16 | 17 | `go-multierror` implements the 18 | [errwrap](https://github.com/hashicorp/errwrap) interface so that it can 19 | be used with that library, as well. 20 | 21 | ## Installation and Docs 22 | 23 | Install using `go get github.com/hashicorp/go-multierror`. 24 | 25 | Full documentation is available at 26 | http://godoc.org/github.com/hashicorp/go-multierror 27 | 28 | ## Usage 29 | 30 | go-multierror is easy to use and purposely built to be unobtrusive in 31 | existing Go applications/libraries that may not be aware of it. 32 | 33 | **Building a list of errors** 34 | 35 | The `Append` function is used to create a list of errors. This function 36 | behaves a lot like the Go built-in `append` function: it doesn't matter 37 | if the first argument is nil, a `multierror.Error`, or any other `error`, 38 | the function behaves as you would expect. 39 | 40 | ```go 41 | var result error 42 | 43 | if err := step1(); err != nil { 44 | result = multierror.Append(result, err) 45 | } 46 | if err := step2(); err != nil { 47 | result = multierror.Append(result, err) 48 | } 49 | 50 | return result 51 | ``` 52 | 53 | **Customizing the formatting of the errors** 54 | 55 | By specifying a custom `ErrorFormat`, you can customize the format 56 | of the `Error() string` function: 57 | 58 | ```go 59 | var result *multierror.Error 60 | 61 | // ... accumulate errors here, maybe using Append 62 | 63 | if result != nil { 64 | result.ErrorFormat = func([]error) string { 65 | return "errors!" 66 | } 67 | } 68 | ``` 69 | 70 | **Accessing the list of errors** 71 | 72 | `multierror.Error` implements `error` so if the caller doesn't know about 73 | multierror, it will work just fine. But if you're aware a multierror might 74 | be returned, you can use type switches to access the list of errors: 75 | 76 | ```go 77 | if err := something(); err != nil { 78 | if merr, ok := err.(*multierror.Error); ok { 79 | // Use merr.Errors 80 | } 81 | } 82 | ``` 83 | 84 | **Returning a multierror only if there are errors** 85 | 86 | If you build a `multierror.Error`, you can use the `ErrorOrNil` function 87 | to return an `error` implementation only if there are errors to return: 88 | 89 | ```go 90 | var result *multierror.Error 91 | 92 | // ... accumulate errors here 93 | 94 | // Return the `error` only if errors were added to the multierror, otherwise 95 | // return nil since there are no errors. 96 | return result.ErrorOrNil() 97 | ``` 98 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/append.go: -------------------------------------------------------------------------------- 1 | package multierror 2 | 3 | // Append is a helper function that will append more errors 4 | // onto an Error in order to create a larger multi-error. 5 | // 6 | // If err is not a multierror.Error, then it will be turned into 7 | // one. If any of the errs are multierr.Error, they will be flattened 8 | // one level into err. 9 | func Append(err error, errs ...error) *Error { 10 | switch err := err.(type) { 11 | case *Error: 12 | // Typed nils can reach here, so initialize if we are nil 13 | if err == nil { 14 | err = new(Error) 15 | } 16 | 17 | // Go through each error and flatten 18 | for _, e := range errs { 19 | switch e := e.(type) { 20 | case *Error: 21 | if e != nil { 22 | err.Errors = append(err.Errors, e.Errors...) 23 | } 24 | default: 25 | if e != nil { 26 | err.Errors = append(err.Errors, e) 27 | } 28 | } 29 | } 30 | 31 | return err 32 | default: 33 | newErrs := make([]error, 0, len(errs)+1) 34 | if err != nil { 35 | newErrs = append(newErrs, err) 36 | } 37 | newErrs = append(newErrs, errs...) 38 | 39 | return Append(&Error{}, newErrs...) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/flatten.go: -------------------------------------------------------------------------------- 1 | package multierror 2 | 3 | // Flatten flattens the given error, merging any *Errors together into 4 | // a single *Error. 5 | func Flatten(err error) error { 6 | // If it isn't an *Error, just return the error as-is 7 | if _, ok := err.(*Error); !ok { 8 | return err 9 | } 10 | 11 | // Otherwise, make the result and flatten away! 12 | flatErr := new(Error) 13 | flatten(err, flatErr) 14 | return flatErr 15 | } 16 | 17 | func flatten(err error, flatErr *Error) { 18 | switch err := err.(type) { 19 | case *Error: 20 | for _, e := range err.Errors { 21 | flatten(e, flatErr) 22 | } 23 | default: 24 | flatErr.Errors = append(flatErr.Errors, err) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/format.go: -------------------------------------------------------------------------------- 1 | package multierror 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | // ErrorFormatFunc is a function callback that is called by Error to 9 | // turn the list of errors into a string. 10 | type ErrorFormatFunc func([]error) string 11 | 12 | // ListFormatFunc is a basic formatter that outputs the number of errors 13 | // that occurred along with a bullet point list of the errors. 14 | func ListFormatFunc(es []error) string { 15 | if len(es) == 1 { 16 | return fmt.Sprintf("1 error occurred:\n\n* %s", es[0]) 17 | } 18 | 19 | points := make([]string, len(es)) 20 | for i, err := range es { 21 | points[i] = fmt.Sprintf("* %s", err) 22 | } 23 | 24 | return fmt.Sprintf( 25 | "%d errors occurred:\n\n%s", 26 | len(es), strings.Join(points, "\n")) 27 | } 28 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/multierror.go: -------------------------------------------------------------------------------- 1 | package multierror 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Error is an error type to track multiple errors. This is used to 8 | // accumulate errors in cases and return them as a single "error". 9 | type Error struct { 10 | Errors []error 11 | ErrorFormat ErrorFormatFunc 12 | } 13 | 14 | func (e *Error) Error() string { 15 | fn := e.ErrorFormat 16 | if fn == nil { 17 | fn = ListFormatFunc 18 | } 19 | 20 | return fn(e.Errors) 21 | } 22 | 23 | // ErrorOrNil returns an error interface if this Error represents 24 | // a list of errors, or returns nil if the list of errors is empty. This 25 | // function is useful at the end of accumulation to make sure that the value 26 | // returned represents the existence of errors. 27 | func (e *Error) ErrorOrNil() error { 28 | if e == nil { 29 | return nil 30 | } 31 | if len(e.Errors) == 0 { 32 | return nil 33 | } 34 | 35 | return e 36 | } 37 | 38 | func (e *Error) GoString() string { 39 | return fmt.Sprintf("*%#v", *e) 40 | } 41 | 42 | // WrappedErrors returns the list of errors that this Error is wrapping. 43 | // It is an implementation of the errwrap.Wrapper interface so that 44 | // multierror.Error can be used with that library. 45 | // 46 | // This method is not safe to be called concurrently and is no different 47 | // than accessing the Errors field directly. It is implemented only to 48 | // satisfy the errwrap.Wrapper interface. 49 | func (e *Error) WrappedErrors() []error { 50 | return e.Errors 51 | } 52 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-multierror/prefix.go: -------------------------------------------------------------------------------- 1 | package multierror 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/hashicorp/errwrap" 7 | ) 8 | 9 | // Prefix is a helper function that will prefix some text 10 | // to the given error. If the error is a multierror.Error, then 11 | // it will be prefixed to each wrapped error. 12 | // 13 | // This is useful to use when appending multiple multierrors 14 | // together in order to give better scoping. 15 | func Prefix(err error, prefix string) error { 16 | if err == nil { 17 | return nil 18 | } 19 | 20 | format := fmt.Sprintf("%s {{err}}", prefix) 21 | switch err := err.(type) { 22 | case *Error: 23 | // Typed nils can reach here, so initialize if we are nil 24 | if err == nil { 25 | err = new(Error) 26 | } 27 | 28 | // Wrap each of the errors 29 | for i, e := range err.Errors { 30 | err.Errors[i] = errwrap.Wrapf(format, e) 31 | } 32 | 33 | return err 34 | default: 35 | return errwrap.Wrapf(format, err) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.6 7 | 8 | branches: 9 | only: 10 | - master 11 | 12 | script: make test 13 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/Makefile: -------------------------------------------------------------------------------- 1 | TEST?=./... 2 | 3 | test: 4 | go test $(TEST) $(TESTARGS) -timeout=3s -parallel=4 5 | go vet $(TEST) 6 | go test $(TEST) -race 7 | 8 | .PHONY: test 9 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/README.md: -------------------------------------------------------------------------------- 1 | # rootcerts 2 | 3 | Functions for loading root certificates for TLS connections. 4 | 5 | ----- 6 | 7 | Go's standard library `crypto/tls` provides a common mechanism for configuring 8 | TLS connections in `tls.Config`. The `RootCAs` field on this struct is a pool 9 | of certificates for the client to use as a trust store when verifying server 10 | certificates. 11 | 12 | This library contains utility functions for loading certificates destined for 13 | that field, as well as one other important thing: 14 | 15 | When the `RootCAs` field is `nil`, the standard library attempts to load the 16 | host's root CA set. This behavior is OS-specific, and the Darwin 17 | implementation contains [a bug that prevents trusted certificates from the 18 | System and Login keychains from being loaded][1]. This library contains 19 | Darwin-specific behavior that works around that bug. 20 | 21 | [1]: https://github.com/golang/go/issues/14514 22 | 23 | ## Example Usage 24 | 25 | Here's a snippet demonstrating how this library is meant to be used: 26 | 27 | ```go 28 | func httpClient() (*http.Client, error) 29 | tlsConfig := &tls.Config{} 30 | err := rootcerts.ConfigureTLS(tlsConfig, &rootcerts.Config{ 31 | CAFile: os.Getenv("MYAPP_CAFILE"), 32 | CAPath: os.Getenv("MYAPP_CAPATH"), 33 | }) 34 | if err != nil { 35 | return nil, err 36 | } 37 | c := cleanhttp.DefaultClient() 38 | t := cleanhttp.DefaultTransport() 39 | t.TLSClientConfig = tlsConfig 40 | c.Transport = t 41 | return c, nil 42 | } 43 | ``` 44 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/doc.go: -------------------------------------------------------------------------------- 1 | // Package rootcerts contains functions to aid in loading CA certificates for 2 | // TLS connections. 3 | // 4 | // In addition, its default behavior on Darwin works around an open issue [1] 5 | // in Go's crypto/x509 that prevents certicates from being loaded from the 6 | // System or Login keychains. 7 | // 8 | // [1] https://github.com/golang/go/issues/14514 9 | package rootcerts 10 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/rootcerts.go: -------------------------------------------------------------------------------- 1 | package rootcerts 2 | 3 | import ( 4 | "crypto/tls" 5 | "crypto/x509" 6 | "fmt" 7 | "io/ioutil" 8 | "os" 9 | "path/filepath" 10 | ) 11 | 12 | // Config determines where LoadCACerts will load certificates from. When both 13 | // CAFile and CAPath are blank, this library's functions will either load 14 | // system roots explicitly and return them, or set the CertPool to nil to allow 15 | // Go's standard library to load system certs. 16 | type Config struct { 17 | // CAFile is a path to a PEM-encoded certificate file or bundle. Takes 18 | // precedence over CAPath. 19 | CAFile string 20 | 21 | // CAPath is a path to a directory populated with PEM-encoded certificates. 22 | CAPath string 23 | } 24 | 25 | // ConfigureTLS sets up the RootCAs on the provided tls.Config based on the 26 | // Config specified. 27 | func ConfigureTLS(t *tls.Config, c *Config) error { 28 | if t == nil { 29 | return nil 30 | } 31 | pool, err := LoadCACerts(c) 32 | if err != nil { 33 | return err 34 | } 35 | t.RootCAs = pool 36 | return nil 37 | } 38 | 39 | // LoadCACerts loads a CertPool based on the Config specified. 40 | func LoadCACerts(c *Config) (*x509.CertPool, error) { 41 | if c == nil { 42 | c = &Config{} 43 | } 44 | if c.CAFile != "" { 45 | return LoadCAFile(c.CAFile) 46 | } 47 | if c.CAPath != "" { 48 | return LoadCAPath(c.CAPath) 49 | } 50 | 51 | return LoadSystemCAs() 52 | } 53 | 54 | // LoadCAFile loads a single PEM-encoded file from the path specified. 55 | func LoadCAFile(caFile string) (*x509.CertPool, error) { 56 | pool := x509.NewCertPool() 57 | 58 | pem, err := ioutil.ReadFile(caFile) 59 | if err != nil { 60 | return nil, fmt.Errorf("Error loading CA File: %s", err) 61 | } 62 | 63 | ok := pool.AppendCertsFromPEM(pem) 64 | if !ok { 65 | return nil, fmt.Errorf("Error loading CA File: Couldn't parse PEM in: %s", caFile) 66 | } 67 | 68 | return pool, nil 69 | } 70 | 71 | // LoadCAPath walks the provided path and loads all certificates encounted into 72 | // a pool. 73 | func LoadCAPath(caPath string) (*x509.CertPool, error) { 74 | pool := x509.NewCertPool() 75 | walkFn := func(path string, info os.FileInfo, err error) error { 76 | if err != nil { 77 | return err 78 | } 79 | 80 | if info.IsDir() { 81 | return nil 82 | } 83 | 84 | pem, err := ioutil.ReadFile(path) 85 | if err != nil { 86 | return fmt.Errorf("Error loading file from CAPath: %s", err) 87 | } 88 | 89 | ok := pool.AppendCertsFromPEM(pem) 90 | if !ok { 91 | return fmt.Errorf("Error loading CA Path: Couldn't parse PEM in: %s", path) 92 | } 93 | 94 | return nil 95 | } 96 | 97 | err := filepath.Walk(caPath, walkFn) 98 | if err != nil { 99 | return nil, err 100 | } 101 | 102 | return pool, nil 103 | } 104 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/rootcerts_base.go: -------------------------------------------------------------------------------- 1 | // +build !darwin 2 | 3 | package rootcerts 4 | 5 | import "crypto/x509" 6 | 7 | // LoadSystemCAs does nothing on non-Darwin systems. We return nil so that 8 | // default behavior of standard TLS config libraries is triggered, which is to 9 | // load system certs. 10 | func LoadSystemCAs() (*x509.CertPool, error) { 11 | return nil, nil 12 | } 13 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/go-rootcerts/rootcerts_darwin.go: -------------------------------------------------------------------------------- 1 | package rootcerts 2 | 3 | import ( 4 | "crypto/x509" 5 | "os/exec" 6 | "path" 7 | 8 | "github.com/mitchellh/go-homedir" 9 | ) 10 | 11 | // LoadSystemCAs has special behavior on Darwin systems to work around 12 | func LoadSystemCAs() (*x509.CertPool, error) { 13 | pool := x509.NewCertPool() 14 | 15 | for _, keychain := range certKeychains() { 16 | err := addCertsFromKeychain(pool, keychain) 17 | if err != nil { 18 | return nil, err 19 | } 20 | } 21 | 22 | return pool, nil 23 | } 24 | 25 | func addCertsFromKeychain(pool *x509.CertPool, keychain string) error { 26 | cmd := exec.Command("/usr/bin/security", "find-certificate", "-a", "-p", keychain) 27 | data, err := cmd.Output() 28 | if err != nil { 29 | return err 30 | } 31 | 32 | pool.AppendCertsFromPEM(data) 33 | 34 | return nil 35 | } 36 | 37 | func certKeychains() []string { 38 | keychains := []string{ 39 | "/System/Library/Keychains/SystemRootCertificates.keychain", 40 | "/Library/Keychains/System.keychain", 41 | } 42 | home, err := homedir.Dir() 43 | if err == nil { 44 | loginKeychain := path.Join(home, "Library", "Keychains", "login.keychain") 45 | keychains = append(keychains, loginKeychain) 46 | } 47 | return keychains 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/.gitignore: -------------------------------------------------------------------------------- 1 | y.output 2 | 3 | # ignore intellij files 4 | .idea 5 | *.iml 6 | *.ipr 7 | *.iws 8 | 9 | *.test 10 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | 3 | language: go 4 | 5 | go: 6 | - 1.x 7 | - tip 8 | 9 | branches: 10 | only: 11 | - master 12 | 13 | script: make test 14 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/Makefile: -------------------------------------------------------------------------------- 1 | TEST?=./... 2 | 3 | default: test 4 | 5 | fmt: generate 6 | go fmt ./... 7 | 8 | test: generate 9 | go get -t ./... 10 | go test $(TEST) $(TESTARGS) 11 | 12 | generate: 13 | go generate ./... 14 | 15 | updatedeps: 16 | go get -u golang.org/x/tools/cmd/stringer 17 | 18 | .PHONY: default generate test updatedeps 19 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/appveyor.yml: -------------------------------------------------------------------------------- 1 | version: "build-{branch}-{build}" 2 | image: Visual Studio 2015 3 | clone_folder: c:\gopath\src\github.com\hashicorp\hcl 4 | environment: 5 | GOPATH: c:\gopath 6 | init: 7 | - git config --global core.autocrlf false 8 | install: 9 | - cmd: >- 10 | echo %Path% 11 | 12 | go version 13 | 14 | go env 15 | 16 | go get -t ./... 17 | 18 | build_script: 19 | - cmd: go test -v ./... 20 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/hcl.go: -------------------------------------------------------------------------------- 1 | // Package hcl decodes HCL into usable Go structures. 2 | // 3 | // hcl input can come in either pure HCL format or JSON format. 4 | // It can be parsed into an AST, and then decoded into a structure, 5 | // or it can be decoded directly from a string into a structure. 6 | // 7 | // If you choose to parse HCL into a raw AST, the benefit is that you 8 | // can write custom visitor implementations to implement custom 9 | // semantic checks. By default, HCL does not perform any semantic 10 | // checks. 11 | package hcl 12 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/hcl/ast/walk.go: -------------------------------------------------------------------------------- 1 | package ast 2 | 3 | import "fmt" 4 | 5 | // WalkFunc describes a function to be called for each node during a Walk. The 6 | // returned node can be used to rewrite the AST. Walking stops the returned 7 | // bool is false. 8 | type WalkFunc func(Node) (Node, bool) 9 | 10 | // Walk traverses an AST in depth-first order: It starts by calling fn(node); 11 | // node must not be nil. If fn returns true, Walk invokes fn recursively for 12 | // each of the non-nil children of node, followed by a call of fn(nil). The 13 | // returned node of fn can be used to rewrite the passed node to fn. 14 | func Walk(node Node, fn WalkFunc) Node { 15 | rewritten, ok := fn(node) 16 | if !ok { 17 | return rewritten 18 | } 19 | 20 | switch n := node.(type) { 21 | case *File: 22 | n.Node = Walk(n.Node, fn) 23 | case *ObjectList: 24 | for i, item := range n.Items { 25 | n.Items[i] = Walk(item, fn).(*ObjectItem) 26 | } 27 | case *ObjectKey: 28 | // nothing to do 29 | case *ObjectItem: 30 | for i, k := range n.Keys { 31 | n.Keys[i] = Walk(k, fn).(*ObjectKey) 32 | } 33 | 34 | if n.Val != nil { 35 | n.Val = Walk(n.Val, fn) 36 | } 37 | case *LiteralType: 38 | // nothing to do 39 | case *ListType: 40 | for i, l := range n.List { 41 | n.List[i] = Walk(l, fn) 42 | } 43 | case *ObjectType: 44 | n.List = Walk(n.List, fn).(*ObjectList) 45 | default: 46 | // should we panic here? 47 | fmt.Printf("unknown type: %T\n", n) 48 | } 49 | 50 | fn(nil) 51 | return rewritten 52 | } 53 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/hcl/parser/error.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/hashicorp/hcl/hcl/token" 7 | ) 8 | 9 | // PosError is a parse error that contains a position. 10 | type PosError struct { 11 | Pos token.Pos 12 | Err error 13 | } 14 | 15 | func (e *PosError) Error() string { 16 | return fmt.Sprintf("At %s: %s", e.Pos, e.Err) 17 | } 18 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/hcl/token/position.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import "fmt" 4 | 5 | // Pos describes an arbitrary source position 6 | // including the file, line, and column location. 7 | // A Position is valid if the line number is > 0. 8 | type Pos struct { 9 | Filename string // filename, if any 10 | Offset int // offset, starting at 0 11 | Line int // line number, starting at 1 12 | Column int // column number, starting at 1 (character count) 13 | } 14 | 15 | // IsValid returns true if the position is valid. 16 | func (p *Pos) IsValid() bool { return p.Line > 0 } 17 | 18 | // String returns a string in one of several forms: 19 | // 20 | // file:line:column valid position with file name 21 | // line:column valid position without file name 22 | // file invalid position with file name 23 | // - invalid position without file name 24 | func (p Pos) String() string { 25 | s := p.Filename 26 | if p.IsValid() { 27 | if s != "" { 28 | s += ":" 29 | } 30 | s += fmt.Sprintf("%d:%d", p.Line, p.Column) 31 | } 32 | if s == "" { 33 | s = "-" 34 | } 35 | return s 36 | } 37 | 38 | // Before reports whether the position p is before u. 39 | func (p Pos) Before(u Pos) bool { 40 | return u.Offset > p.Offset || u.Line > p.Line 41 | } 42 | 43 | // After reports whether the position p is after u. 44 | func (p Pos) After(u Pos) bool { 45 | return u.Offset < p.Offset || u.Line < p.Line 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/json/parser/flatten.go: -------------------------------------------------------------------------------- 1 | package parser 2 | 3 | import "github.com/hashicorp/hcl/hcl/ast" 4 | 5 | // flattenObjects takes an AST node, walks it, and flattens 6 | func flattenObjects(node ast.Node) { 7 | ast.Walk(node, func(n ast.Node) (ast.Node, bool) { 8 | // We only care about lists, because this is what we modify 9 | list, ok := n.(*ast.ObjectList) 10 | if !ok { 11 | return n, true 12 | } 13 | 14 | // Rebuild the item list 15 | items := make([]*ast.ObjectItem, 0, len(list.Items)) 16 | frontier := make([]*ast.ObjectItem, len(list.Items)) 17 | copy(frontier, list.Items) 18 | for len(frontier) > 0 { 19 | // Pop the current item 20 | n := len(frontier) 21 | item := frontier[n-1] 22 | frontier = frontier[:n-1] 23 | 24 | switch v := item.Val.(type) { 25 | case *ast.ObjectType: 26 | items, frontier = flattenObjectType(v, item, items, frontier) 27 | case *ast.ListType: 28 | items, frontier = flattenListType(v, item, items, frontier) 29 | default: 30 | items = append(items, item) 31 | } 32 | } 33 | 34 | // Reverse the list since the frontier model runs things backwards 35 | for i := len(items)/2 - 1; i >= 0; i-- { 36 | opp := len(items) - 1 - i 37 | items[i], items[opp] = items[opp], items[i] 38 | } 39 | 40 | // Done! Set the original items 41 | list.Items = items 42 | return n, true 43 | }) 44 | } 45 | 46 | func flattenListType( 47 | ot *ast.ListType, 48 | item *ast.ObjectItem, 49 | items []*ast.ObjectItem, 50 | frontier []*ast.ObjectItem) ([]*ast.ObjectItem, []*ast.ObjectItem) { 51 | // If the list is empty, keep the original list 52 | if len(ot.List) == 0 { 53 | items = append(items, item) 54 | return items, frontier 55 | } 56 | 57 | // All the elements of this object must also be objects! 58 | for _, subitem := range ot.List { 59 | if _, ok := subitem.(*ast.ObjectType); !ok { 60 | items = append(items, item) 61 | return items, frontier 62 | } 63 | } 64 | 65 | // Great! We have a match go through all the items and flatten 66 | for _, elem := range ot.List { 67 | // Add it to the frontier so that we can recurse 68 | frontier = append(frontier, &ast.ObjectItem{ 69 | Keys: item.Keys, 70 | Assign: item.Assign, 71 | Val: elem, 72 | LeadComment: item.LeadComment, 73 | LineComment: item.LineComment, 74 | }) 75 | } 76 | 77 | return items, frontier 78 | } 79 | 80 | func flattenObjectType( 81 | ot *ast.ObjectType, 82 | item *ast.ObjectItem, 83 | items []*ast.ObjectItem, 84 | frontier []*ast.ObjectItem) ([]*ast.ObjectItem, []*ast.ObjectItem) { 85 | // If the list has no items we do not have to flatten anything 86 | if ot.List.Items == nil { 87 | items = append(items, item) 88 | return items, frontier 89 | } 90 | 91 | // All the elements of this object must also be objects! 92 | for _, subitem := range ot.List.Items { 93 | if _, ok := subitem.Val.(*ast.ObjectType); !ok { 94 | items = append(items, item) 95 | return items, frontier 96 | } 97 | } 98 | 99 | // Great! We have a match go through all the items and flatten 100 | for _, subitem := range ot.List.Items { 101 | // Copy the new key 102 | keys := make([]*ast.ObjectKey, len(item.Keys)+len(subitem.Keys)) 103 | copy(keys, item.Keys) 104 | copy(keys[len(item.Keys):], subitem.Keys) 105 | 106 | // Add it to the frontier so that we can recurse 107 | frontier = append(frontier, &ast.ObjectItem{ 108 | Keys: keys, 109 | Assign: item.Assign, 110 | Val: subitem.Val, 111 | LeadComment: item.LeadComment, 112 | LineComment: item.LineComment, 113 | }) 114 | } 115 | 116 | return items, frontier 117 | } 118 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/json/token/position.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import "fmt" 4 | 5 | // Pos describes an arbitrary source position 6 | // including the file, line, and column location. 7 | // A Position is valid if the line number is > 0. 8 | type Pos struct { 9 | Filename string // filename, if any 10 | Offset int // offset, starting at 0 11 | Line int // line number, starting at 1 12 | Column int // column number, starting at 1 (character count) 13 | } 14 | 15 | // IsValid returns true if the position is valid. 16 | func (p *Pos) IsValid() bool { return p.Line > 0 } 17 | 18 | // String returns a string in one of several forms: 19 | // 20 | // file:line:column valid position with file name 21 | // line:column valid position without file name 22 | // file invalid position with file name 23 | // - invalid position without file name 24 | func (p Pos) String() string { 25 | s := p.Filename 26 | if p.IsValid() { 27 | if s != "" { 28 | s += ":" 29 | } 30 | s += fmt.Sprintf("%d:%d", p.Line, p.Column) 31 | } 32 | if s == "" { 33 | s = "-" 34 | } 35 | return s 36 | } 37 | 38 | // Before reports whether the position p is before u. 39 | func (p Pos) Before(u Pos) bool { 40 | return u.Offset > p.Offset || u.Line > p.Line 41 | } 42 | 43 | // After reports whether the position p is after u. 44 | func (p Pos) After(u Pos) bool { 45 | return u.Offset < p.Offset || u.Line < p.Line 46 | } 47 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/json/token/token.go: -------------------------------------------------------------------------------- 1 | package token 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | 7 | hcltoken "github.com/hashicorp/hcl/hcl/token" 8 | ) 9 | 10 | // Token defines a single HCL token which can be obtained via the Scanner 11 | type Token struct { 12 | Type Type 13 | Pos Pos 14 | Text string 15 | } 16 | 17 | // Type is the set of lexical tokens of the HCL (HashiCorp Configuration Language) 18 | type Type int 19 | 20 | const ( 21 | // Special tokens 22 | ILLEGAL Type = iota 23 | EOF 24 | 25 | identifier_beg 26 | literal_beg 27 | NUMBER // 12345 28 | FLOAT // 123.45 29 | BOOL // true,false 30 | STRING // "abc" 31 | NULL // null 32 | literal_end 33 | identifier_end 34 | 35 | operator_beg 36 | LBRACK // [ 37 | LBRACE // { 38 | COMMA // , 39 | PERIOD // . 40 | COLON // : 41 | 42 | RBRACK // ] 43 | RBRACE // } 44 | 45 | operator_end 46 | ) 47 | 48 | var tokens = [...]string{ 49 | ILLEGAL: "ILLEGAL", 50 | 51 | EOF: "EOF", 52 | 53 | NUMBER: "NUMBER", 54 | FLOAT: "FLOAT", 55 | BOOL: "BOOL", 56 | STRING: "STRING", 57 | NULL: "NULL", 58 | 59 | LBRACK: "LBRACK", 60 | LBRACE: "LBRACE", 61 | COMMA: "COMMA", 62 | PERIOD: "PERIOD", 63 | COLON: "COLON", 64 | 65 | RBRACK: "RBRACK", 66 | RBRACE: "RBRACE", 67 | } 68 | 69 | // String returns the string corresponding to the token tok. 70 | func (t Type) String() string { 71 | s := "" 72 | if 0 <= t && t < Type(len(tokens)) { 73 | s = tokens[t] 74 | } 75 | if s == "" { 76 | s = "token(" + strconv.Itoa(int(t)) + ")" 77 | } 78 | return s 79 | } 80 | 81 | // IsIdentifier returns true for tokens corresponding to identifiers and basic 82 | // type literals; it returns false otherwise. 83 | func (t Type) IsIdentifier() bool { return identifier_beg < t && t < identifier_end } 84 | 85 | // IsLiteral returns true for tokens corresponding to basic type literals; it 86 | // returns false otherwise. 87 | func (t Type) IsLiteral() bool { return literal_beg < t && t < literal_end } 88 | 89 | // IsOperator returns true for tokens corresponding to operators and 90 | // delimiters; it returns false otherwise. 91 | func (t Type) IsOperator() bool { return operator_beg < t && t < operator_end } 92 | 93 | // String returns the token's literal text. Note that this is only 94 | // applicable for certain token types, such as token.IDENT, 95 | // token.STRING, etc.. 96 | func (t Token) String() string { 97 | return fmt.Sprintf("%s %s %s", t.Pos.String(), t.Type.String(), t.Text) 98 | } 99 | 100 | // HCLToken converts this token to an HCL token. 101 | // 102 | // The token type must be a literal type or this will panic. 103 | func (t Token) HCLToken() hcltoken.Token { 104 | switch t.Type { 105 | case BOOL: 106 | return hcltoken.Token{Type: hcltoken.BOOL, Text: t.Text} 107 | case FLOAT: 108 | return hcltoken.Token{Type: hcltoken.FLOAT, Text: t.Text} 109 | case NULL: 110 | return hcltoken.Token{Type: hcltoken.STRING, Text: ""} 111 | case NUMBER: 112 | return hcltoken.Token{Type: hcltoken.NUMBER, Text: t.Text} 113 | case STRING: 114 | return hcltoken.Token{Type: hcltoken.STRING, Text: t.Text, JSON: true} 115 | default: 116 | panic(fmt.Sprintf("unimplemented HCLToken for type: %s", t.Type)) 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/lex.go: -------------------------------------------------------------------------------- 1 | package hcl 2 | 3 | import ( 4 | "unicode" 5 | "unicode/utf8" 6 | ) 7 | 8 | type lexModeValue byte 9 | 10 | const ( 11 | lexModeUnknown lexModeValue = iota 12 | lexModeHcl 13 | lexModeJson 14 | ) 15 | 16 | // lexMode returns whether we're going to be parsing in JSON 17 | // mode or HCL mode. 18 | func lexMode(v []byte) lexModeValue { 19 | var ( 20 | r rune 21 | w int 22 | offset int 23 | ) 24 | 25 | for { 26 | r, w = utf8.DecodeRune(v[offset:]) 27 | offset += w 28 | if unicode.IsSpace(r) { 29 | continue 30 | } 31 | if r == '{' { 32 | return lexModeJson 33 | } 34 | break 35 | } 36 | 37 | return lexModeHcl 38 | } 39 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/hcl/parse.go: -------------------------------------------------------------------------------- 1 | package hcl 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/hashicorp/hcl/hcl/ast" 7 | hclParser "github.com/hashicorp/hcl/hcl/parser" 8 | jsonParser "github.com/hashicorp/hcl/json/parser" 9 | ) 10 | 11 | // ParseBytes accepts as input byte slice and returns ast tree. 12 | // 13 | // Input can be either JSON or HCL 14 | func ParseBytes(in []byte) (*ast.File, error) { 15 | return parse(in) 16 | } 17 | 18 | // ParseString accepts input as a string and returns ast tree. 19 | func ParseString(input string) (*ast.File, error) { 20 | return parse([]byte(input)) 21 | } 22 | 23 | func parse(in []byte) (*ast.File, error) { 24 | switch lexMode(in) { 25 | case lexModeHcl: 26 | return hclParser.Parse(in) 27 | case lexModeJson: 28 | return jsonParser.Parse(in) 29 | } 30 | 31 | return nil, fmt.Errorf("unknown config format") 32 | } 33 | 34 | // Parse parses the given input and returns the root object. 35 | // 36 | // The input format can be either HCL or JSON. 37 | func Parse(input string) (*ast.File, error) { 38 | return parse([]byte(input)) 39 | } 40 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/auth.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // Auth is used to perform credential backend related operations. 4 | type Auth struct { 5 | c *Client 6 | } 7 | 8 | // Auth is used to return the client for credential-backend API calls. 9 | func (c *Client) Auth() *Auth { 10 | return &Auth{c: c} 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/help.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | ) 6 | 7 | // Help reads the help information for the given path. 8 | func (c *Client) Help(path string) (*Help, error) { 9 | r := c.NewRequest("GET", fmt.Sprintf("/v1/%s", path)) 10 | r.Params.Add("help", "1") 11 | resp, err := c.RawRequest(r) 12 | if err != nil { 13 | return nil, err 14 | } 15 | defer resp.Body.Close() 16 | 17 | var result Help 18 | err = resp.DecodeJSON(&result) 19 | return &result, err 20 | } 21 | 22 | type Help struct { 23 | Help string `json:"help"` 24 | SeeAlso []string `json:"see_also"` 25 | } 26 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/request.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "bytes" 5 | "encoding/json" 6 | "io" 7 | "net/http" 8 | "net/url" 9 | ) 10 | 11 | // Request is a raw request configuration structure used to initiate 12 | // API requests to the Vault server. 13 | type Request struct { 14 | Method string 15 | URL *url.URL 16 | Params url.Values 17 | Headers http.Header 18 | ClientToken string 19 | MFAHeaderVals []string 20 | WrapTTL string 21 | Obj interface{} 22 | Body io.Reader 23 | BodySize int64 24 | 25 | // Whether to request overriding soft-mandatory Sentinel policies (RGPs and 26 | // EGPs). If set, the override flag will take effect for all policies 27 | // evaluated during the request. 28 | PolicyOverride bool 29 | } 30 | 31 | // SetJSONBody is used to set a request body that is a JSON-encoded value. 32 | func (r *Request) SetJSONBody(val interface{}) error { 33 | buf := bytes.NewBuffer(nil) 34 | enc := json.NewEncoder(buf) 35 | if err := enc.Encode(val); err != nil { 36 | return err 37 | } 38 | 39 | r.Obj = val 40 | r.Body = buf 41 | r.BodySize = int64(buf.Len()) 42 | return nil 43 | } 44 | 45 | // ResetJSONBody is used to reset the body for a redirect 46 | func (r *Request) ResetJSONBody() error { 47 | if r.Body == nil { 48 | return nil 49 | } 50 | return r.SetJSONBody(r.Obj) 51 | } 52 | 53 | // ToHTTP turns this request into a valid *http.Request for use with the 54 | // net/http package. 55 | func (r *Request) ToHTTP() (*http.Request, error) { 56 | // Encode the query parameters 57 | r.URL.RawQuery = r.Params.Encode() 58 | 59 | // Create the HTTP request 60 | req, err := http.NewRequest(r.Method, r.URL.RequestURI(), r.Body) 61 | if err != nil { 62 | return nil, err 63 | } 64 | 65 | req.URL.User = r.URL.User 66 | req.URL.Scheme = r.URL.Scheme 67 | req.URL.Host = r.URL.Host 68 | req.Host = r.URL.Host 69 | 70 | if r.Headers != nil { 71 | for header, vals := range r.Headers { 72 | for _, val := range vals { 73 | req.Header.Add(header, val) 74 | } 75 | } 76 | } 77 | 78 | if len(r.ClientToken) != 0 { 79 | req.Header.Set("X-Vault-Token", r.ClientToken) 80 | } 81 | 82 | if len(r.WrapTTL) != 0 { 83 | req.Header.Set("X-Vault-Wrap-TTL", r.WrapTTL) 84 | } 85 | 86 | if len(r.MFAHeaderVals) != 0 { 87 | for _, mfaHeaderVal := range r.MFAHeaderVals { 88 | req.Header.Add("X-Vault-MFA", mfaHeaderVal) 89 | } 90 | } 91 | 92 | if r.PolicyOverride { 93 | req.Header.Set("X-Vault-Policy-Override", "true") 94 | } 95 | 96 | return req, nil 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/response.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io" 7 | "net/http" 8 | 9 | "github.com/hashicorp/vault/helper/jsonutil" 10 | ) 11 | 12 | // Response is a raw response that wraps an HTTP response. 13 | type Response struct { 14 | *http.Response 15 | } 16 | 17 | // DecodeJSON will decode the response body to a JSON structure. This 18 | // will consume the response body, but will not close it. Close must 19 | // still be called. 20 | func (r *Response) DecodeJSON(out interface{}) error { 21 | return jsonutil.DecodeJSONFromReader(r.Body, out) 22 | } 23 | 24 | // Error returns an error response if there is one. If there is an error, 25 | // this will fully consume the response body, but will not close it. The 26 | // body must still be closed manually. 27 | func (r *Response) Error() error { 28 | // 200 to 399 are okay status codes. 429 is the code for health status of 29 | // standby nodes. 30 | if (r.StatusCode >= 200 && r.StatusCode < 400) || r.StatusCode == 429 { 31 | return nil 32 | } 33 | 34 | // We have an error. Let's copy the body into our own buffer first, 35 | // so that if we can't decode JSON, we can at least copy it raw. 36 | var bodyBuf bytes.Buffer 37 | if _, err := io.Copy(&bodyBuf, r.Body); err != nil { 38 | return err 39 | } 40 | 41 | // Decode the error response if we can. Note that we wrap the bodyBuf 42 | // in a bytes.Reader here so that the JSON decoder doesn't move the 43 | // read pointer for the original buffer. 44 | var resp ErrorResponse 45 | if err := jsonutil.DecodeJSON(bodyBuf.Bytes(), &resp); err != nil { 46 | // Ignore the decoding error and just drop the raw response 47 | return fmt.Errorf( 48 | "Error making API request.\n\n"+ 49 | "URL: %s %s\n"+ 50 | "Code: %d. Raw Message:\n\n%s", 51 | r.Request.Method, r.Request.URL.String(), 52 | r.StatusCode, bodyBuf.String()) 53 | } 54 | 55 | var errBody bytes.Buffer 56 | errBody.WriteString(fmt.Sprintf( 57 | "Error making API request.\n\n"+ 58 | "URL: %s %s\n"+ 59 | "Code: %d. Errors:\n\n", 60 | r.Request.Method, r.Request.URL.String(), 61 | r.StatusCode)) 62 | for _, err := range resp.Errors { 63 | errBody.WriteString(fmt.Sprintf("* %s", err)) 64 | } 65 | 66 | return fmt.Errorf(errBody.String()) 67 | } 68 | 69 | // ErrorResponse is the raw structure of errors when they're returned by the 70 | // HTTP API. 71 | type ErrorResponse struct { 72 | Errors []string 73 | } 74 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/ssh.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import "fmt" 4 | 5 | // SSH is used to return a client to invoke operations on SSH backend. 6 | type SSH struct { 7 | c *Client 8 | MountPoint string 9 | } 10 | 11 | // SSH returns the client for logical-backend API calls. 12 | func (c *Client) SSH() *SSH { 13 | return c.SSHWithMountPoint(SSHHelperDefaultMountPoint) 14 | } 15 | 16 | // SSHWithMountPoint returns the client with specific SSH mount point. 17 | func (c *Client) SSHWithMountPoint(mountPoint string) *SSH { 18 | return &SSH{ 19 | c: c, 20 | MountPoint: mountPoint, 21 | } 22 | } 23 | 24 | // Credential invokes the SSH backend API to create a credential to establish an SSH session. 25 | func (c *SSH) Credential(role string, data map[string]interface{}) (*Secret, error) { 26 | r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/%s/creds/%s", c.MountPoint, role)) 27 | if err := r.SetJSONBody(data); err != nil { 28 | return nil, err 29 | } 30 | 31 | resp, err := c.c.RawRequest(r) 32 | if err != nil { 33 | return nil, err 34 | } 35 | defer resp.Body.Close() 36 | 37 | return ParseSecret(resp.Body) 38 | } 39 | 40 | // SignKey signs the given public key and returns a signed public key to pass 41 | // along with the SSH request. 42 | func (c *SSH) SignKey(role string, data map[string]interface{}) (*Secret, error) { 43 | r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/%s/sign/%s", c.MountPoint, role)) 44 | if err := r.SetJSONBody(data); err != nil { 45 | return nil, err 46 | } 47 | 48 | resp, err := c.c.RawRequest(r) 49 | if err != nil { 50 | return nil, err 51 | } 52 | defer resp.Body.Close() 53 | 54 | return ParseSecret(resp.Body) 55 | } 56 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | // Sys is used to perform system-related operations on Vault. 4 | type Sys struct { 5 | c *Client 6 | } 7 | 8 | // Sys is used to return the client for sys-related API calls. 9 | func (c *Client) Sys() *Sys { 10 | return &Sys{c: c} 11 | } 12 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_audit.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/structs" 7 | "github.com/mitchellh/mapstructure" 8 | ) 9 | 10 | func (c *Sys) AuditHash(path string, input string) (string, error) { 11 | body := map[string]interface{}{ 12 | "input": input, 13 | } 14 | 15 | r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/audit-hash/%s", path)) 16 | if err := r.SetJSONBody(body); err != nil { 17 | return "", err 18 | } 19 | 20 | resp, err := c.c.RawRequest(r) 21 | if err != nil { 22 | return "", err 23 | } 24 | defer resp.Body.Close() 25 | 26 | type d struct { 27 | Hash string `json:"hash"` 28 | } 29 | 30 | var result d 31 | err = resp.DecodeJSON(&result) 32 | if err != nil { 33 | return "", err 34 | } 35 | 36 | return result.Hash, err 37 | } 38 | 39 | func (c *Sys) ListAudit() (map[string]*Audit, error) { 40 | r := c.c.NewRequest("GET", "/v1/sys/audit") 41 | resp, err := c.c.RawRequest(r) 42 | if err != nil { 43 | return nil, err 44 | } 45 | defer resp.Body.Close() 46 | 47 | var result map[string]interface{} 48 | err = resp.DecodeJSON(&result) 49 | if err != nil { 50 | return nil, err 51 | } 52 | 53 | mounts := map[string]*Audit{} 54 | for k, v := range result { 55 | switch v.(type) { 56 | case map[string]interface{}: 57 | default: 58 | continue 59 | } 60 | var res Audit 61 | err = mapstructure.Decode(v, &res) 62 | if err != nil { 63 | return nil, err 64 | } 65 | // Not a mount, some other api.Secret data 66 | if res.Type == "" { 67 | continue 68 | } 69 | mounts[k] = &res 70 | } 71 | 72 | return mounts, nil 73 | } 74 | 75 | // DEPRECATED: Use EnableAuditWithOptions instead 76 | func (c *Sys) EnableAudit( 77 | path string, auditType string, desc string, opts map[string]string) error { 78 | return c.EnableAuditWithOptions(path, &EnableAuditOptions{ 79 | Type: auditType, 80 | Description: desc, 81 | Options: opts, 82 | }) 83 | } 84 | 85 | func (c *Sys) EnableAuditWithOptions(path string, options *EnableAuditOptions) error { 86 | body := structs.Map(options) 87 | 88 | r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/audit/%s", path)) 89 | if err := r.SetJSONBody(body); err != nil { 90 | return err 91 | } 92 | 93 | resp, err := c.c.RawRequest(r) 94 | if err != nil { 95 | return err 96 | } 97 | defer resp.Body.Close() 98 | 99 | return nil 100 | } 101 | 102 | func (c *Sys) DisableAudit(path string) error { 103 | r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/audit/%s", path)) 104 | resp, err := c.c.RawRequest(r) 105 | if err == nil { 106 | defer resp.Body.Close() 107 | } 108 | return err 109 | } 110 | 111 | // Structures for the requests/resposne are all down here. They aren't 112 | // individually documented because the map almost directly to the raw HTTP API 113 | // documentation. Please refer to that documentation for more details. 114 | 115 | type EnableAuditOptions struct { 116 | Type string `json:"type" structs:"type"` 117 | Description string `json:"description" structs:"description"` 118 | Options map[string]string `json:"options" structs:"options"` 119 | Local bool `json:"local" structs:"local"` 120 | } 121 | 122 | type Audit struct { 123 | Path string 124 | Type string 125 | Description string 126 | Options map[string]string 127 | Local bool 128 | } 129 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_auth.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/fatih/structs" 7 | "github.com/mitchellh/mapstructure" 8 | ) 9 | 10 | func (c *Sys) ListAuth() (map[string]*AuthMount, error) { 11 | r := c.c.NewRequest("GET", "/v1/sys/auth") 12 | resp, err := c.c.RawRequest(r) 13 | if err != nil { 14 | return nil, err 15 | } 16 | defer resp.Body.Close() 17 | 18 | var result map[string]interface{} 19 | err = resp.DecodeJSON(&result) 20 | if err != nil { 21 | return nil, err 22 | } 23 | 24 | mounts := map[string]*AuthMount{} 25 | for k, v := range result { 26 | switch v.(type) { 27 | case map[string]interface{}: 28 | default: 29 | continue 30 | } 31 | var res AuthMount 32 | err = mapstructure.Decode(v, &res) 33 | if err != nil { 34 | return nil, err 35 | } 36 | // Not a mount, some other api.Secret data 37 | if res.Type == "" { 38 | continue 39 | } 40 | mounts[k] = &res 41 | } 42 | 43 | return mounts, nil 44 | } 45 | 46 | // DEPRECATED: Use EnableAuthWithOptions instead 47 | func (c *Sys) EnableAuth(path, authType, desc string) error { 48 | return c.EnableAuthWithOptions(path, &EnableAuthOptions{ 49 | Type: authType, 50 | Description: desc, 51 | }) 52 | } 53 | 54 | func (c *Sys) EnableAuthWithOptions(path string, options *EnableAuthOptions) error { 55 | body := structs.Map(options) 56 | 57 | r := c.c.NewRequest("POST", fmt.Sprintf("/v1/sys/auth/%s", path)) 58 | if err := r.SetJSONBody(body); err != nil { 59 | return err 60 | } 61 | 62 | resp, err := c.c.RawRequest(r) 63 | if err != nil { 64 | return err 65 | } 66 | defer resp.Body.Close() 67 | 68 | return nil 69 | } 70 | 71 | func (c *Sys) DisableAuth(path string) error { 72 | r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/auth/%s", path)) 73 | resp, err := c.c.RawRequest(r) 74 | if err == nil { 75 | defer resp.Body.Close() 76 | } 77 | return err 78 | } 79 | 80 | // Structures for the requests/resposne are all down here. They aren't 81 | // individually documentd because the map almost directly to the raw HTTP API 82 | // documentation. Please refer to that documentation for more details. 83 | 84 | type EnableAuthOptions struct { 85 | Type string `json:"type" structs:"type"` 86 | Description string `json:"description" structs:"description"` 87 | Config AuthConfigInput `json:"config" structs:"config"` 88 | Local bool `json:"local" structs:"local"` 89 | PluginName string `json:"plugin_name,omitempty" structs:"plugin_name,omitempty"` 90 | SealWrap bool `json:"seal_wrap" structs:"seal_wrap" mapstructure:"seal_wrap"` 91 | } 92 | 93 | type AuthConfigInput struct { 94 | PluginName string `json:"plugin_name,omitempty" structs:"plugin_name,omitempty" mapstructure:"plugin_name"` 95 | } 96 | 97 | type AuthMount struct { 98 | Type string `json:"type" structs:"type" mapstructure:"type"` 99 | Description string `json:"description" structs:"description" mapstructure:"description"` 100 | Accessor string `json:"accessor" structs:"accessor" mapstructure:"accessor"` 101 | Config AuthConfigOutput `json:"config" structs:"config" mapstructure:"config"` 102 | Local bool `json:"local" structs:"local" mapstructure:"local"` 103 | SealWrap bool `json:"seal_wrap" structs:"seal_wrap" mapstructure:"seal_wrap"` 104 | } 105 | 106 | type AuthConfigOutput struct { 107 | DefaultLeaseTTL int `json:"default_lease_ttl" structs:"default_lease_ttl" mapstructure:"default_lease_ttl"` 108 | MaxLeaseTTL int `json:"max_lease_ttl" structs:"max_lease_ttl" mapstructure:"max_lease_ttl"` 109 | PluginName string `json:"plugin_name,omitempty" structs:"plugin_name,omitempty" mapstructure:"plugin_name"` 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_capabilities.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import "fmt" 4 | 5 | func (c *Sys) CapabilitiesSelf(path string) ([]string, error) { 6 | return c.Capabilities(c.c.Token(), path) 7 | } 8 | 9 | func (c *Sys) Capabilities(token, path string) ([]string, error) { 10 | body := map[string]string{ 11 | "token": token, 12 | "path": path, 13 | } 14 | 15 | reqPath := "/v1/sys/capabilities" 16 | if token == c.c.Token() { 17 | reqPath = fmt.Sprintf("%s-self", reqPath) 18 | } 19 | 20 | r := c.c.NewRequest("POST", reqPath) 21 | if err := r.SetJSONBody(body); err != nil { 22 | return nil, err 23 | } 24 | 25 | resp, err := c.c.RawRequest(r) 26 | if err != nil { 27 | return nil, err 28 | } 29 | defer resp.Body.Close() 30 | 31 | var result map[string]interface{} 32 | err = resp.DecodeJSON(&result) 33 | if err != nil { 34 | return nil, err 35 | } 36 | 37 | var capabilities []string 38 | capabilitiesRaw := result["capabilities"].([]interface{}) 39 | for _, capability := range capabilitiesRaw { 40 | capabilities = append(capabilities, capability.(string)) 41 | } 42 | return capabilities, nil 43 | } 44 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_config_cors.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) CORSStatus() (*CORSResponse, error) { 4 | r := c.c.NewRequest("GET", "/v1/sys/config/cors") 5 | resp, err := c.c.RawRequest(r) 6 | if err != nil { 7 | return nil, err 8 | } 9 | defer resp.Body.Close() 10 | 11 | var result CORSResponse 12 | err = resp.DecodeJSON(&result) 13 | return &result, err 14 | } 15 | 16 | func (c *Sys) ConfigureCORS(req *CORSRequest) (*CORSResponse, error) { 17 | r := c.c.NewRequest("PUT", "/v1/sys/config/cors") 18 | if err := r.SetJSONBody(req); err != nil { 19 | return nil, err 20 | } 21 | 22 | resp, err := c.c.RawRequest(r) 23 | if err != nil { 24 | return nil, err 25 | } 26 | defer resp.Body.Close() 27 | 28 | var result CORSResponse 29 | err = resp.DecodeJSON(&result) 30 | return &result, err 31 | } 32 | 33 | func (c *Sys) DisableCORS() (*CORSResponse, error) { 34 | r := c.c.NewRequest("DELETE", "/v1/sys/config/cors") 35 | 36 | resp, err := c.c.RawRequest(r) 37 | if err != nil { 38 | return nil, err 39 | } 40 | defer resp.Body.Close() 41 | 42 | var result CORSResponse 43 | err = resp.DecodeJSON(&result) 44 | return &result, err 45 | 46 | } 47 | 48 | type CORSRequest struct { 49 | AllowedOrigins string `json:"allowed_origins"` 50 | Enabled bool `json:"enabled"` 51 | } 52 | 53 | type CORSResponse struct { 54 | AllowedOrigins string `json:"allowed_origins"` 55 | Enabled bool `json:"enabled"` 56 | } 57 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_generate_root.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) GenerateRootStatus() (*GenerateRootStatusResponse, error) { 4 | return c.generateRootStatusCommon("/v1/sys/generate-root/attempt") 5 | } 6 | 7 | func (c *Sys) GenerateDROperationTokenStatus() (*GenerateRootStatusResponse, error) { 8 | return c.generateRootStatusCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt") 9 | } 10 | 11 | func (c *Sys) generateRootStatusCommon(path string) (*GenerateRootStatusResponse, error) { 12 | r := c.c.NewRequest("GET", path) 13 | resp, err := c.c.RawRequest(r) 14 | if err != nil { 15 | return nil, err 16 | } 17 | defer resp.Body.Close() 18 | 19 | var result GenerateRootStatusResponse 20 | err = resp.DecodeJSON(&result) 21 | return &result, err 22 | } 23 | 24 | func (c *Sys) GenerateRootInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) { 25 | return c.generateRootInitCommon("/v1/sys/generate-root/attempt", otp, pgpKey) 26 | } 27 | 28 | func (c *Sys) GenerateDROperationTokenInit(otp, pgpKey string) (*GenerateRootStatusResponse, error) { 29 | return c.generateRootInitCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt", otp, pgpKey) 30 | } 31 | 32 | func (c *Sys) generateRootInitCommon(path, otp, pgpKey string) (*GenerateRootStatusResponse, error) { 33 | body := map[string]interface{}{ 34 | "otp": otp, 35 | "pgp_key": pgpKey, 36 | } 37 | 38 | r := c.c.NewRequest("PUT", path) 39 | if err := r.SetJSONBody(body); err != nil { 40 | return nil, err 41 | } 42 | 43 | resp, err := c.c.RawRequest(r) 44 | if err != nil { 45 | return nil, err 46 | } 47 | defer resp.Body.Close() 48 | 49 | var result GenerateRootStatusResponse 50 | err = resp.DecodeJSON(&result) 51 | return &result, err 52 | } 53 | 54 | func (c *Sys) GenerateRootCancel() error { 55 | return c.generateRootCancelCommon("/v1/sys/generate-root/attempt") 56 | } 57 | 58 | func (c *Sys) GenerateDROperationTokenCancel() error { 59 | return c.generateRootCancelCommon("/v1/sys/replication/dr/secondary/generate-operation-token/attempt") 60 | } 61 | 62 | func (c *Sys) generateRootCancelCommon(path string) error { 63 | r := c.c.NewRequest("DELETE", path) 64 | resp, err := c.c.RawRequest(r) 65 | if err == nil { 66 | defer resp.Body.Close() 67 | } 68 | return err 69 | } 70 | 71 | func (c *Sys) GenerateRootUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) { 72 | return c.generateRootUpdateCommon("/v1/sys/generate-root/update", shard, nonce) 73 | } 74 | 75 | func (c *Sys) GenerateDROperationTokenUpdate(shard, nonce string) (*GenerateRootStatusResponse, error) { 76 | return c.generateRootUpdateCommon("/v1/sys/replication/dr/secondary/generate-operation-token/update", shard, nonce) 77 | } 78 | 79 | func (c *Sys) generateRootUpdateCommon(path, shard, nonce string) (*GenerateRootStatusResponse, error) { 80 | body := map[string]interface{}{ 81 | "key": shard, 82 | "nonce": nonce, 83 | } 84 | 85 | r := c.c.NewRequest("PUT", path) 86 | if err := r.SetJSONBody(body); err != nil { 87 | return nil, err 88 | } 89 | 90 | resp, err := c.c.RawRequest(r) 91 | if err != nil { 92 | return nil, err 93 | } 94 | defer resp.Body.Close() 95 | 96 | var result GenerateRootStatusResponse 97 | err = resp.DecodeJSON(&result) 98 | return &result, err 99 | } 100 | 101 | type GenerateRootStatusResponse struct { 102 | Nonce string 103 | Started bool 104 | Progress int 105 | Required int 106 | Complete bool 107 | EncodedToken string `json:"encoded_token"` 108 | EncodedRootToken string `json:"encoded_root_token"` 109 | PGPFingerprint string `json:"pgp_fingerprint"` 110 | } 111 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_health.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) Health() (*HealthResponse, error) { 4 | r := c.c.NewRequest("GET", "/v1/sys/health") 5 | // If the code is 400 or above it will automatically turn into an error, 6 | // but the sys/health API defaults to returning 5xx when not sealed or 7 | // inited, so we force this code to be something else so we parse correctly 8 | r.Params.Add("uninitcode", "299") 9 | r.Params.Add("sealedcode", "299") 10 | r.Params.Add("standbycode", "299") 11 | r.Params.Add("drsecondarycode", "299") 12 | resp, err := c.c.RawRequest(r) 13 | if err != nil { 14 | return nil, err 15 | } 16 | defer resp.Body.Close() 17 | 18 | var result HealthResponse 19 | err = resp.DecodeJSON(&result) 20 | return &result, err 21 | } 22 | 23 | type HealthResponse struct { 24 | Initialized bool `json:"initialized"` 25 | Sealed bool `json:"sealed"` 26 | Standby bool `json:"standby"` 27 | ReplicationPerformanceMode string `json:"replication_performance_mode"` 28 | ReplicationDRMode string `json:"replication_dr_mode"` 29 | ServerTimeUTC int64 `json:"server_time_utc"` 30 | Version string `json:"version"` 31 | ClusterName string `json:"cluster_name,omitempty"` 32 | ClusterID string `json:"cluster_id,omitempty"` 33 | } 34 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_init.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) InitStatus() (bool, error) { 4 | r := c.c.NewRequest("GET", "/v1/sys/init") 5 | resp, err := c.c.RawRequest(r) 6 | if err != nil { 7 | return false, err 8 | } 9 | defer resp.Body.Close() 10 | 11 | var result InitStatusResponse 12 | err = resp.DecodeJSON(&result) 13 | return result.Initialized, err 14 | } 15 | 16 | func (c *Sys) Init(opts *InitRequest) (*InitResponse, error) { 17 | r := c.c.NewRequest("PUT", "/v1/sys/init") 18 | if err := r.SetJSONBody(opts); err != nil { 19 | return nil, err 20 | } 21 | 22 | resp, err := c.c.RawRequest(r) 23 | if err != nil { 24 | return nil, err 25 | } 26 | defer resp.Body.Close() 27 | 28 | var result InitResponse 29 | err = resp.DecodeJSON(&result) 30 | return &result, err 31 | } 32 | 33 | type InitRequest struct { 34 | SecretShares int `json:"secret_shares"` 35 | SecretThreshold int `json:"secret_threshold"` 36 | StoredShares int `json:"stored_shares"` 37 | PGPKeys []string `json:"pgp_keys"` 38 | RecoveryShares int `json:"recovery_shares"` 39 | RecoveryThreshold int `json:"recovery_threshold"` 40 | RecoveryPGPKeys []string `json:"recovery_pgp_keys"` 41 | RootTokenPGPKey string `json:"root_token_pgp_key"` 42 | } 43 | 44 | type InitStatusResponse struct { 45 | Initialized bool 46 | } 47 | 48 | type InitResponse struct { 49 | Keys []string `json:"keys"` 50 | KeysB64 []string `json:"keys_base64"` 51 | RecoveryKeys []string `json:"recovery_keys"` 52 | RecoveryKeysB64 []string `json:"recovery_keys_base64"` 53 | RootToken string `json:"root_token"` 54 | } 55 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_leader.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) Leader() (*LeaderResponse, error) { 4 | r := c.c.NewRequest("GET", "/v1/sys/leader") 5 | resp, err := c.c.RawRequest(r) 6 | if err != nil { 7 | return nil, err 8 | } 9 | defer resp.Body.Close() 10 | 11 | var result LeaderResponse 12 | err = resp.DecodeJSON(&result) 13 | return &result, err 14 | } 15 | 16 | type LeaderResponse struct { 17 | HAEnabled bool `json:"ha_enabled"` 18 | IsSelf bool `json:"is_self"` 19 | LeaderAddress string `json:"leader_address"` 20 | LeaderClusterAddress string `json:"leader_cluster_address"` 21 | } 22 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_leases.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) Renew(id string, increment int) (*Secret, error) { 4 | r := c.c.NewRequest("PUT", "/v1/sys/leases/renew") 5 | 6 | body := map[string]interface{}{ 7 | "increment": increment, 8 | "lease_id": id, 9 | } 10 | if err := r.SetJSONBody(body); err != nil { 11 | return nil, err 12 | } 13 | 14 | resp, err := c.c.RawRequest(r) 15 | if err != nil { 16 | return nil, err 17 | } 18 | defer resp.Body.Close() 19 | 20 | return ParseSecret(resp.Body) 21 | } 22 | 23 | func (c *Sys) Revoke(id string) error { 24 | r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke/"+id) 25 | resp, err := c.c.RawRequest(r) 26 | if err == nil { 27 | defer resp.Body.Close() 28 | } 29 | return err 30 | } 31 | 32 | func (c *Sys) RevokePrefix(id string) error { 33 | r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke-prefix/"+id) 34 | resp, err := c.c.RawRequest(r) 35 | if err == nil { 36 | defer resp.Body.Close() 37 | } 38 | return err 39 | } 40 | 41 | func (c *Sys) RevokeForce(id string) error { 42 | r := c.c.NewRequest("PUT", "/v1/sys/leases/revoke-force/"+id) 43 | resp, err := c.c.RawRequest(r) 44 | if err == nil { 45 | defer resp.Body.Close() 46 | } 47 | return err 48 | } 49 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_policy.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import "fmt" 4 | 5 | func (c *Sys) ListPolicies() ([]string, error) { 6 | r := c.c.NewRequest("GET", "/v1/sys/policy") 7 | resp, err := c.c.RawRequest(r) 8 | if err != nil { 9 | return nil, err 10 | } 11 | defer resp.Body.Close() 12 | 13 | var result map[string]interface{} 14 | err = resp.DecodeJSON(&result) 15 | if err != nil { 16 | return nil, err 17 | } 18 | 19 | var ok bool 20 | if _, ok = result["policies"]; !ok { 21 | return nil, fmt.Errorf("policies not found in response") 22 | } 23 | 24 | listRaw := result["policies"].([]interface{}) 25 | var policies []string 26 | 27 | for _, val := range listRaw { 28 | policies = append(policies, val.(string)) 29 | } 30 | 31 | return policies, err 32 | } 33 | 34 | func (c *Sys) GetPolicy(name string) (string, error) { 35 | r := c.c.NewRequest("GET", fmt.Sprintf("/v1/sys/policy/%s", name)) 36 | resp, err := c.c.RawRequest(r) 37 | if resp != nil { 38 | defer resp.Body.Close() 39 | if resp.StatusCode == 404 { 40 | return "", nil 41 | } 42 | } 43 | if err != nil { 44 | return "", err 45 | } 46 | 47 | var result map[string]interface{} 48 | err = resp.DecodeJSON(&result) 49 | if err != nil { 50 | return "", err 51 | } 52 | 53 | if rulesRaw, ok := result["rules"]; ok { 54 | return rulesRaw.(string), nil 55 | } 56 | if policyRaw, ok := result["policy"]; ok { 57 | return policyRaw.(string), nil 58 | } 59 | 60 | return "", fmt.Errorf("no policy found in response") 61 | } 62 | 63 | func (c *Sys) PutPolicy(name, rules string) error { 64 | body := map[string]string{ 65 | "rules": rules, 66 | } 67 | 68 | r := c.c.NewRequest("PUT", fmt.Sprintf("/v1/sys/policy/%s", name)) 69 | if err := r.SetJSONBody(body); err != nil { 70 | return err 71 | } 72 | 73 | resp, err := c.c.RawRequest(r) 74 | if err != nil { 75 | return err 76 | } 77 | defer resp.Body.Close() 78 | 79 | return nil 80 | } 81 | 82 | func (c *Sys) DeletePolicy(name string) error { 83 | r := c.c.NewRequest("DELETE", fmt.Sprintf("/v1/sys/policy/%s", name)) 84 | resp, err := c.c.RawRequest(r) 85 | if err == nil { 86 | defer resp.Body.Close() 87 | } 88 | return err 89 | } 90 | 91 | type getPoliciesResp struct { 92 | Rules string `json:"rules"` 93 | } 94 | 95 | type listPoliciesResp struct { 96 | Policies []string `json:"policies"` 97 | } 98 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_rotate.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | import "time" 4 | 5 | func (c *Sys) Rotate() error { 6 | r := c.c.NewRequest("POST", "/v1/sys/rotate") 7 | resp, err := c.c.RawRequest(r) 8 | if err == nil { 9 | defer resp.Body.Close() 10 | } 11 | return err 12 | } 13 | 14 | func (c *Sys) KeyStatus() (*KeyStatus, error) { 15 | r := c.c.NewRequest("GET", "/v1/sys/key-status") 16 | resp, err := c.c.RawRequest(r) 17 | if err != nil { 18 | return nil, err 19 | } 20 | defer resp.Body.Close() 21 | 22 | result := new(KeyStatus) 23 | err = resp.DecodeJSON(result) 24 | return result, err 25 | } 26 | 27 | type KeyStatus struct { 28 | Term int `json:"term"` 29 | InstallTime time.Time `json:"install_time"` 30 | } 31 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_seal.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) SealStatus() (*SealStatusResponse, error) { 4 | r := c.c.NewRequest("GET", "/v1/sys/seal-status") 5 | return sealStatusRequest(c, r) 6 | } 7 | 8 | func (c *Sys) Seal() error { 9 | r := c.c.NewRequest("PUT", "/v1/sys/seal") 10 | resp, err := c.c.RawRequest(r) 11 | if err == nil { 12 | defer resp.Body.Close() 13 | } 14 | return err 15 | } 16 | 17 | func (c *Sys) ResetUnsealProcess() (*SealStatusResponse, error) { 18 | body := map[string]interface{}{"reset": true} 19 | 20 | r := c.c.NewRequest("PUT", "/v1/sys/unseal") 21 | if err := r.SetJSONBody(body); err != nil { 22 | return nil, err 23 | } 24 | 25 | return sealStatusRequest(c, r) 26 | } 27 | 28 | func (c *Sys) Unseal(shard string) (*SealStatusResponse, error) { 29 | body := map[string]interface{}{"key": shard} 30 | 31 | r := c.c.NewRequest("PUT", "/v1/sys/unseal") 32 | if err := r.SetJSONBody(body); err != nil { 33 | return nil, err 34 | } 35 | 36 | return sealStatusRequest(c, r) 37 | } 38 | 39 | func sealStatusRequest(c *Sys, r *Request) (*SealStatusResponse, error) { 40 | resp, err := c.c.RawRequest(r) 41 | if err != nil { 42 | return nil, err 43 | } 44 | defer resp.Body.Close() 45 | 46 | var result SealStatusResponse 47 | err = resp.DecodeJSON(&result) 48 | return &result, err 49 | } 50 | 51 | type SealStatusResponse struct { 52 | Type string `json:"type"` 53 | Sealed bool `json:"sealed"` 54 | T int `json:"t"` 55 | N int `json:"n"` 56 | Progress int `json:"progress"` 57 | Nonce string `json:"nonce"` 58 | Version string `json:"version"` 59 | ClusterName string `json:"cluster_name,omitempty"` 60 | ClusterID string `json:"cluster_id,omitempty"` 61 | RecoverySeal bool `json:"recovery_seal"` 62 | } 63 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/api/sys_stepdown.go: -------------------------------------------------------------------------------- 1 | package api 2 | 3 | func (c *Sys) StepDown() error { 4 | r := c.c.NewRequest("PUT", "/v1/sys/step-down") 5 | resp, err := c.c.RawRequest(r) 6 | if err == nil { 7 | defer resp.Body.Close() 8 | } 9 | return err 10 | } 11 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/helper/jsonutil/json.go: -------------------------------------------------------------------------------- 1 | package jsonutil 2 | 3 | import ( 4 | "bytes" 5 | "compress/gzip" 6 | "encoding/json" 7 | "fmt" 8 | "io" 9 | 10 | "github.com/hashicorp/vault/helper/compressutil" 11 | ) 12 | 13 | // Encodes/Marshals the given object into JSON 14 | func EncodeJSON(in interface{}) ([]byte, error) { 15 | if in == nil { 16 | return nil, fmt.Errorf("input for encoding is nil") 17 | } 18 | var buf bytes.Buffer 19 | enc := json.NewEncoder(&buf) 20 | if err := enc.Encode(in); err != nil { 21 | return nil, err 22 | } 23 | return buf.Bytes(), nil 24 | } 25 | 26 | // EncodeJSONAndCompress encodes the given input into JSON and compresses the 27 | // encoded value (using Gzip format BestCompression level, by default). A 28 | // canary byte is placed at the beginning of the returned bytes for the logic 29 | // in decompression method to identify compressed input. 30 | func EncodeJSONAndCompress(in interface{}, config *compressutil.CompressionConfig) ([]byte, error) { 31 | if in == nil { 32 | return nil, fmt.Errorf("input for encoding is nil") 33 | } 34 | 35 | // First JSON encode the given input 36 | encodedBytes, err := EncodeJSON(in) 37 | if err != nil { 38 | return nil, err 39 | } 40 | 41 | if config == nil { 42 | config = &compressutil.CompressionConfig{ 43 | Type: compressutil.CompressionTypeGzip, 44 | GzipCompressionLevel: gzip.BestCompression, 45 | } 46 | } 47 | 48 | return compressutil.Compress(encodedBytes, config) 49 | } 50 | 51 | // DecodeJSON tries to decompress the given data. The call to decompress, fails 52 | // if the content was not compressed in the first place, which is identified by 53 | // a canary byte before the compressed data. If the data is not compressed, it 54 | // is JSON decoded directly. Otherwise the decompressed data will be JSON 55 | // decoded. 56 | func DecodeJSON(data []byte, out interface{}) error { 57 | if data == nil || len(data) == 0 { 58 | return fmt.Errorf("'data' being decoded is nil") 59 | } 60 | if out == nil { 61 | return fmt.Errorf("output parameter 'out' is nil") 62 | } 63 | 64 | // Decompress the data if it was compressed in the first place 65 | decompressedBytes, uncompressed, err := compressutil.Decompress(data) 66 | if err != nil { 67 | return fmt.Errorf("failed to decompress JSON: err: %v", err) 68 | } 69 | if !uncompressed && (decompressedBytes == nil || len(decompressedBytes) == 0) { 70 | return fmt.Errorf("decompressed data being decoded is invalid") 71 | } 72 | 73 | // If the input supplied failed to contain the compression canary, it 74 | // will be notified by the compression utility. Decode the decompressed 75 | // input. 76 | if !uncompressed { 77 | data = decompressedBytes 78 | } 79 | 80 | return DecodeJSONFromReader(bytes.NewReader(data), out) 81 | } 82 | 83 | // Decodes/Unmarshals the given io.Reader pointing to a JSON, into a desired object 84 | func DecodeJSONFromReader(r io.Reader, out interface{}) error { 85 | if r == nil { 86 | return fmt.Errorf("'io.Reader' being decoded is nil") 87 | } 88 | if out == nil { 89 | return fmt.Errorf("output parameter 'out' is nil") 90 | } 91 | 92 | dec := json.NewDecoder(r) 93 | 94 | // While decoding JSON values, intepret the integer values as `json.Number`s instead of `float64`. 95 | dec.UseNumber() 96 | 97 | // Since 'out' is an interface representing a pointer, pass it to the decoder without an '&' 98 | return dec.Decode(out) 99 | } 100 | -------------------------------------------------------------------------------- /vendor/github.com/hashicorp/vault/helper/parseutil/parseutil.go: -------------------------------------------------------------------------------- 1 | package parseutil 2 | 3 | import ( 4 | "encoding/json" 5 | "errors" 6 | "strconv" 7 | "strings" 8 | "time" 9 | 10 | "github.com/mitchellh/mapstructure" 11 | ) 12 | 13 | func ParseDurationSecond(in interface{}) (time.Duration, error) { 14 | var dur time.Duration 15 | jsonIn, ok := in.(json.Number) 16 | if ok { 17 | in = jsonIn.String() 18 | } 19 | switch in.(type) { 20 | case string: 21 | inp := in.(string) 22 | if inp == "" { 23 | return time.Duration(0), nil 24 | } 25 | var err error 26 | // Look for a suffix otherwise its a plain second value 27 | if strings.HasSuffix(inp, "s") || strings.HasSuffix(inp, "m") || strings.HasSuffix(inp, "h") { 28 | dur, err = time.ParseDuration(inp) 29 | if err != nil { 30 | return dur, err 31 | } 32 | } else { 33 | // Plain integer 34 | secs, err := strconv.ParseInt(inp, 10, 64) 35 | if err != nil { 36 | return dur, err 37 | } 38 | dur = time.Duration(secs) * time.Second 39 | } 40 | case int: 41 | dur = time.Duration(in.(int)) * time.Second 42 | case int32: 43 | dur = time.Duration(in.(int32)) * time.Second 44 | case int64: 45 | dur = time.Duration(in.(int64)) * time.Second 46 | case uint: 47 | dur = time.Duration(in.(uint)) * time.Second 48 | case uint32: 49 | dur = time.Duration(in.(uint32)) * time.Second 50 | case uint64: 51 | dur = time.Duration(in.(uint64)) * time.Second 52 | default: 53 | return 0, errors.New("could not parse duration from input") 54 | } 55 | 56 | return dur, nil 57 | } 58 | 59 | func ParseInt(in interface{}) (int64, error) { 60 | var ret int64 61 | jsonIn, ok := in.(json.Number) 62 | if ok { 63 | in = jsonIn.String() 64 | } 65 | switch in.(type) { 66 | case string: 67 | inp := in.(string) 68 | if inp == "" { 69 | return 0, nil 70 | } 71 | var err error 72 | left, err := strconv.ParseInt(inp, 10, 64) 73 | if err != nil { 74 | return ret, err 75 | } 76 | ret = left 77 | case int: 78 | ret = int64(in.(int)) 79 | case int32: 80 | ret = int64(in.(int32)) 81 | case int64: 82 | ret = in.(int64) 83 | case uint: 84 | ret = int64(in.(uint)) 85 | case uint32: 86 | ret = int64(in.(uint32)) 87 | case uint64: 88 | ret = int64(in.(uint64)) 89 | default: 90 | return 0, errors.New("could not parse value from input") 91 | } 92 | 93 | return ret, nil 94 | } 95 | 96 | func ParseBool(in interface{}) (bool, error) { 97 | var result bool 98 | if err := mapstructure.WeakDecode(in, &result); err != nil { 99 | return false, err 100 | } 101 | return result, nil 102 | } 103 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/README.md: -------------------------------------------------------------------------------- 1 | # go-homedir 2 | 3 | This is a Go library for detecting the user's home directory without 4 | the use of cgo, so the library can be used in cross-compilation environments. 5 | 6 | Usage is incredibly simple, just call `homedir.Dir()` to get the home directory 7 | for a user, and `homedir.Expand()` to expand the `~` in a path to the home 8 | directory. 9 | 10 | **Why not just use `os/user`?** The built-in `os/user` package requires 11 | cgo on Darwin systems. This means that any Go code that uses that package 12 | cannot cross compile. But 99% of the time the use for `os/user` is just to 13 | retrieve the home directory, which we can do for the current user without 14 | cgo. This library does that, enabling cross-compilation. 15 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/go-homedir/homedir.go: -------------------------------------------------------------------------------- 1 | package homedir 2 | 3 | import ( 4 | "bytes" 5 | "errors" 6 | "os" 7 | "os/exec" 8 | "path/filepath" 9 | "runtime" 10 | "strconv" 11 | "strings" 12 | "sync" 13 | ) 14 | 15 | // DisableCache will disable caching of the home directory. Caching is enabled 16 | // by default. 17 | var DisableCache bool 18 | 19 | var homedirCache string 20 | var cacheLock sync.RWMutex 21 | 22 | // Dir returns the home directory for the executing user. 23 | // 24 | // This uses an OS-specific method for discovering the home directory. 25 | // An error is returned if a home directory cannot be detected. 26 | func Dir() (string, error) { 27 | if !DisableCache { 28 | cacheLock.RLock() 29 | cached := homedirCache 30 | cacheLock.RUnlock() 31 | if cached != "" { 32 | return cached, nil 33 | } 34 | } 35 | 36 | cacheLock.Lock() 37 | defer cacheLock.Unlock() 38 | 39 | var result string 40 | var err error 41 | if runtime.GOOS == "windows" { 42 | result, err = dirWindows() 43 | } else { 44 | // Unix-like system, so just assume Unix 45 | result, err = dirUnix() 46 | } 47 | 48 | if err != nil { 49 | return "", err 50 | } 51 | homedirCache = result 52 | return result, nil 53 | } 54 | 55 | // Expand expands the path to include the home directory if the path 56 | // is prefixed with `~`. If it isn't prefixed with `~`, the path is 57 | // returned as-is. 58 | func Expand(path string) (string, error) { 59 | if len(path) == 0 { 60 | return path, nil 61 | } 62 | 63 | if path[0] != '~' { 64 | return path, nil 65 | } 66 | 67 | if len(path) > 1 && path[1] != '/' && path[1] != '\\' { 68 | return "", errors.New("cannot expand user-specific home dir") 69 | } 70 | 71 | dir, err := Dir() 72 | if err != nil { 73 | return "", err 74 | } 75 | 76 | return filepath.Join(dir, path[1:]), nil 77 | } 78 | 79 | func dirUnix() (string, error) { 80 | // First prefer the HOME environmental variable 81 | if home := os.Getenv("HOME"); home != "" { 82 | return home, nil 83 | } 84 | 85 | // If that fails, try getent 86 | var stdout bytes.Buffer 87 | cmd := exec.Command("getent", "passwd", strconv.Itoa(os.Getuid())) 88 | cmd.Stdout = &stdout 89 | if err := cmd.Run(); err != nil { 90 | // If the error is ErrNotFound, we ignore it. Otherwise, return it. 91 | if err != exec.ErrNotFound { 92 | return "", err 93 | } 94 | } else { 95 | if passwd := strings.TrimSpace(stdout.String()); passwd != "" { 96 | // username:password:uid:gid:gecos:home:shell 97 | passwdParts := strings.SplitN(passwd, ":", 7) 98 | if len(passwdParts) > 5 { 99 | return passwdParts[5], nil 100 | } 101 | } 102 | } 103 | 104 | // If all else fails, try the shell 105 | stdout.Reset() 106 | cmd = exec.Command("sh", "-c", "cd && pwd") 107 | cmd.Stdout = &stdout 108 | if err := cmd.Run(); err != nil { 109 | return "", err 110 | } 111 | 112 | result := strings.TrimSpace(stdout.String()) 113 | if result == "" { 114 | return "", errors.New("blank output when reading home directory") 115 | } 116 | 117 | return result, nil 118 | } 119 | 120 | func dirWindows() (string, error) { 121 | // First prefer the HOME environmental variable 122 | if home := os.Getenv("HOME"); home != "" { 123 | return home, nil 124 | } 125 | 126 | drive := os.Getenv("HOMEDRIVE") 127 | path := os.Getenv("HOMEPATH") 128 | home := drive + path 129 | if drive == "" || path == "" { 130 | home = os.Getenv("USERPROFILE") 131 | } 132 | if home == "" { 133 | return "", errors.New("HOMEDRIVE, HOMEPATH, and USERPROFILE are blank") 134 | } 135 | 136 | return home, nil 137 | } 138 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.9.x 5 | - tip 6 | 7 | script: 8 | - go test 9 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013 Mitchell Hashimoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/README.md: -------------------------------------------------------------------------------- 1 | # mapstructure [![Godoc](https://godoc.org/github.com/mitchell/mapstructure?status.svg)](https://godoc.org/github.com/mitchell/mapstructure) 2 | 3 | mapstructure is a Go library for decoding generic map values to structures 4 | and vice versa, while providing helpful error handling. 5 | 6 | This library is most useful when decoding values from some data stream (JSON, 7 | Gob, etc.) where you don't _quite_ know the structure of the underlying data 8 | until you read a part of it. You can therefore read a `map[string]interface{}` 9 | and use this library to decode it into the proper underlying native Go 10 | structure. 11 | 12 | ## Installation 13 | 14 | Standard `go get`: 15 | 16 | ``` 17 | $ go get github.com/mitchellh/mapstructure 18 | ``` 19 | 20 | ## Usage & Example 21 | 22 | For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/mapstructure). 23 | 24 | The `Decode` function has examples associated with it there. 25 | 26 | ## But Why?! 27 | 28 | Go offers fantastic standard libraries for decoding formats such as JSON. 29 | The standard method is to have a struct pre-created, and populate that struct 30 | from the bytes of the encoded format. This is great, but the problem is if 31 | you have configuration or an encoding that changes slightly depending on 32 | specific fields. For example, consider this JSON: 33 | 34 | ```json 35 | { 36 | "type": "person", 37 | "name": "Mitchell" 38 | } 39 | ``` 40 | 41 | Perhaps we can't populate a specific structure without first reading 42 | the "type" field from the JSON. We could always do two passes over the 43 | decoding of the JSON (reading the "type" first, and the rest later). 44 | However, it is much simpler to just decode this into a `map[string]interface{}` 45 | structure, read the "type" key, then use something like this library 46 | to decode it into the proper structure. 47 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/decode_hooks.go: -------------------------------------------------------------------------------- 1 | package mapstructure 2 | 3 | import ( 4 | "errors" 5 | "reflect" 6 | "strconv" 7 | "strings" 8 | "time" 9 | ) 10 | 11 | // typedDecodeHook takes a raw DecodeHookFunc (an interface{}) and turns 12 | // it into the proper DecodeHookFunc type, such as DecodeHookFuncType. 13 | func typedDecodeHook(h DecodeHookFunc) DecodeHookFunc { 14 | // Create variables here so we can reference them with the reflect pkg 15 | var f1 DecodeHookFuncType 16 | var f2 DecodeHookFuncKind 17 | 18 | // Fill in the variables into this interface and the rest is done 19 | // automatically using the reflect package. 20 | potential := []interface{}{f1, f2} 21 | 22 | v := reflect.ValueOf(h) 23 | vt := v.Type() 24 | for _, raw := range potential { 25 | pt := reflect.ValueOf(raw).Type() 26 | if vt.ConvertibleTo(pt) { 27 | return v.Convert(pt).Interface() 28 | } 29 | } 30 | 31 | return nil 32 | } 33 | 34 | // DecodeHookExec executes the given decode hook. This should be used 35 | // since it'll naturally degrade to the older backwards compatible DecodeHookFunc 36 | // that took reflect.Kind instead of reflect.Type. 37 | func DecodeHookExec( 38 | raw DecodeHookFunc, 39 | from reflect.Type, to reflect.Type, 40 | data interface{}) (interface{}, error) { 41 | switch f := typedDecodeHook(raw).(type) { 42 | case DecodeHookFuncType: 43 | return f(from, to, data) 44 | case DecodeHookFuncKind: 45 | return f(from.Kind(), to.Kind(), data) 46 | default: 47 | return nil, errors.New("invalid decode hook signature") 48 | } 49 | } 50 | 51 | // ComposeDecodeHookFunc creates a single DecodeHookFunc that 52 | // automatically composes multiple DecodeHookFuncs. 53 | // 54 | // The composed funcs are called in order, with the result of the 55 | // previous transformation. 56 | func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc { 57 | return func( 58 | f reflect.Type, 59 | t reflect.Type, 60 | data interface{}) (interface{}, error) { 61 | var err error 62 | for _, f1 := range fs { 63 | data, err = DecodeHookExec(f1, f, t, data) 64 | if err != nil { 65 | return nil, err 66 | } 67 | 68 | // Modify the from kind to be correct with the new data 69 | f = nil 70 | if val := reflect.ValueOf(data); val.IsValid() { 71 | f = val.Type() 72 | } 73 | } 74 | 75 | return data, nil 76 | } 77 | } 78 | 79 | // StringToSliceHookFunc returns a DecodeHookFunc that converts 80 | // string to []string by splitting on the given sep. 81 | func StringToSliceHookFunc(sep string) DecodeHookFunc { 82 | return func( 83 | f reflect.Kind, 84 | t reflect.Kind, 85 | data interface{}) (interface{}, error) { 86 | if f != reflect.String || t != reflect.Slice { 87 | return data, nil 88 | } 89 | 90 | raw := data.(string) 91 | if raw == "" { 92 | return []string{}, nil 93 | } 94 | 95 | return strings.Split(raw, sep), nil 96 | } 97 | } 98 | 99 | // StringToTimeDurationHookFunc returns a DecodeHookFunc that converts 100 | // strings to time.Duration. 101 | func StringToTimeDurationHookFunc() DecodeHookFunc { 102 | return func( 103 | f reflect.Type, 104 | t reflect.Type, 105 | data interface{}) (interface{}, error) { 106 | if f.Kind() != reflect.String { 107 | return data, nil 108 | } 109 | if t != reflect.TypeOf(time.Duration(5)) { 110 | return data, nil 111 | } 112 | 113 | // Convert it by parsing 114 | return time.ParseDuration(data.(string)) 115 | } 116 | } 117 | 118 | // WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to 119 | // the decoder. 120 | // 121 | // Note that this is significantly different from the WeaklyTypedInput option 122 | // of the DecoderConfig. 123 | func WeaklyTypedHook( 124 | f reflect.Kind, 125 | t reflect.Kind, 126 | data interface{}) (interface{}, error) { 127 | dataVal := reflect.ValueOf(data) 128 | switch t { 129 | case reflect.String: 130 | switch f { 131 | case reflect.Bool: 132 | if dataVal.Bool() { 133 | return "1", nil 134 | } 135 | return "0", nil 136 | case reflect.Float32: 137 | return strconv.FormatFloat(dataVal.Float(), 'f', -1, 64), nil 138 | case reflect.Int: 139 | return strconv.FormatInt(dataVal.Int(), 10), nil 140 | case reflect.Slice: 141 | dataType := dataVal.Type() 142 | elemKind := dataType.Elem().Kind() 143 | if elemKind == reflect.Uint8 { 144 | return string(dataVal.Interface().([]uint8)), nil 145 | } 146 | case reflect.Uint: 147 | return strconv.FormatUint(dataVal.Uint(), 10), nil 148 | } 149 | } 150 | 151 | return data, nil 152 | } 153 | -------------------------------------------------------------------------------- /vendor/github.com/mitchellh/mapstructure/error.go: -------------------------------------------------------------------------------- 1 | package mapstructure 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | "sort" 7 | "strings" 8 | ) 9 | 10 | // Error implements the error interface and can represents multiple 11 | // errors that occur in the course of a single decode. 12 | type Error struct { 13 | Errors []string 14 | } 15 | 16 | func (e *Error) Error() string { 17 | points := make([]string, len(e.Errors)) 18 | for i, err := range e.Errors { 19 | points[i] = fmt.Sprintf("* %s", err) 20 | } 21 | 22 | sort.Strings(points) 23 | return fmt.Sprintf( 24 | "%d error(s) decoding:\n\n%s", 25 | len(e.Errors), strings.Join(points, "\n")) 26 | } 27 | 28 | // WrappedErrors implements the errwrap.Wrapper interface to make this 29 | // return value more useful with the errwrap and go-multierror libraries. 30 | func (e *Error) WrappedErrors() []error { 31 | if e == nil { 32 | return nil 33 | } 34 | 35 | result := make([]error, len(e.Errors)) 36 | for i, e := range e.Errors { 37 | result[i] = errors.New(e) 38 | } 39 | 40 | return result 41 | } 42 | 43 | func appendErrors(errors []string, err error) []string { 44 | switch e := err.(type) { 45 | case *Error: 46 | return append(errors, e.Errors...) 47 | default: 48 | return append(errors, e.Error()) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /vendor/github.com/sethgrid/pester/LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) SendGrid 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http/httpguts/guts.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package httpguts provides functions implementing various details 6 | // of the HTTP specification. 7 | // 8 | // This package is shared by the standard library (which vendors it) 9 | // and x/net/http2. It comes with no API stability promise. 10 | package httpguts 11 | 12 | import ( 13 | "net/textproto" 14 | "strings" 15 | ) 16 | 17 | // ValidTrailerHeader reports whether name is a valid header field name to appear 18 | // in trailers. 19 | // See RFC 7230, Section 4.1.2 20 | func ValidTrailerHeader(name string) bool { 21 | name = textproto.CanonicalMIMEHeaderKey(name) 22 | if strings.HasPrefix(name, "If-") || badTrailer[name] { 23 | return false 24 | } 25 | return true 26 | } 27 | 28 | var badTrailer = map[string]bool{ 29 | "Authorization": true, 30 | "Cache-Control": true, 31 | "Connection": true, 32 | "Content-Encoding": true, 33 | "Content-Length": true, 34 | "Content-Range": true, 35 | "Content-Type": true, 36 | "Expect": true, 37 | "Host": true, 38 | "Keep-Alive": true, 39 | "Max-Forwards": true, 40 | "Pragma": true, 41 | "Proxy-Authenticate": true, 42 | "Proxy-Authorization": true, 43 | "Proxy-Connection": true, 44 | "Range": true, 45 | "Realm": true, 46 | "Te": true, 47 | "Trailer": true, 48 | "Transfer-Encoding": true, 49 | "Www-Authenticate": true, 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | h2i/h2i 3 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # This Dockerfile builds a recent curl with HTTP/2 client support, using 3 | # a recent nghttp2 build. 4 | # 5 | # See the Makefile for how to tag it. If Docker and that image is found, the 6 | # Go tests use this curl binary for integration tests. 7 | # 8 | 9 | FROM ubuntu:trusty 10 | 11 | RUN apt-get update && \ 12 | apt-get upgrade -y && \ 13 | apt-get install -y git-core build-essential wget 14 | 15 | RUN apt-get install -y --no-install-recommends \ 16 | autotools-dev libtool pkg-config zlib1g-dev \ 17 | libcunit1-dev libssl-dev libxml2-dev libevent-dev \ 18 | automake autoconf 19 | 20 | # The list of packages nghttp2 recommends for h2load: 21 | RUN apt-get install -y --no-install-recommends make binutils \ 22 | autoconf automake autotools-dev \ 23 | libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \ 24 | libev-dev libevent-dev libjansson-dev libjemalloc-dev \ 25 | cython python3.4-dev python-setuptools 26 | 27 | # Note: setting NGHTTP2_VER before the git clone, so an old git clone isn't cached: 28 | ENV NGHTTP2_VER 895da9a 29 | RUN cd /root && git clone https://github.com/tatsuhiro-t/nghttp2.git 30 | 31 | WORKDIR /root/nghttp2 32 | RUN git reset --hard $NGHTTP2_VER 33 | RUN autoreconf -i 34 | RUN automake 35 | RUN autoconf 36 | RUN ./configure 37 | RUN make 38 | RUN make install 39 | 40 | WORKDIR /root 41 | RUN wget http://curl.haxx.se/download/curl-7.45.0.tar.gz 42 | RUN tar -zxvf curl-7.45.0.tar.gz 43 | WORKDIR /root/curl-7.45.0 44 | RUN ./configure --with-ssl --with-nghttp2=/usr/local 45 | RUN make 46 | RUN make install 47 | RUN ldconfig 48 | 49 | CMD ["-h"] 50 | ENTRYPOINT ["/usr/local/bin/curl"] 51 | 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Makefile: -------------------------------------------------------------------------------- 1 | curlimage: 2 | docker build -t gohttp2/curl . 3 | 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/README: -------------------------------------------------------------------------------- 1 | This is a work-in-progress HTTP/2 implementation for Go. 2 | 3 | It will eventually live in the Go standard library and won't require 4 | any changes to your code to use. It will just be automatic. 5 | 6 | Status: 7 | 8 | * The server support is pretty good. A few things are missing 9 | but are being worked on. 10 | * The client work has just started but shares a lot of code 11 | is coming along much quicker. 12 | 13 | Docs are at https://godoc.org/golang.org/x/net/http2 14 | 15 | Demo test server at https://http2.golang.org/ 16 | 17 | Help & bug reports welcome! 18 | 19 | Contributing: https://golang.org/doc/contribute.html 20 | Bugs: https://golang.org/issue/new?title=x/net/http2:+ 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/configure_transport.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "fmt" 12 | "net/http" 13 | ) 14 | 15 | func configureTransport(t1 *http.Transport) (*Transport, error) { 16 | connPool := new(clientConnPool) 17 | t2 := &Transport{ 18 | ConnPool: noDialClientConnPool{connPool}, 19 | t1: t1, 20 | } 21 | connPool.t = t2 22 | if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil { 23 | return nil, err 24 | } 25 | if t1.TLSClientConfig == nil { 26 | t1.TLSClientConfig = new(tls.Config) 27 | } 28 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "h2") { 29 | t1.TLSClientConfig.NextProtos = append([]string{"h2"}, t1.TLSClientConfig.NextProtos...) 30 | } 31 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "http/1.1") { 32 | t1.TLSClientConfig.NextProtos = append(t1.TLSClientConfig.NextProtos, "http/1.1") 33 | } 34 | upgradeFn := func(authority string, c *tls.Conn) http.RoundTripper { 35 | addr := authorityAddr("https", authority) 36 | if used, err := connPool.addConnIfNeeded(addr, t2, c); err != nil { 37 | go c.Close() 38 | return erringRoundTripper{err} 39 | } else if !used { 40 | // Turns out we don't need this c. 41 | // For example, two goroutines made requests to the same host 42 | // at the same time, both kicking off TCP dials. (since protocol 43 | // was unknown) 44 | go c.Close() 45 | } 46 | return t2 47 | } 48 | if m := t1.TLSNextProto; len(m) == 0 { 49 | t1.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{ 50 | "h2": upgradeFn, 51 | } 52 | } else { 53 | m["h2"] = upgradeFn 54 | } 55 | return t2, nil 56 | } 57 | 58 | // registerHTTPSProtocol calls Transport.RegisterProtocol but 59 | // converting panics into errors. 60 | func registerHTTPSProtocol(t *http.Transport, rt noDialH2RoundTripper) (err error) { 61 | defer func() { 62 | if e := recover(); e != nil { 63 | err = fmt.Errorf("%v", e) 64 | } 65 | }() 66 | t.RegisterProtocol("https", rt) 67 | return nil 68 | } 69 | 70 | // noDialH2RoundTripper is a RoundTripper which only tries to complete the request 71 | // if there's already has a cached connection to the host. 72 | // (The field is exported so it can be accessed via reflect from net/http; tested 73 | // by TestNoDialH2RoundTripperType) 74 | type noDialH2RoundTripper struct{ *Transport } 75 | 76 | func (rt noDialH2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { 77 | res, err := rt.Transport.RoundTrip(req) 78 | if isNoCachedConnError(err) { 79 | return nil, http.ErrSkipAltProtocol 80 | } 81 | return res, err 82 | } 83 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/flow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Flow control 6 | 7 | package http2 8 | 9 | // flow is the flow control window's size. 10 | type flow struct { 11 | // n is the number of DATA bytes we're allowed to send. 12 | // A flow is kept both on a conn and a per-stream. 13 | n int32 14 | 15 | // conn points to the shared connection-level flow that is 16 | // shared by all streams on that conn. It is nil for the flow 17 | // that's on the conn directly. 18 | conn *flow 19 | } 20 | 21 | func (f *flow) setConnFlow(cf *flow) { f.conn = cf } 22 | 23 | func (f *flow) available() int32 { 24 | n := f.n 25 | if f.conn != nil && f.conn.n < n { 26 | n = f.conn.n 27 | } 28 | return n 29 | } 30 | 31 | func (f *flow) take(n int32) { 32 | if n > f.available() { 33 | panic("internal error: took too much") 34 | } 35 | f.n -= n 36 | if f.conn != nil { 37 | f.conn.n -= n 38 | } 39 | } 40 | 41 | // add adds n bytes (positive or negative) to the flow control window. 42 | // It returns false if the sum would exceed 2^31-1. 43 | func (f *flow) add(n int32) bool { 44 | sum := f.n + n 45 | if (sum > n) == (f.n > 0) { 46 | f.n = sum 47 | return true 48 | } 49 | return false 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go111.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.11 6 | 7 | package http2 8 | 9 | import "net/textproto" 10 | 11 | func traceHasWroteHeaderField(trace *clientTrace) bool { 12 | return trace != nil && trace.WroteHeaderField != nil 13 | } 14 | 15 | func traceWroteHeaderField(trace *clientTrace, k, v string) { 16 | if trace != nil && trace.WroteHeaderField != nil { 17 | trace.WroteHeaderField(k, []string{v}) 18 | } 19 | } 20 | 21 | func traceGot1xxResponseFunc(trace *clientTrace) func(int, textproto.MIMEHeader) error { 22 | if trace != nil { 23 | return trace.Got1xxResponse 24 | } 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 15 | return t1.ExpectContinueTimeout 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "context" 11 | "net" 12 | "net/http" 13 | "net/http/httptrace" 14 | "time" 15 | ) 16 | 17 | type contextContext interface { 18 | context.Context 19 | } 20 | 21 | var errCanceled = context.Canceled 22 | 23 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 24 | ctx, cancel = context.WithCancel(context.Background()) 25 | ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr()) 26 | if hs := opts.baseConfig(); hs != nil { 27 | ctx = context.WithValue(ctx, http.ServerContextKey, hs) 28 | } 29 | return 30 | } 31 | 32 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 33 | return context.WithCancel(ctx) 34 | } 35 | 36 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 37 | return req.WithContext(ctx) 38 | } 39 | 40 | type clientTrace httptrace.ClientTrace 41 | 42 | func reqContext(r *http.Request) context.Context { return r.Context() } 43 | 44 | func (t *Transport) idleConnTimeout() time.Duration { 45 | if t.t1 != nil { 46 | return t.t1.IdleConnTimeout 47 | } 48 | return 0 49 | } 50 | 51 | func setResponseUncompressed(res *http.Response) { res.Uncompressed = true } 52 | 53 | func traceGetConn(req *http.Request, hostPort string) { 54 | trace := httptrace.ContextClientTrace(req.Context()) 55 | if trace == nil || trace.GetConn == nil { 56 | return 57 | } 58 | trace.GetConn(hostPort) 59 | } 60 | 61 | func traceGotConn(req *http.Request, cc *ClientConn) { 62 | trace := httptrace.ContextClientTrace(req.Context()) 63 | if trace == nil || trace.GotConn == nil { 64 | return 65 | } 66 | ci := httptrace.GotConnInfo{Conn: cc.tconn} 67 | cc.mu.Lock() 68 | ci.Reused = cc.nextStreamID > 1 69 | ci.WasIdle = len(cc.streams) == 0 && ci.Reused 70 | if ci.WasIdle && !cc.lastActive.IsZero() { 71 | ci.IdleTime = time.Now().Sub(cc.lastActive) 72 | } 73 | cc.mu.Unlock() 74 | 75 | trace.GotConn(ci) 76 | } 77 | 78 | func traceWroteHeaders(trace *clientTrace) { 79 | if trace != nil && trace.WroteHeaders != nil { 80 | trace.WroteHeaders() 81 | } 82 | } 83 | 84 | func traceGot100Continue(trace *clientTrace) { 85 | if trace != nil && trace.Got100Continue != nil { 86 | trace.Got100Continue() 87 | } 88 | } 89 | 90 | func traceWait100Continue(trace *clientTrace) { 91 | if trace != nil && trace.Wait100Continue != nil { 92 | trace.Wait100Continue() 93 | } 94 | } 95 | 96 | func traceWroteRequest(trace *clientTrace, err error) { 97 | if trace != nil && trace.WroteRequest != nil { 98 | trace.WroteRequest(httptrace.WroteRequestInfo{Err: err}) 99 | } 100 | } 101 | 102 | func traceFirstResponseByte(trace *clientTrace) { 103 | if trace != nil && trace.GotFirstResponseByte != nil { 104 | trace.GotFirstResponseByte() 105 | } 106 | } 107 | 108 | func requestTrace(req *http.Request) *clientTrace { 109 | trace := httptrace.ContextClientTrace(req.Context()) 110 | return (*clientTrace)(trace) 111 | } 112 | 113 | // Ping sends a PING frame to the server and waits for the ack. 114 | func (cc *ClientConn) Ping(ctx context.Context) error { 115 | return cc.ping(ctx) 116 | } 117 | 118 | // Shutdown gracefully closes the client connection, waiting for running streams to complete. 119 | func (cc *ClientConn) Shutdown(ctx context.Context) error { 120 | return cc.shutdown(ctx) 121 | } 122 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17_not18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7,!go1.8 6 | 7 | package http2 8 | 9 | import "crypto/tls" 10 | 11 | // temporary copy of Go 1.7's private tls.Config.clone: 12 | func cloneTLSConfig(c *tls.Config) *tls.Config { 13 | return &tls.Config{ 14 | Rand: c.Rand, 15 | Time: c.Time, 16 | Certificates: c.Certificates, 17 | NameToCertificate: c.NameToCertificate, 18 | GetCertificate: c.GetCertificate, 19 | RootCAs: c.RootCAs, 20 | NextProtos: c.NextProtos, 21 | ServerName: c.ServerName, 22 | ClientAuth: c.ClientAuth, 23 | ClientCAs: c.ClientCAs, 24 | InsecureSkipVerify: c.InsecureSkipVerify, 25 | CipherSuites: c.CipherSuites, 26 | PreferServerCipherSuites: c.PreferServerCipherSuites, 27 | SessionTicketsDisabled: c.SessionTicketsDisabled, 28 | SessionTicketKey: c.SessionTicketKey, 29 | ClientSessionCache: c.ClientSessionCache, 30 | MinVersion: c.MinVersion, 31 | MaxVersion: c.MaxVersion, 32 | CurvePreferences: c.CurvePreferences, 33 | DynamicRecordSizingDisabled: c.DynamicRecordSizingDisabled, 34 | Renegotiation: c.Renegotiation, 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "io" 12 | "net/http" 13 | ) 14 | 15 | func cloneTLSConfig(c *tls.Config) *tls.Config { 16 | c2 := c.Clone() 17 | c2.GetClientCertificate = c.GetClientCertificate // golang.org/issue/19264 18 | return c2 19 | } 20 | 21 | var _ http.Pusher = (*responseWriter)(nil) 22 | 23 | // Push implements http.Pusher. 24 | func (w *responseWriter) Push(target string, opts *http.PushOptions) error { 25 | internalOpts := pushOptions{} 26 | if opts != nil { 27 | internalOpts.Method = opts.Method 28 | internalOpts.Header = opts.Header 29 | } 30 | return w.push(target, internalOpts) 31 | } 32 | 33 | func configureServer18(h1 *http.Server, h2 *Server) error { 34 | if h2.IdleTimeout == 0 { 35 | if h1.IdleTimeout != 0 { 36 | h2.IdleTimeout = h1.IdleTimeout 37 | } else { 38 | h2.IdleTimeout = h1.ReadTimeout 39 | } 40 | } 41 | return nil 42 | } 43 | 44 | func shouldLogPanic(panicValue interface{}) bool { 45 | return panicValue != nil && panicValue != http.ErrAbortHandler 46 | } 47 | 48 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 49 | return req.GetBody 50 | } 51 | 52 | func reqBodyIsNoBody(body io.ReadCloser) bool { 53 | return body == http.NoBody 54 | } 55 | 56 | func go18httpNoBody() io.ReadCloser { return http.NoBody } // for tests only 57 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | s.RegisterOnShutdown(conf.state.startGracefulShutdown) 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/gotrack.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Defensive debug-only utility to track that functions run on the 6 | // goroutine that they're supposed to. 7 | 8 | package http2 9 | 10 | import ( 11 | "bytes" 12 | "errors" 13 | "fmt" 14 | "os" 15 | "runtime" 16 | "strconv" 17 | "sync" 18 | ) 19 | 20 | var DebugGoroutines = os.Getenv("DEBUG_HTTP2_GOROUTINES") == "1" 21 | 22 | type goroutineLock uint64 23 | 24 | func newGoroutineLock() goroutineLock { 25 | if !DebugGoroutines { 26 | return 0 27 | } 28 | return goroutineLock(curGoroutineID()) 29 | } 30 | 31 | func (g goroutineLock) check() { 32 | if !DebugGoroutines { 33 | return 34 | } 35 | if curGoroutineID() != uint64(g) { 36 | panic("running on the wrong goroutine") 37 | } 38 | } 39 | 40 | func (g goroutineLock) checkNotOn() { 41 | if !DebugGoroutines { 42 | return 43 | } 44 | if curGoroutineID() == uint64(g) { 45 | panic("running on the wrong goroutine") 46 | } 47 | } 48 | 49 | var goroutineSpace = []byte("goroutine ") 50 | 51 | func curGoroutineID() uint64 { 52 | bp := littleBuf.Get().(*[]byte) 53 | defer littleBuf.Put(bp) 54 | b := *bp 55 | b = b[:runtime.Stack(b, false)] 56 | // Parse the 4707 out of "goroutine 4707 [" 57 | b = bytes.TrimPrefix(b, goroutineSpace) 58 | i := bytes.IndexByte(b, ' ') 59 | if i < 0 { 60 | panic(fmt.Sprintf("No space found in %q", b)) 61 | } 62 | b = b[:i] 63 | n, err := parseUintBytes(b, 10, 64) 64 | if err != nil { 65 | panic(fmt.Sprintf("Failed to parse goroutine ID out of %q: %v", b, err)) 66 | } 67 | return n 68 | } 69 | 70 | var littleBuf = sync.Pool{ 71 | New: func() interface{} { 72 | buf := make([]byte, 64) 73 | return &buf 74 | }, 75 | } 76 | 77 | // parseUintBytes is like strconv.ParseUint, but using a []byte. 78 | func parseUintBytes(s []byte, base int, bitSize int) (n uint64, err error) { 79 | var cutoff, maxVal uint64 80 | 81 | if bitSize == 0 { 82 | bitSize = int(strconv.IntSize) 83 | } 84 | 85 | s0 := s 86 | switch { 87 | case len(s) < 1: 88 | err = strconv.ErrSyntax 89 | goto Error 90 | 91 | case 2 <= base && base <= 36: 92 | // valid base; nothing to do 93 | 94 | case base == 0: 95 | // Look for octal, hex prefix. 96 | switch { 97 | case s[0] == '0' && len(s) > 1 && (s[1] == 'x' || s[1] == 'X'): 98 | base = 16 99 | s = s[2:] 100 | if len(s) < 1 { 101 | err = strconv.ErrSyntax 102 | goto Error 103 | } 104 | case s[0] == '0': 105 | base = 8 106 | default: 107 | base = 10 108 | } 109 | 110 | default: 111 | err = errors.New("invalid base " + strconv.Itoa(base)) 112 | goto Error 113 | } 114 | 115 | n = 0 116 | cutoff = cutoff64(base) 117 | maxVal = 1<= base { 135 | n = 0 136 | err = strconv.ErrSyntax 137 | goto Error 138 | } 139 | 140 | if n >= cutoff { 141 | // n*base overflows 142 | n = 1<<64 - 1 143 | err = strconv.ErrRange 144 | goto Error 145 | } 146 | n *= uint64(base) 147 | 148 | n1 := n + uint64(v) 149 | if n1 < n || n1 > maxVal { 150 | // n+v overflows 151 | n = 1<<64 - 1 152 | err = strconv.ErrRange 153 | goto Error 154 | } 155 | n = n1 156 | } 157 | 158 | return n, nil 159 | 160 | Error: 161 | return n, &strconv.NumError{Func: "ParseUint", Num: string(s0), Err: err} 162 | } 163 | 164 | // Return the first number n such that n*base >= 1<<64. 165 | func cutoff64(base int) uint64 { 166 | if base < 2 { 167 | return 0 168 | } 169 | return (1<<64-1)/uint64(base) + 1 170 | } 171 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/headermap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "net/http" 9 | "strings" 10 | "sync" 11 | ) 12 | 13 | var ( 14 | commonBuildOnce sync.Once 15 | commonLowerHeader map[string]string // Go-Canonical-Case -> lower-case 16 | commonCanonHeader map[string]string // lower-case -> Go-Canonical-Case 17 | ) 18 | 19 | func buildCommonHeaderMapsOnce() { 20 | commonBuildOnce.Do(buildCommonHeaderMaps) 21 | } 22 | 23 | func buildCommonHeaderMaps() { 24 | common := []string{ 25 | "accept", 26 | "accept-charset", 27 | "accept-encoding", 28 | "accept-language", 29 | "accept-ranges", 30 | "age", 31 | "access-control-allow-origin", 32 | "allow", 33 | "authorization", 34 | "cache-control", 35 | "content-disposition", 36 | "content-encoding", 37 | "content-language", 38 | "content-length", 39 | "content-location", 40 | "content-range", 41 | "content-type", 42 | "cookie", 43 | "date", 44 | "etag", 45 | "expect", 46 | "expires", 47 | "from", 48 | "host", 49 | "if-match", 50 | "if-modified-since", 51 | "if-none-match", 52 | "if-unmodified-since", 53 | "last-modified", 54 | "link", 55 | "location", 56 | "max-forwards", 57 | "proxy-authenticate", 58 | "proxy-authorization", 59 | "range", 60 | "referer", 61 | "refresh", 62 | "retry-after", 63 | "server", 64 | "set-cookie", 65 | "strict-transport-security", 66 | "trailer", 67 | "transfer-encoding", 68 | "user-agent", 69 | "vary", 70 | "via", 71 | "www-authenticate", 72 | } 73 | commonLowerHeader = make(map[string]string, len(common)) 74 | commonCanonHeader = make(map[string]string, len(common)) 75 | for _, v := range common { 76 | chk := http.CanonicalHeaderKey(v) 77 | commonLowerHeader[chk] = v 78 | commonCanonHeader[v] = chk 79 | } 80 | } 81 | 82 | func lowerHeader(v string) string { 83 | buildCommonHeaderMapsOnce() 84 | if s, ok := commonLowerHeader[v]; ok { 85 | return s 86 | } 87 | return strings.ToLower(v) 88 | } 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go111.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.11 6 | 7 | package http2 8 | 9 | import "net/textproto" 10 | 11 | func traceHasWroteHeaderField(trace *clientTrace) bool { return false } 12 | 13 | func traceWroteHeaderField(trace *clientTrace, k, v string) {} 14 | 15 | func traceGot1xxResponseFunc(trace *clientTrace) func(int, textproto.MIMEHeader) error { 16 | return nil 17 | } 18 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | "time" 12 | ) 13 | 14 | func configureTransport(t1 *http.Transport) (*Transport, error) { 15 | return nil, errTransportVersion 16 | } 17 | 18 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 19 | return 0 20 | 21 | } 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "errors" 12 | "net" 13 | "net/http" 14 | "time" 15 | ) 16 | 17 | type contextContext interface { 18 | Done() <-chan struct{} 19 | Err() error 20 | } 21 | 22 | var errCanceled = errors.New("canceled") 23 | 24 | type fakeContext struct{} 25 | 26 | func (fakeContext) Done() <-chan struct{} { return nil } 27 | func (fakeContext) Err() error { panic("should not be called") } 28 | 29 | func reqContext(r *http.Request) fakeContext { 30 | return fakeContext{} 31 | } 32 | 33 | func setResponseUncompressed(res *http.Response) { 34 | // Nothing. 35 | } 36 | 37 | type clientTrace struct{} 38 | 39 | func requestTrace(*http.Request) *clientTrace { return nil } 40 | func traceGetConn(*http.Request, string) {} 41 | func traceGotConn(*http.Request, *ClientConn) {} 42 | func traceFirstResponseByte(*clientTrace) {} 43 | func traceWroteHeaders(*clientTrace) {} 44 | func traceWroteRequest(*clientTrace, error) {} 45 | func traceGot100Continue(trace *clientTrace) {} 46 | func traceWait100Continue(trace *clientTrace) {} 47 | 48 | func nop() {} 49 | 50 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 51 | return nil, nop 52 | } 53 | 54 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 55 | return ctx, nop 56 | } 57 | 58 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 59 | return req 60 | } 61 | 62 | // temporary copy of Go 1.6's private tls.Config.clone: 63 | func cloneTLSConfig(c *tls.Config) *tls.Config { 64 | return &tls.Config{ 65 | Rand: c.Rand, 66 | Time: c.Time, 67 | Certificates: c.Certificates, 68 | NameToCertificate: c.NameToCertificate, 69 | GetCertificate: c.GetCertificate, 70 | RootCAs: c.RootCAs, 71 | NextProtos: c.NextProtos, 72 | ServerName: c.ServerName, 73 | ClientAuth: c.ClientAuth, 74 | ClientCAs: c.ClientCAs, 75 | InsecureSkipVerify: c.InsecureSkipVerify, 76 | CipherSuites: c.CipherSuites, 77 | PreferServerCipherSuites: c.PreferServerCipherSuites, 78 | SessionTicketsDisabled: c.SessionTicketsDisabled, 79 | SessionTicketKey: c.SessionTicketKey, 80 | ClientSessionCache: c.ClientSessionCache, 81 | MinVersion: c.MinVersion, 82 | MaxVersion: c.MaxVersion, 83 | CurvePreferences: c.CurvePreferences, 84 | } 85 | } 86 | 87 | func (cc *ClientConn) Ping(ctx contextContext) error { 88 | return cc.ping(ctx) 89 | } 90 | 91 | func (cc *ClientConn) Shutdown(ctx contextContext) error { 92 | return cc.shutdown(ctx) 93 | } 94 | 95 | func (t *Transport) idleConnTimeout() time.Duration { return 0 } 96 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go18.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.8 6 | 7 | package http2 8 | 9 | import ( 10 | "io" 11 | "net/http" 12 | ) 13 | 14 | func configureServer18(h1 *http.Server, h2 *Server) error { 15 | // No IdleTimeout to sync prior to Go 1.8. 16 | return nil 17 | } 18 | 19 | func shouldLogPanic(panicValue interface{}) bool { 20 | return panicValue != nil 21 | } 22 | 23 | func reqGetBody(req *http.Request) func() (io.ReadCloser, error) { 24 | return nil 25 | } 26 | 27 | func reqBodyIsNoBody(io.ReadCloser) bool { return false } 28 | 29 | func go18httpNoBody() io.ReadCloser { return nil } // for tests only 30 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go19.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.9 6 | 7 | package http2 8 | 9 | import ( 10 | "net/http" 11 | ) 12 | 13 | func configureServer19(s *http.Server, conf *Server) error { 14 | // not supported prior to go1.9 15 | return nil 16 | } 17 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/pipe.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "errors" 9 | "io" 10 | "sync" 11 | ) 12 | 13 | // pipe is a goroutine-safe io.Reader/io.Writer pair. It's like 14 | // io.Pipe except there are no PipeReader/PipeWriter halves, and the 15 | // underlying buffer is an interface. (io.Pipe is always unbuffered) 16 | type pipe struct { 17 | mu sync.Mutex 18 | c sync.Cond // c.L lazily initialized to &p.mu 19 | b pipeBuffer // nil when done reading 20 | err error // read error once empty. non-nil means closed. 21 | breakErr error // immediate read error (caller doesn't see rest of b) 22 | donec chan struct{} // closed on error 23 | readFn func() // optional code to run in Read before error 24 | } 25 | 26 | type pipeBuffer interface { 27 | Len() int 28 | io.Writer 29 | io.Reader 30 | } 31 | 32 | func (p *pipe) Len() int { 33 | p.mu.Lock() 34 | defer p.mu.Unlock() 35 | if p.b == nil { 36 | return 0 37 | } 38 | return p.b.Len() 39 | } 40 | 41 | // Read waits until data is available and copies bytes 42 | // from the buffer into p. 43 | func (p *pipe) Read(d []byte) (n int, err error) { 44 | p.mu.Lock() 45 | defer p.mu.Unlock() 46 | if p.c.L == nil { 47 | p.c.L = &p.mu 48 | } 49 | for { 50 | if p.breakErr != nil { 51 | return 0, p.breakErr 52 | } 53 | if p.b != nil && p.b.Len() > 0 { 54 | return p.b.Read(d) 55 | } 56 | if p.err != nil { 57 | if p.readFn != nil { 58 | p.readFn() // e.g. copy trailers 59 | p.readFn = nil // not sticky like p.err 60 | } 61 | p.b = nil 62 | return 0, p.err 63 | } 64 | p.c.Wait() 65 | } 66 | } 67 | 68 | var errClosedPipeWrite = errors.New("write on closed buffer") 69 | 70 | // Write copies bytes from p into the buffer and wakes a reader. 71 | // It is an error to write more data than the buffer can hold. 72 | func (p *pipe) Write(d []byte) (n int, err error) { 73 | p.mu.Lock() 74 | defer p.mu.Unlock() 75 | if p.c.L == nil { 76 | p.c.L = &p.mu 77 | } 78 | defer p.c.Signal() 79 | if p.err != nil { 80 | return 0, errClosedPipeWrite 81 | } 82 | if p.breakErr != nil { 83 | return len(d), nil // discard when there is no reader 84 | } 85 | return p.b.Write(d) 86 | } 87 | 88 | // CloseWithError causes the next Read (waking up a current blocked 89 | // Read if needed) to return the provided err after all data has been 90 | // read. 91 | // 92 | // The error must be non-nil. 93 | func (p *pipe) CloseWithError(err error) { p.closeWithError(&p.err, err, nil) } 94 | 95 | // BreakWithError causes the next Read (waking up a current blocked 96 | // Read if needed) to return the provided err immediately, without 97 | // waiting for unread data. 98 | func (p *pipe) BreakWithError(err error) { p.closeWithError(&p.breakErr, err, nil) } 99 | 100 | // closeWithErrorAndCode is like CloseWithError but also sets some code to run 101 | // in the caller's goroutine before returning the error. 102 | func (p *pipe) closeWithErrorAndCode(err error, fn func()) { p.closeWithError(&p.err, err, fn) } 103 | 104 | func (p *pipe) closeWithError(dst *error, err error, fn func()) { 105 | if err == nil { 106 | panic("err must be non-nil") 107 | } 108 | p.mu.Lock() 109 | defer p.mu.Unlock() 110 | if p.c.L == nil { 111 | p.c.L = &p.mu 112 | } 113 | defer p.c.Signal() 114 | if *dst != nil { 115 | // Already been done. 116 | return 117 | } 118 | p.readFn = fn 119 | if dst == &p.breakErr { 120 | p.b = nil 121 | } 122 | *dst = err 123 | p.closeDoneLocked() 124 | } 125 | 126 | // requires p.mu be held. 127 | func (p *pipe) closeDoneLocked() { 128 | if p.donec == nil { 129 | return 130 | } 131 | // Close if unclosed. This isn't racy since we always 132 | // hold p.mu while closing. 133 | select { 134 | case <-p.donec: 135 | default: 136 | close(p.donec) 137 | } 138 | } 139 | 140 | // Err returns the error (if any) first set by BreakWithError or CloseWithError. 141 | func (p *pipe) Err() error { 142 | p.mu.Lock() 143 | defer p.mu.Unlock() 144 | if p.breakErr != nil { 145 | return p.breakErr 146 | } 147 | return p.err 148 | } 149 | 150 | // Done returns a channel which is closed if and when this pipe is closed 151 | // with CloseWithError. 152 | func (p *pipe) Done() <-chan struct{} { 153 | p.mu.Lock() 154 | defer p.mu.Unlock() 155 | if p.donec == nil { 156 | p.donec = make(chan struct{}) 157 | if p.err != nil || p.breakErr != nil { 158 | // Already hit an error. 159 | p.closeDoneLocked() 160 | } 161 | } 162 | return p.donec 163 | } 164 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/writesched_random.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import "math" 8 | 9 | // NewRandomWriteScheduler constructs a WriteScheduler that ignores HTTP/2 10 | // priorities. Control frames like SETTINGS and PING are written before DATA 11 | // frames, but if no control frames are queued and multiple streams have queued 12 | // HEADERS or DATA frames, Pop selects a ready stream arbitrarily. 13 | func NewRandomWriteScheduler() WriteScheduler { 14 | return &randomWriteScheduler{sq: make(map[uint32]*writeQueue)} 15 | } 16 | 17 | type randomWriteScheduler struct { 18 | // zero are frames not associated with a specific stream. 19 | zero writeQueue 20 | 21 | // sq contains the stream-specific queues, keyed by stream ID. 22 | // When a stream is idle or closed, it's deleted from the map. 23 | sq map[uint32]*writeQueue 24 | 25 | // pool of empty queues for reuse. 26 | queuePool writeQueuePool 27 | } 28 | 29 | func (ws *randomWriteScheduler) OpenStream(streamID uint32, options OpenStreamOptions) { 30 | // no-op: idle streams are not tracked 31 | } 32 | 33 | func (ws *randomWriteScheduler) CloseStream(streamID uint32) { 34 | q, ok := ws.sq[streamID] 35 | if !ok { 36 | return 37 | } 38 | delete(ws.sq, streamID) 39 | ws.queuePool.put(q) 40 | } 41 | 42 | func (ws *randomWriteScheduler) AdjustStream(streamID uint32, priority PriorityParam) { 43 | // no-op: priorities are ignored 44 | } 45 | 46 | func (ws *randomWriteScheduler) Push(wr FrameWriteRequest) { 47 | id := wr.StreamID() 48 | if id == 0 { 49 | ws.zero.push(wr) 50 | return 51 | } 52 | q, ok := ws.sq[id] 53 | if !ok { 54 | q = ws.queuePool.get() 55 | ws.sq[id] = q 56 | } 57 | q.push(wr) 58 | } 59 | 60 | func (ws *randomWriteScheduler) Pop() (FrameWriteRequest, bool) { 61 | // Control frames first. 62 | if !ws.zero.empty() { 63 | return ws.zero.shift(), true 64 | } 65 | // Iterate over all non-idle streams until finding one that can be consumed. 66 | for _, q := range ws.sq { 67 | if wr, ok := q.consume(math.MaxInt32); ok { 68 | return wr, true 69 | } 70 | } 71 | return FrameWriteRequest{}, false 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/trie.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | // Copyright 2016 The Go Authors. All rights reserved. 4 | // Use of this source code is governed by a BSD-style 5 | // license that can be found in the LICENSE file. 6 | 7 | package idna 8 | 9 | // appendMapping appends the mapping for the respective rune. isMapped must be 10 | // true. A mapping is a categorization of a rune as defined in UTS #46. 11 | func (c info) appendMapping(b []byte, s string) []byte { 12 | index := int(c >> indexShift) 13 | if c&xorBit == 0 { 14 | s := mappings[index:] 15 | return append(b, s[1:s[0]+1]...) 16 | } 17 | b = append(b, s...) 18 | if c&inlineXOR == inlineXOR { 19 | // TODO: support and handle two-byte inline masks 20 | b[len(b)-1] ^= byte(index) 21 | } else { 22 | for p := len(b) - int(xorData[index]); p < len(b); p++ { 23 | index++ 24 | b[p] ^= xorData[index] 25 | } 26 | } 27 | return b 28 | } 29 | 30 | // Sparse block handling code. 31 | 32 | type valueRange struct { 33 | value uint16 // header: value:stride 34 | lo, hi byte // header: lo:n 35 | } 36 | 37 | type sparseBlocks struct { 38 | values []valueRange 39 | offset []uint16 40 | } 41 | 42 | var idnaSparse = sparseBlocks{ 43 | values: idnaSparseValues[:], 44 | offset: idnaSparseOffset[:], 45 | } 46 | 47 | // Don't use newIdnaTrie to avoid unconditional linking in of the table. 48 | var trie = &idnaTrie{} 49 | 50 | // lookup determines the type of block n and looks up the value for b. 51 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 52 | // is a list of ranges with an accompanying value. Given a matching range r, 53 | // the value for b is by r.value + (b - r.lo) * stride. 54 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 55 | offset := t.offset[n] 56 | header := t.values[offset] 57 | lo := offset + 1 58 | hi := lo + uint16(header.lo) 59 | for lo < hi { 60 | m := lo + (hi-lo)/2 61 | r := t.values[m] 62 | if r.lo <= b && b <= r.hi { 63 | return r.value + uint16(b-r.lo)*header.value 64 | } 65 | if b < r.lo { 66 | hi = m 67 | } else { 68 | lo = m + 1 69 | } 70 | } 71 | return 0 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/idna/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package idna 4 | 5 | // This file contains definitions for interpreting the trie value of the idna 6 | // trie generated by "go run gen*.go". It is shared by both the generator 7 | // program and the resultant package. Sharing is achieved by the generator 8 | // copying gen_trieval.go to trieval.go and changing what's above this comment. 9 | 10 | // info holds information from the IDNA mapping table for a single rune. It is 11 | // the value returned by a trie lookup. In most cases, all information fits in 12 | // a 16-bit value. For mappings, this value may contain an index into a slice 13 | // with the mapped string. Such mappings can consist of the actual mapped value 14 | // or an XOR pattern to be applied to the bytes of the UTF8 encoding of the 15 | // input rune. This technique is used by the cases packages and reduces the 16 | // table size significantly. 17 | // 18 | // The per-rune values have the following format: 19 | // 20 | // if mapped { 21 | // if inlinedXOR { 22 | // 15..13 inline XOR marker 23 | // 12..11 unused 24 | // 10..3 inline XOR mask 25 | // } else { 26 | // 15..3 index into xor or mapping table 27 | // } 28 | // } else { 29 | // 15..14 unused 30 | // 13 mayNeedNorm 31 | // 12..11 attributes 32 | // 10..8 joining type 33 | // 7..3 category type 34 | // } 35 | // 2 use xor pattern 36 | // 1..0 mapped category 37 | // 38 | // See the definitions below for a more detailed description of the various 39 | // bits. 40 | type info uint16 41 | 42 | const ( 43 | catSmallMask = 0x3 44 | catBigMask = 0xF8 45 | indexShift = 3 46 | xorBit = 0x4 // interpret the index as an xor pattern 47 | inlineXOR = 0xE000 // These bits are set if the XOR pattern is inlined. 48 | 49 | joinShift = 8 50 | joinMask = 0x07 51 | 52 | // Attributes 53 | attributesMask = 0x1800 54 | viramaModifier = 0x1800 55 | modifier = 0x1000 56 | rtl = 0x0800 57 | 58 | mayNeedNorm = 0x2000 59 | ) 60 | 61 | // A category corresponds to a category defined in the IDNA mapping table. 62 | type category uint16 63 | 64 | const ( 65 | unknown category = 0 // not currently defined in unicode. 66 | mapped category = 1 67 | disallowedSTD3Mapped category = 2 68 | deviation category = 3 69 | ) 70 | 71 | const ( 72 | valid category = 0x08 73 | validNV8 category = 0x18 74 | validXV8 category = 0x28 75 | disallowed category = 0x40 76 | disallowedSTD3Valid category = 0x80 77 | ignored category = 0xC0 78 | ) 79 | 80 | // join types and additional rune information 81 | const ( 82 | joiningL = (iota + 1) 83 | joiningD 84 | joiningT 85 | joiningR 86 | 87 | //the following types are derived during processing 88 | joinZWJ 89 | joinZWNJ 90 | joinVirama 91 | numJoinTypes 92 | ) 93 | 94 | func (c info) isMapped() bool { 95 | return c&0x3 != 0 96 | } 97 | 98 | func (c info) category() category { 99 | small := c & catSmallMask 100 | if small != 0 { 101 | return category(small) 102 | } 103 | return category(c & catBigMask) 104 | } 105 | 106 | func (c info) joinType() info { 107 | if c.isMapped() { 108 | return 0 109 | } 110 | return (c >> joinShift) & joinMask 111 | } 112 | 113 | func (c info) isModifier() bool { 114 | return c&(modifier|catSmallMask) == modifier 115 | } 116 | 117 | func (c info) isViramaModifier() bool { 118 | return c&(attributesMask|catSmallMask) == viramaModifier 119 | } 120 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule10.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 11 | } 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/secure/bidirule/bidirule9.0.0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.10 6 | 7 | package bidirule 8 | 9 | func (t *Transformer) isFinal() bool { 10 | if !t.isRTL() { 11 | return true 12 | } 13 | return t.state == ruleLTRFinal || t.state == ruleRTLFinal || t.state == ruleInitial 14 | } 15 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/gen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "flag" 11 | "log" 12 | 13 | "golang.org/x/text/internal/gen" 14 | "golang.org/x/text/internal/triegen" 15 | "golang.org/x/text/internal/ucd" 16 | ) 17 | 18 | var outputFile = flag.String("out", "tables.go", "output file") 19 | 20 | func main() { 21 | gen.Init() 22 | gen.Repackage("gen_trieval.go", "trieval.go", "bidi") 23 | gen.Repackage("gen_ranges.go", "ranges_test.go", "bidi") 24 | 25 | genTables() 26 | } 27 | 28 | // bidiClass names and codes taken from class "bc" in 29 | // http://www.unicode.org/Public/8.0.0/ucd/PropertyValueAliases.txt 30 | var bidiClass = map[string]Class{ 31 | "AL": AL, // ArabicLetter 32 | "AN": AN, // ArabicNumber 33 | "B": B, // ParagraphSeparator 34 | "BN": BN, // BoundaryNeutral 35 | "CS": CS, // CommonSeparator 36 | "EN": EN, // EuropeanNumber 37 | "ES": ES, // EuropeanSeparator 38 | "ET": ET, // EuropeanTerminator 39 | "L": L, // LeftToRight 40 | "NSM": NSM, // NonspacingMark 41 | "ON": ON, // OtherNeutral 42 | "R": R, // RightToLeft 43 | "S": S, // SegmentSeparator 44 | "WS": WS, // WhiteSpace 45 | 46 | "FSI": Control, 47 | "PDF": Control, 48 | "PDI": Control, 49 | "LRE": Control, 50 | "LRI": Control, 51 | "LRO": Control, 52 | "RLE": Control, 53 | "RLI": Control, 54 | "RLO": Control, 55 | } 56 | 57 | func genTables() { 58 | if numClass > 0x0F { 59 | log.Fatalf("Too many Class constants (%#x > 0x0F).", numClass) 60 | } 61 | w := gen.NewCodeWriter() 62 | defer w.WriteVersionedGoFile(*outputFile, "bidi") 63 | 64 | gen.WriteUnicodeVersion(w) 65 | 66 | t := triegen.NewTrie("bidi") 67 | 68 | // Build data about bracket mapping. These bits need to be or-ed with 69 | // any other bits. 70 | orMask := map[rune]uint64{} 71 | 72 | xorMap := map[rune]int{} 73 | xorMasks := []rune{0} // First value is no-op. 74 | 75 | ucd.Parse(gen.OpenUCDFile("BidiBrackets.txt"), func(p *ucd.Parser) { 76 | r1 := p.Rune(0) 77 | r2 := p.Rune(1) 78 | xor := r1 ^ r2 79 | if _, ok := xorMap[xor]; !ok { 80 | xorMap[xor] = len(xorMasks) 81 | xorMasks = append(xorMasks, xor) 82 | } 83 | entry := uint64(xorMap[xor]) << xorMaskShift 84 | switch p.String(2) { 85 | case "o": 86 | entry |= openMask 87 | case "c", "n": 88 | default: 89 | log.Fatalf("Unknown bracket class %q.", p.String(2)) 90 | } 91 | orMask[r1] = entry 92 | }) 93 | 94 | w.WriteComment(` 95 | xorMasks contains masks to be xor-ed with brackets to get the reverse 96 | version.`) 97 | w.WriteVar("xorMasks", xorMasks) 98 | 99 | done := map[rune]bool{} 100 | 101 | insert := func(r rune, c Class) { 102 | if !done[r] { 103 | t.Insert(r, orMask[r]|uint64(c)) 104 | done[r] = true 105 | } 106 | } 107 | 108 | // Insert the derived BiDi properties. 109 | ucd.Parse(gen.OpenUCDFile("extracted/DerivedBidiClass.txt"), func(p *ucd.Parser) { 110 | r := p.Rune(0) 111 | class, ok := bidiClass[p.String(1)] 112 | if !ok { 113 | log.Fatalf("%U: Unknown BiDi class %q", r, p.String(1)) 114 | } 115 | insert(r, class) 116 | }) 117 | visitDefaults(insert) 118 | 119 | // TODO: use sparse blocks. This would reduce table size considerably 120 | // from the looks of it. 121 | 122 | sz, err := t.Gen(w) 123 | if err != nil { 124 | log.Fatal(err) 125 | } 126 | w.Size += sz 127 | } 128 | 129 | // dummy values to make methods in gen_common compile. The real versions 130 | // will be generated by this file to tables.go. 131 | var ( 132 | xorMasks []rune 133 | ) 134 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/gen_ranges.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | import ( 10 | "unicode" 11 | 12 | "golang.org/x/text/internal/gen" 13 | "golang.org/x/text/internal/ucd" 14 | "golang.org/x/text/unicode/rangetable" 15 | ) 16 | 17 | // These tables are hand-extracted from: 18 | // http://www.unicode.org/Public/8.0.0/ucd/extracted/DerivedBidiClass.txt 19 | func visitDefaults(fn func(r rune, c Class)) { 20 | // first write default values for ranges listed above. 21 | visitRunes(fn, AL, []rune{ 22 | 0x0600, 0x07BF, // Arabic 23 | 0x08A0, 0x08FF, // Arabic Extended-A 24 | 0xFB50, 0xFDCF, // Arabic Presentation Forms 25 | 0xFDF0, 0xFDFF, 26 | 0xFE70, 0xFEFF, 27 | 0x0001EE00, 0x0001EEFF, // Arabic Mathematical Alpha Symbols 28 | }) 29 | visitRunes(fn, R, []rune{ 30 | 0x0590, 0x05FF, // Hebrew 31 | 0x07C0, 0x089F, // Nko et al. 32 | 0xFB1D, 0xFB4F, 33 | 0x00010800, 0x00010FFF, // Cypriot Syllabary et. al. 34 | 0x0001E800, 0x0001EDFF, 35 | 0x0001EF00, 0x0001EFFF, 36 | }) 37 | visitRunes(fn, ET, []rune{ // European Terminator 38 | 0x20A0, 0x20Cf, // Currency symbols 39 | }) 40 | rangetable.Visit(unicode.Noncharacter_Code_Point, func(r rune) { 41 | fn(r, BN) // Boundary Neutral 42 | }) 43 | ucd.Parse(gen.OpenUCDFile("DerivedCoreProperties.txt"), func(p *ucd.Parser) { 44 | if p.String(1) == "Default_Ignorable_Code_Point" { 45 | fn(p.Rune(0), BN) // Boundary Neutral 46 | } 47 | }) 48 | } 49 | 50 | func visitRunes(fn func(r rune, c Class), c Class, runes []rune) { 51 | for i := 0; i < len(runes); i += 2 { 52 | lo, hi := runes[i], runes[i+1] 53 | for j := lo; j <= hi; j++ { 54 | fn(j, c) 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/gen_trieval.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | package main 8 | 9 | // Class is the Unicode BiDi class. Each rune has a single class. 10 | type Class uint 11 | 12 | const ( 13 | L Class = iota // LeftToRight 14 | R // RightToLeft 15 | EN // EuropeanNumber 16 | ES // EuropeanSeparator 17 | ET // EuropeanTerminator 18 | AN // ArabicNumber 19 | CS // CommonSeparator 20 | B // ParagraphSeparator 21 | S // SegmentSeparator 22 | WS // WhiteSpace 23 | ON // OtherNeutral 24 | BN // BoundaryNeutral 25 | NSM // NonspacingMark 26 | AL // ArabicLetter 27 | Control // Control LRO - PDI 28 | 29 | numClass 30 | 31 | LRO // LeftToRightOverride 32 | RLO // RightToLeftOverride 33 | LRE // LeftToRightEmbedding 34 | RLE // RightToLeftEmbedding 35 | PDF // PopDirectionalFormat 36 | LRI // LeftToRightIsolate 37 | RLI // RightToLeftIsolate 38 | FSI // FirstStrongIsolate 39 | PDI // PopDirectionalIsolate 40 | 41 | unknownClass = ^Class(0) 42 | ) 43 | 44 | var controlToClass = map[rune]Class{ 45 | 0x202D: LRO, // LeftToRightOverride, 46 | 0x202E: RLO, // RightToLeftOverride, 47 | 0x202A: LRE, // LeftToRightEmbedding, 48 | 0x202B: RLE, // RightToLeftEmbedding, 49 | 0x202C: PDF, // PopDirectionalFormat, 50 | 0x2066: LRI, // LeftToRightIsolate, 51 | 0x2067: RLI, // RightToLeftIsolate, 52 | 0x2068: FSI, // FirstStrongIsolate, 53 | 0x2069: PDI, // PopDirectionalIsolate, 54 | } 55 | 56 | // A trie entry has the following bits: 57 | // 7..5 XOR mask for brackets 58 | // 4 1: Bracket open, 0: Bracket close 59 | // 3..0 Class type 60 | 61 | const ( 62 | openMask = 0x10 63 | xorMaskShift = 5 64 | ) 65 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/bidi/trieval.go: -------------------------------------------------------------------------------- 1 | // Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT. 2 | 3 | package bidi 4 | 5 | // Class is the Unicode BiDi class. Each rune has a single class. 6 | type Class uint 7 | 8 | const ( 9 | L Class = iota // LeftToRight 10 | R // RightToLeft 11 | EN // EuropeanNumber 12 | ES // EuropeanSeparator 13 | ET // EuropeanTerminator 14 | AN // ArabicNumber 15 | CS // CommonSeparator 16 | B // ParagraphSeparator 17 | S // SegmentSeparator 18 | WS // WhiteSpace 19 | ON // OtherNeutral 20 | BN // BoundaryNeutral 21 | NSM // NonspacingMark 22 | AL // ArabicLetter 23 | Control // Control LRO - PDI 24 | 25 | numClass 26 | 27 | LRO // LeftToRightOverride 28 | RLO // RightToLeftOverride 29 | LRE // LeftToRightEmbedding 30 | RLE // RightToLeftEmbedding 31 | PDF // PopDirectionalFormat 32 | LRI // LeftToRightIsolate 33 | RLI // RightToLeftIsolate 34 | FSI // FirstStrongIsolate 35 | PDI // PopDirectionalIsolate 36 | 37 | unknownClass = ^Class(0) 38 | ) 39 | 40 | var controlToClass = map[rune]Class{ 41 | 0x202D: LRO, // LeftToRightOverride, 42 | 0x202E: RLO, // RightToLeftOverride, 43 | 0x202A: LRE, // LeftToRightEmbedding, 44 | 0x202B: RLE, // RightToLeftEmbedding, 45 | 0x202C: PDF, // PopDirectionalFormat, 46 | 0x2066: LRI, // LeftToRightIsolate, 47 | 0x2067: RLI, // RightToLeftIsolate, 48 | 0x2068: FSI, // FirstStrongIsolate, 49 | 0x2069: PDI, // PopDirectionalIsolate, 50 | } 51 | 52 | // A trie entry has the following bits: 53 | // 7..5 XOR mask for brackets 54 | // 4 1: Bracket open, 0: Bracket close 55 | // 3..0 Class type 56 | 57 | const ( 58 | openMask = 0x10 59 | xorMaskShift = 5 60 | ) 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/input.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "unicode/utf8" 8 | 9 | type input struct { 10 | str string 11 | bytes []byte 12 | } 13 | 14 | func inputBytes(str []byte) input { 15 | return input{bytes: str} 16 | } 17 | 18 | func inputString(str string) input { 19 | return input{str: str} 20 | } 21 | 22 | func (in *input) setBytes(str []byte) { 23 | in.str = "" 24 | in.bytes = str 25 | } 26 | 27 | func (in *input) setString(str string) { 28 | in.str = str 29 | in.bytes = nil 30 | } 31 | 32 | func (in *input) _byte(p int) byte { 33 | if in.bytes == nil { 34 | return in.str[p] 35 | } 36 | return in.bytes[p] 37 | } 38 | 39 | func (in *input) skipASCII(p, max int) int { 40 | if in.bytes == nil { 41 | for ; p < max && in.str[p] < utf8.RuneSelf; p++ { 42 | } 43 | } else { 44 | for ; p < max && in.bytes[p] < utf8.RuneSelf; p++ { 45 | } 46 | } 47 | return p 48 | } 49 | 50 | func (in *input) skipContinuationBytes(p int) int { 51 | if in.bytes == nil { 52 | for ; p < len(in.str) && !utf8.RuneStart(in.str[p]); p++ { 53 | } 54 | } else { 55 | for ; p < len(in.bytes) && !utf8.RuneStart(in.bytes[p]); p++ { 56 | } 57 | } 58 | return p 59 | } 60 | 61 | func (in *input) appendSlice(buf []byte, b, e int) []byte { 62 | if in.bytes != nil { 63 | return append(buf, in.bytes[b:e]...) 64 | } 65 | for i := b; i < e; i++ { 66 | buf = append(buf, in.str[i]) 67 | } 68 | return buf 69 | } 70 | 71 | func (in *input) copySlice(buf []byte, b, e int) int { 72 | if in.bytes == nil { 73 | return copy(buf, in.str[b:e]) 74 | } 75 | return copy(buf, in.bytes[b:e]) 76 | } 77 | 78 | func (in *input) charinfoNFC(p int) (uint16, int) { 79 | if in.bytes == nil { 80 | return nfcData.lookupString(in.str[p:]) 81 | } 82 | return nfcData.lookup(in.bytes[p:]) 83 | } 84 | 85 | func (in *input) charinfoNFKC(p int) (uint16, int) { 86 | if in.bytes == nil { 87 | return nfkcData.lookupString(in.str[p:]) 88 | } 89 | return nfkcData.lookup(in.bytes[p:]) 90 | } 91 | 92 | func (in *input) hangul(p int) (r rune) { 93 | var size int 94 | if in.bytes == nil { 95 | if !isHangulString(in.str[p:]) { 96 | return 0 97 | } 98 | r, size = utf8.DecodeRuneInString(in.str[p:]) 99 | } else { 100 | if !isHangul(in.bytes[p:]) { 101 | return 0 102 | } 103 | r, size = utf8.DecodeRune(in.bytes[p:]) 104 | } 105 | if size != hangulUTF8Size { 106 | return 0 107 | } 108 | return r 109 | } 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/readwriter.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import "io" 8 | 9 | type normWriter struct { 10 | rb reorderBuffer 11 | w io.Writer 12 | buf []byte 13 | } 14 | 15 | // Write implements the standard write interface. If the last characters are 16 | // not at a normalization boundary, the bytes will be buffered for the next 17 | // write. The remaining bytes will be written on close. 18 | func (w *normWriter) Write(data []byte) (n int, err error) { 19 | // Process data in pieces to keep w.buf size bounded. 20 | const chunk = 4000 21 | 22 | for len(data) > 0 { 23 | // Normalize into w.buf. 24 | m := len(data) 25 | if m > chunk { 26 | m = chunk 27 | } 28 | w.rb.src = inputBytes(data[:m]) 29 | w.rb.nsrc = m 30 | w.buf = doAppend(&w.rb, w.buf, 0) 31 | data = data[m:] 32 | n += m 33 | 34 | // Write out complete prefix, save remainder. 35 | // Note that lastBoundary looks back at most 31 runes. 36 | i := lastBoundary(&w.rb.f, w.buf) 37 | if i == -1 { 38 | i = 0 39 | } 40 | if i > 0 { 41 | if _, err = w.w.Write(w.buf[:i]); err != nil { 42 | break 43 | } 44 | bn := copy(w.buf, w.buf[i:]) 45 | w.buf = w.buf[:bn] 46 | } 47 | } 48 | return n, err 49 | } 50 | 51 | // Close forces data that remains in the buffer to be written. 52 | func (w *normWriter) Close() error { 53 | if len(w.buf) > 0 { 54 | _, err := w.w.Write(w.buf) 55 | if err != nil { 56 | return err 57 | } 58 | } 59 | return nil 60 | } 61 | 62 | // Writer returns a new writer that implements Write(b) 63 | // by writing f(b) to w. The returned writer may use an 64 | // an internal buffer to maintain state across Write calls. 65 | // Calling its Close method writes any buffered data to w. 66 | func (f Form) Writer(w io.Writer) io.WriteCloser { 67 | wr := &normWriter{rb: reorderBuffer{}, w: w} 68 | wr.rb.init(f, nil) 69 | return wr 70 | } 71 | 72 | type normReader struct { 73 | rb reorderBuffer 74 | r io.Reader 75 | inbuf []byte 76 | outbuf []byte 77 | bufStart int 78 | lastBoundary int 79 | err error 80 | } 81 | 82 | // Read implements the standard read interface. 83 | func (r *normReader) Read(p []byte) (int, error) { 84 | for { 85 | if r.lastBoundary-r.bufStart > 0 { 86 | n := copy(p, r.outbuf[r.bufStart:r.lastBoundary]) 87 | r.bufStart += n 88 | if r.lastBoundary-r.bufStart > 0 { 89 | return n, nil 90 | } 91 | return n, r.err 92 | } 93 | if r.err != nil { 94 | return 0, r.err 95 | } 96 | outn := copy(r.outbuf, r.outbuf[r.lastBoundary:]) 97 | r.outbuf = r.outbuf[0:outn] 98 | r.bufStart = 0 99 | 100 | n, err := r.r.Read(r.inbuf) 101 | r.rb.src = inputBytes(r.inbuf[0:n]) 102 | r.rb.nsrc, r.err = n, err 103 | if n > 0 { 104 | r.outbuf = doAppend(&r.rb, r.outbuf, 0) 105 | } 106 | if err == io.EOF { 107 | r.lastBoundary = len(r.outbuf) 108 | } else { 109 | r.lastBoundary = lastBoundary(&r.rb.f, r.outbuf) 110 | if r.lastBoundary == -1 { 111 | r.lastBoundary = 0 112 | } 113 | } 114 | } 115 | } 116 | 117 | // Reader returns a new reader that implements Read 118 | // by reading data from r and returning f(data). 119 | func (f Form) Reader(r io.Reader) io.Reader { 120 | const chunk = 4000 121 | buf := make([]byte, chunk) 122 | rr := &normReader{rb: reorderBuffer{}, r: r, inbuf: buf} 123 | rr.rb.init(f, buf) 124 | return rr 125 | } 126 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/transform.go: -------------------------------------------------------------------------------- 1 | // Copyright 2013 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | import ( 8 | "unicode/utf8" 9 | 10 | "golang.org/x/text/transform" 11 | ) 12 | 13 | // Reset implements the Reset method of the transform.Transformer interface. 14 | func (Form) Reset() {} 15 | 16 | // Transform implements the Transform method of the transform.Transformer 17 | // interface. It may need to write segments of up to MaxSegmentSize at once. 18 | // Users should either catch ErrShortDst and allow dst to grow or have dst be at 19 | // least of size MaxTransformChunkSize to be guaranteed of progress. 20 | func (f Form) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 21 | n := 0 22 | // Cap the maximum number of src bytes to check. 23 | b := src 24 | eof := atEOF 25 | if ns := len(dst); ns < len(b) { 26 | err = transform.ErrShortDst 27 | eof = false 28 | b = b[:ns] 29 | } 30 | i, ok := formTable[f].quickSpan(inputBytes(b), n, len(b), eof) 31 | n += copy(dst[n:], b[n:i]) 32 | if !ok { 33 | nDst, nSrc, err = f.transform(dst[n:], src[n:], atEOF) 34 | return nDst + n, nSrc + n, err 35 | } 36 | if n < len(src) && !atEOF { 37 | err = transform.ErrShortSrc 38 | } 39 | return n, n, err 40 | } 41 | 42 | func flushTransform(rb *reorderBuffer) bool { 43 | // Write out (must fully fit in dst, or else it is an ErrShortDst). 44 | if len(rb.out) < rb.nrune*utf8.UTFMax { 45 | return false 46 | } 47 | rb.out = rb.out[rb.flushCopy(rb.out):] 48 | return true 49 | } 50 | 51 | var errs = []error{nil, transform.ErrShortDst, transform.ErrShortSrc} 52 | 53 | // transform implements the transform.Transformer interface. It is only called 54 | // when quickSpan does not pass for a given string. 55 | func (f Form) transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err error) { 56 | // TODO: get rid of reorderBuffer. See CL 23460044. 57 | rb := reorderBuffer{} 58 | rb.init(f, src) 59 | for { 60 | // Load segment into reorder buffer. 61 | rb.setFlusher(dst[nDst:], flushTransform) 62 | end := decomposeSegment(&rb, nSrc, atEOF) 63 | if end < 0 { 64 | return nDst, nSrc, errs[-end] 65 | } 66 | nDst = len(dst) - len(rb.out) 67 | nSrc = end 68 | 69 | // Next quickSpan. 70 | end = rb.nsrc 71 | eof := atEOF 72 | if n := nSrc + len(dst) - nDst; n < end { 73 | err = transform.ErrShortDst 74 | end = n 75 | eof = false 76 | } 77 | end, ok := rb.f.quickSpan(rb.src, nSrc, end, eof) 78 | n := copy(dst[nDst:], rb.src.bytes[nSrc:end]) 79 | nSrc += n 80 | nDst += n 81 | if ok { 82 | if n < rb.nsrc && !atEOF { 83 | err = transform.ErrShortSrc 84 | } 85 | return nDst, nSrc, err 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/trie.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package norm 6 | 7 | type valueRange struct { 8 | value uint16 // header: value:stride 9 | lo, hi byte // header: lo:n 10 | } 11 | 12 | type sparseBlocks struct { 13 | values []valueRange 14 | offset []uint16 15 | } 16 | 17 | var nfcSparse = sparseBlocks{ 18 | values: nfcSparseValues[:], 19 | offset: nfcSparseOffset[:], 20 | } 21 | 22 | var nfkcSparse = sparseBlocks{ 23 | values: nfkcSparseValues[:], 24 | offset: nfkcSparseOffset[:], 25 | } 26 | 27 | var ( 28 | nfcData = newNfcTrie(0) 29 | nfkcData = newNfkcTrie(0) 30 | ) 31 | 32 | // lookupValue determines the type of block n and looks up the value for b. 33 | // For n < t.cutoff, the block is a simple lookup table. Otherwise, the block 34 | // is a list of ranges with an accompanying value. Given a matching range r, 35 | // the value for b is by r.value + (b - r.lo) * stride. 36 | func (t *sparseBlocks) lookup(n uint32, b byte) uint16 { 37 | offset := t.offset[n] 38 | header := t.values[offset] 39 | lo := offset + 1 40 | hi := lo + uint16(header.lo) 41 | for lo < hi { 42 | m := lo + (hi-lo)/2 43 | r := t.values[m] 44 | if r.lo <= b && b <= r.hi { 45 | return r.value + uint16(b-r.lo)*header.value 46 | } 47 | if b < r.lo { 48 | hi = m 49 | } else { 50 | lo = m + 1 51 | } 52 | } 53 | return 0 54 | } 55 | -------------------------------------------------------------------------------- /vendor/golang.org/x/text/unicode/norm/triegen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build ignore 6 | 7 | // Trie table generator. 8 | // Used by make*tables tools to generate a go file with trie data structures 9 | // for mapping UTF-8 to a 16-bit value. All but the last byte in a UTF-8 byte 10 | // sequence are used to lookup offsets in the index table to be used for the 11 | // next byte. The last byte is used to index into a table with 16-bit values. 12 | 13 | package main 14 | 15 | import ( 16 | "fmt" 17 | "io" 18 | ) 19 | 20 | const maxSparseEntries = 16 21 | 22 | type normCompacter struct { 23 | sparseBlocks [][]uint64 24 | sparseOffset []uint16 25 | sparseCount int 26 | name string 27 | } 28 | 29 | func mostFrequentStride(a []uint64) int { 30 | counts := make(map[int]int) 31 | var v int 32 | for _, x := range a { 33 | if stride := int(x) - v; v != 0 && stride >= 0 { 34 | counts[stride]++ 35 | } 36 | v = int(x) 37 | } 38 | var maxs, maxc int 39 | for stride, cnt := range counts { 40 | if cnt > maxc || (cnt == maxc && stride < maxs) { 41 | maxs, maxc = stride, cnt 42 | } 43 | } 44 | return maxs 45 | } 46 | 47 | func countSparseEntries(a []uint64) int { 48 | stride := mostFrequentStride(a) 49 | var v, count int 50 | for _, tv := range a { 51 | if int(tv)-v != stride { 52 | if tv != 0 { 53 | count++ 54 | } 55 | } 56 | v = int(tv) 57 | } 58 | return count 59 | } 60 | 61 | func (c *normCompacter) Size(v []uint64) (sz int, ok bool) { 62 | if n := countSparseEntries(v); n <= maxSparseEntries { 63 | return (n+1)*4 + 2, true 64 | } 65 | return 0, false 66 | } 67 | 68 | func (c *normCompacter) Store(v []uint64) uint32 { 69 | h := uint32(len(c.sparseOffset)) 70 | c.sparseBlocks = append(c.sparseBlocks, v) 71 | c.sparseOffset = append(c.sparseOffset, uint16(c.sparseCount)) 72 | c.sparseCount += countSparseEntries(v) + 1 73 | return h 74 | } 75 | 76 | func (c *normCompacter) Handler() string { 77 | return c.name + "Sparse.lookup" 78 | } 79 | 80 | func (c *normCompacter) Print(w io.Writer) (retErr error) { 81 | p := func(f string, x ...interface{}) { 82 | if _, err := fmt.Fprintf(w, f, x...); retErr == nil && err != nil { 83 | retErr = err 84 | } 85 | } 86 | 87 | ls := len(c.sparseBlocks) 88 | p("// %sSparseOffset: %d entries, %d bytes\n", c.name, ls, ls*2) 89 | p("var %sSparseOffset = %#v\n\n", c.name, c.sparseOffset) 90 | 91 | ns := c.sparseCount 92 | p("// %sSparseValues: %d entries, %d bytes\n", c.name, ns, ns*4) 93 | p("var %sSparseValues = [%d]valueRange {", c.name, ns) 94 | for i, b := range c.sparseBlocks { 95 | p("\n// Block %#x, offset %#x", i, c.sparseOffset[i]) 96 | var v int 97 | stride := mostFrequentStride(b) 98 | n := countSparseEntries(b) 99 | p("\n{value:%#04x,lo:%#02x},", stride, uint8(n)) 100 | for i, nv := range b { 101 | if int(nv)-v != stride { 102 | if v != 0 { 103 | p(",hi:%#02x},", 0x80+i-1) 104 | } 105 | if nv != 0 { 106 | p("\n{value:%#04x,lo:%#02x", nv, 0x80+i) 107 | } 108 | } 109 | v = int(nv) 110 | } 111 | if v != 0 { 112 | p(",hi:%#02x},", 0x80+len(b)-1) 113 | } 114 | } 115 | p("\n}\n\n") 116 | return 117 | } 118 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/fatih/structs v1.0.0 2 | github.com/fatih/structs 3 | # github.com/golang/snappy v0.0.0-20170215233205-553a64147049 4 | github.com/golang/snappy 5 | # github.com/hashicorp/errwrap v0.0.0-20141028054710-7554cd9344ce 6 | github.com/hashicorp/errwrap 7 | # github.com/hashicorp/go-cleanhttp v0.0.0-20171218145408-d5fe4b57a186 8 | github.com/hashicorp/go-cleanhttp 9 | # github.com/hashicorp/go-multierror v0.0.0-20171204182908-b7773ae21874 10 | github.com/hashicorp/go-multierror 11 | # github.com/hashicorp/go-rootcerts v0.0.0-20160503143440-6bb64b370b90 12 | github.com/hashicorp/go-rootcerts 13 | # github.com/hashicorp/hcl v0.0.0-20171017181929-23c074d0eceb 14 | github.com/hashicorp/hcl 15 | github.com/hashicorp/hcl/hcl/ast 16 | github.com/hashicorp/hcl/hcl/parser 17 | github.com/hashicorp/hcl/hcl/token 18 | github.com/hashicorp/hcl/json/parser 19 | github.com/hashicorp/hcl/hcl/scanner 20 | github.com/hashicorp/hcl/hcl/strconv 21 | github.com/hashicorp/hcl/json/scanner 22 | github.com/hashicorp/hcl/json/token 23 | # github.com/hashicorp/vault v0.9.3 24 | github.com/hashicorp/vault/api 25 | github.com/hashicorp/vault/helper/jsonutil 26 | github.com/hashicorp/vault/helper/parseutil 27 | github.com/hashicorp/vault/helper/compressutil 28 | # github.com/mitchellh/go-homedir v0.0.0-20161203194507-b8bc1bf76747 29 | github.com/mitchellh/go-homedir 30 | # github.com/mitchellh/mapstructure v0.0.0-20180111000720-b4575eea38cc 31 | github.com/mitchellh/mapstructure 32 | # github.com/sethgrid/pester v0.0.0-20171127025028-760f8913c048 33 | github.com/sethgrid/pester 34 | # golang.org/x/net v0.0.0-20180826012351-8a410e7b638d 35 | golang.org/x/net/http2 36 | golang.org/x/net/http/httpguts 37 | golang.org/x/net/http2/hpack 38 | golang.org/x/net/idna 39 | # golang.org/x/text v0.3.0 40 | golang.org/x/text/secure/bidirule 41 | golang.org/x/text/unicode/bidi 42 | golang.org/x/text/unicode/norm 43 | golang.org/x/text/transform 44 | --------------------------------------------------------------------------------