diff options
author | mjarkk <mkopenga@gmail.com> | 2018-10-27 14:56:15 +0200 |
---|---|---|
committer | mjarkk <mkopenga@gmail.com> | 2018-10-27 14:56:15 +0200 |
commit | 87d1b9a5470b3cdd6095714cceec39dcd7fd2093 (patch) | |
tree | 7dec3db45b92f101f7ff93ac7f964781f3b6f02e /vendor | |
parent | 959d6fa2cae500d86199be2d5f9da9b64c272bff (diff) |
Fixed circleci build
Diffstat (limited to 'vendor')
50 files changed, 2157 insertions, 0 deletions
diff --git a/vendor/github.com/ionrock/procs/Gopkg.toml b/vendor/github.com/ionrock/procs/Gopkg.toml new file mode 100644 index 000000000..2521101cd --- /dev/null +++ b/vendor/github.com/ionrock/procs/Gopkg.toml @@ -0,0 +1,30 @@ + +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" + + +[[constraint]] + branch = "master" + name = "github.com/apoydence/onpar" + +[[constraint]] + branch = "master" + name = "github.com/flynn/go-shlex" diff --git a/vendor/github.com/ionrock/procs/LICENSE.md b/vendor/github.com/ionrock/procs/LICENSE.md new file mode 100644 index 000000000..9fb415ad4 --- /dev/null +++ b/vendor/github.com/ionrock/procs/LICENSE.md @@ -0,0 +1,13 @@ +Copyright 2017 Eric Larson <eric@ionrock.org> + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/github.com/ionrock/procs/Makefile b/vendor/github.com/ionrock/procs/Makefile new file mode 100644 index 000000000..9e82d411d --- /dev/null +++ b/vendor/github.com/ionrock/procs/Makefile @@ -0,0 +1,32 @@ +SOURCEDIR=. +SOURCES := $(shell find $(SOURCEDIR) -name '*.go') + +test: dep + dep ensure + go test . + +race: dep + dep ensure + go test -race . + + +dep: +ifeq (, $(shell which dep)) + go get -u github.com/golang/dep/cmd/dep +endif + +all: prelog cmdtmpl procmon + +prelog: $(SOURCES) + go build ./cmd/prelog + +cmdtmpl: $(SOURCES) + go build ./cmd/cmdtmpl + +procmon: $(SOURCES) + go build ./cmd/procmon + +clean: + rm -f prelog + rm -f cmdtmpl + rm -f procmon diff --git a/vendor/github.com/ionrock/procs/README.md b/vendor/github.com/ionrock/procs/README.md new file mode 100644 index 000000000..0efd1252b --- /dev/null +++ b/vendor/github.com/ionrock/procs/README.md @@ -0,0 +1,168 @@ +# Procs + +[![](https://travis-ci.org/ionrock/procs.svg?branch=master)](https://travis-ci.org/ionrock/procs) +[![Go Report Card](https://goreportcard.com/badge/github.com/ionrock/procs)](https://goreportcard.com/report/github.com/ionrock/procs) +[![GoDoc](https://godoc.org/github.com/ionrock/procs?status.svg)](https://godoc.org/github.com/ionrock/procs) + +Procs is a library to make working with command line applications a +little nicer. + +The primary use case is when you have to use a command line client in +place of an API. Often times you want to do things like output stdout +within your own logs or ensure that every time the command is called, +there are a standard set of flags that are used. + +## Basic Usage + +The majority of this functionality is intended to be included the +procs.Process. + +### Defining a Command + +A command can be defined by a string rather than a []string. Normally, +this also implies that the library will run the command in a shell, +exposing a potential man in the middle attack. Rather than using a +shell, procs [lexically +parses](https://github.com/flynn-archive/go-shlex) the command for the +different arguments. It also allows for pipes in order to string +commands together. + +```go +p := procs.NewProcess("kubectl get events | grep dev") +``` + +You can also define a new `Process` by passing in predefined commands. + +```go +cmds := []*exec.Cmd{ + exec.Command("kubectl", "get", "events"), + exec.Command("grep", "dev"), +} + +p := procs.Process{Cmds: cmds} +``` + +### Output Handling + +One use case that is cumbersome is using the piped output from a +command. For example, lets say we wanted to start a couple commands +and have each command have its own prefix in stdout, while still +capturing the output of the command as-is. + +```go +p := procs.NewProcess("cmd1") +p.OutputHandler = func(line string) string { + fmt.Printf("cmd1 | %s\n") + return line +} +out, _ := p.Run() +fmt.Println(out) +``` + +Whatever is returned from the `OutputHandler` will be in the buffered +output. In this way you can choose to filter or skip output buffering +completely. + +You can also define a `ErrHandler` using the same signature to get the +same filtering for stderr. + +### Environment Variables + +Rather than use the `exec.Cmd` `[]string` environment variables, a +`procs.Process` uses a `map[string]string` for environment variables. + +```go +p := procs.NewProcess("echo $FOO") +p.Env = map[string]string{"FOO": "foo"} +``` + +Also, environment variables defined by the `Process.Env` can be +expanded automatically using the `os.Expand` semantics and the +provided environment. + +There is a `ParseEnv` function that can help to merge the parent +processes' environment with any new values. + +```go +env := ParseEnv(os.Environ()) +env["USER"] = "foo" +``` + +Finally, if you are building commands manually, the `Env` function can +take a `map[string]string` and convert it to a `[]string` for use with +an `exec.Cmd`. The `Env` function also accepts a `useEnv` bool to help +include the parent process environment. + +```go +cmd := exec.Command("knife", "cookbook", "show", cb) +cmd.Env = Env(map[string]string{"USER": "knife-user"}, true) +``` + +## Example Applications + +Take a look in the [`cmd`](./cmd/) dir for some simple applications +that use the library. You can also `make all` to build them. The +examples below assume you've built them locally. + +### Prelog + +The `prelog` command allows running a command and prefixing the output +with a value. + +```bash +$ ./prelog -prefix foo -- echo 'hello world!' +Running the command +foo | hello world! +Accessing the output without a prefix. +hello world! +Running the command with Start / Wait +foo | hello world! +``` + +### Cmdtmpl + +The `cmdtmpl` command uses the `procs.Builder` to create a command +based on some paramters. It will take a `data.yml` file and +`template.yml` file to create a command. + +```bash +$ cat example/data.json +{ + "source": "https://my.example.org", + "user": "foo", + "model": "widget", + "action": "create", + "args": "-f new -i improved" +} +$ cat example/template.json +[ + "mysvc ${model} ${action} ${args}", + "--endpoint ${source}", + "--username ${user}" +] +$ ./cmdtmpl -data example/data.json -template example/template.json +Command: mysvc foo widget create -f new -i imporoved --endpoint https://my.example.org --username foo +$ ./cmdtmpl -data example/data.json -template example/template.json -field user=bar +Command: mysvc foo widget create -f new -i imporoved --endpoint https://my.example.org --username bar +``` + +### Procmon + +The `procmon` command acts like +[foreman](https://github.com/ddollar/foreman) with the difference +being it uses a JSON file with key value pairs instead of a +Procfile. This example uses the `procs.Manager` to manage a set of +`procs.Processes`. + +```bash +$ cat example/procfile.json +{ + "web": "python -m SimpleHTTPServer" +} +$ ./procmon -procfile example/procfile.json +web | Starting web with python -m SimpleHTTPServer +``` + +You can then access http://localhost:8000 to see the logs. You can +also kill the child process and see `procmon` recognizing it has +exited and exit itself. diff --git a/vendor/github.com/ionrock/procs/builder.go b/vendor/github.com/ionrock/procs/builder.go new file mode 100644 index 000000000..85c68391c --- /dev/null +++ b/vendor/github.com/ionrock/procs/builder.go @@ -0,0 +1,58 @@ +package procs + +import ( + "os" + "strings" +) + +// Builder helps construct commands using templates. +type Builder struct { + Context map[string]string + Templates []string +} + +func (b *Builder) getConfig(ctx map[string]string) func(string) string { + return func(key string) string { + if v, ok := ctx[key]; ok { + return v + } + return "" + } +} + +func (b *Builder) expand(v string, ctx map[string]string) string { + return os.Expand(v, b.getConfig(ctx)) +} + +// Command returns the result of the templates as a single string. +func (b *Builder) Command() string { + parts := []string{} + for _, t := range b.Templates { + parts = append(parts, b.expand(t, b.Context)) + } + + return strings.Join(parts, " ") +} + +// CommandContext returns the result of the templates as a single +// string, but allows providing an environment context as a +// map[string]string for expansions. +func (b *Builder) CommandContext(ctx map[string]string) string { + // Build our environment context by starting with our Builder + // context and overlay the passed in context map. + env := make(map[string]string) + for k, v := range b.Context { + env[k] = b.expand(v, b.Context) + } + + for k, v := range ctx { + env[k] = b.expand(v, env) + } + + parts := []string{} + for _, t := range b.Templates { + parts = append(parts, b.expand(t, env)) + } + + return strings.Join(parts, " ") +} diff --git a/vendor/github.com/ionrock/procs/builder_test.go b/vendor/github.com/ionrock/procs/builder_test.go new file mode 100644 index 000000000..a093eeb09 --- /dev/null +++ b/vendor/github.com/ionrock/procs/builder_test.go @@ -0,0 +1,58 @@ +package procs_test + +import ( + "testing" + + "github.com/ionrock/procs" +) + +func TestCommandContext(t *testing.T) { + b := &procs.Builder{ + Context: map[string]string{ + "options": "-Fj -s https://example.com/chef -k knife.pem", + }, + + Templates: []string{ + "knife", + "${model} ${action}", + "${args}", + "${options}", + }, + } + + cmd := b.CommandContext(map[string]string{ + "model": "data bag", + "action": "from file", + "args": "foo data_bags/foo/bar.json", + }) + + expected := "knife data bag from file foo data_bags/foo/bar.json -Fj -s https://example.com/chef -k knife.pem" + if cmd != expected { + t.Fatalf("failed building command: %q != %q", cmd, expected) + } +} + +func TestCommand(t *testing.T) { + b := &procs.Builder{ + Context: map[string]string{ + "options": "-Fj -s https://example.com/chef -k knife.pem", + "model": "data bag", + "action": "from file", + "args": "foo data_bags/foo/bar.json", + }, + + Templates: []string{ + "knife", + "${model} ${action}", + "${args}", + "${options}", + }, + } + + cmd := b.CommandContext(map[string]string{}) + + expected := "knife data bag from file foo data_bags/foo/bar.json -Fj -s https://example.com/chef -k knife.pem" + if cmd != expected { + t.Fatalf("failed building command: %q != %q", cmd, expected) + } +} diff --git a/vendor/github.com/ionrock/procs/env.go b/vendor/github.com/ionrock/procs/env.go new file mode 100644 index 000000000..3cf93f76d --- /dev/null +++ b/vendor/github.com/ionrock/procs/env.go @@ -0,0 +1,48 @@ +package procs + +import ( + "fmt" + "os" + "strings" +) + +// ParseEnv takes an environment []string and converts it to a map[string]string. +func ParseEnv(environ []string) map[string]string { + env := make(map[string]string) + for _, e := range environ { + pair := strings.SplitN(e, "=", 2) + + // There is a chance we can get an env with empty values + if len(pair) == 2 { + env[pair[0]] = pair[1] + } + } + return env +} + +// Env takes a map[string]string and converts it to a []string that +// can be used with exec.Cmd. The useEnv boolean flag will include the +// current process environment, overlaying the provided env +// map[string]string. +func Env(env map[string]string, useEnv bool) []string { + envlist := []string{} + + // update our env by loading our env and overriding any values in + // the provided env. + if useEnv { + environ := ParseEnv(os.Environ()) + for k, v := range env { + environ[k] = v + } + env = environ + } + + for key, val := range env { + if key == "" { + continue + } + envlist = append(envlist, fmt.Sprintf("%s=%s", key, val)) + } + + return envlist +} diff --git a/vendor/github.com/ionrock/procs/env_test.go b/vendor/github.com/ionrock/procs/env_test.go new file mode 100644 index 000000000..1b2a0498b --- /dev/null +++ b/vendor/github.com/ionrock/procs/env_test.go @@ -0,0 +1,83 @@ +package procs_test + +import ( + "fmt" + "os" + "os/exec" + "strings" + "testing" + + "github.com/ionrock/procs" +) + +func TestParseEnv(t *testing.T) { + env := []string{ + "FOO=bar", + "BAZ=`echo 'hello=world'`", + } + + m := procs.ParseEnv(env) + + v, ok := m["FOO"] + if !ok { + t.Errorf("error missing FOO from env: %#v", m) + } + + if v != "bar" { + t.Errorf("error FOO != bar: %s", v) + } + + v, ok = m["BAZ"] + + if !ok { + t.Errorf("error missing BAZ from env: %#v", m) + } + + expectBaz := "`echo 'hello=world'`" + if v != expectBaz { + t.Errorf("error BAZ != %s: %s", expectBaz, v) + } +} + +func TestEnvBuilder(t *testing.T) { + env := procs.Env(map[string]string{ + "FOO": "bar", + "BAZ": "hello world", + }, false) + + if len(env) != 2 { + t.Errorf("error loading env: %s", env) + } +} + +func helperEnvCommand(env map[string]string) *exec.Cmd { + cmd := exec.Command(os.Args[0], "-test.run=TestEnvBuilderOverrides") + cmd.Env = procs.Env(env, false) + return cmd +} + +func TestEnvBuilderOverrides(t *testing.T) { + if os.Getenv("GO_WANT_HELPER_PROCESS") != "1" { + return + } + for _, envvar := range procs.Env(map[string]string{"FOO": "override"}, true) { + fmt.Println(envvar) + } +} + +func TestEnvBuilderWithEnv(t *testing.T) { + cmd := helperEnvCommand(map[string]string{ + "GO_WANT_HELPER_PROCESS": "1", + "FOO": "default", + }) + out, err := cmd.Output() + if err != nil { + t.Fatalf("error running helper: %s", err) + } + + env := procs.ParseEnv(strings.Split(string(out), "\n")) + + if env["FOO"] != "override" { + t.Errorf("error overriding envvar: %s", string(out)) + } +} diff --git a/vendor/github.com/ionrock/procs/example_basic_test.go b/vendor/github.com/ionrock/procs/example_basic_test.go new file mode 100644 index 000000000..8d2adaf06 --- /dev/null +++ b/vendor/github.com/ionrock/procs/example_basic_test.go @@ -0,0 +1,33 @@ +package procs_test + +import ( + "fmt" + + "github.com/ionrock/procs" +) + +func Example() { + + b := procs.Builder{ + Context: map[string]string{ + "NAME": "eric", + }, + Templates: []string{ + "echo $NAME |", + "grep $NAME", + }, + } + + cmd := b.Command() + + fmt.Println(cmd) + + p := procs.NewProcess(cmd) + + p.Run() + out, _ := p.Output() + fmt.Println(string(out)) + // Output: + // echo eric | grep eric + // eric +} diff --git a/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go b/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go new file mode 100644 index 000000000..3dfd64015 --- /dev/null +++ b/vendor/github.com/ionrock/procs/example_predefined_cmds_test.go @@ -0,0 +1,23 @@ +package procs_test + +import ( + "fmt" + "os/exec" + + "github.com/ionrock/procs" +) + +func Example_predefinedCmds() { + p := procs.Process{ + Cmds: []*exec.Cmd{ + exec.Command("echo", "foo"), + exec.Command("grep", "foo"), + }, + } + + p.Run() + out, _ := p.Output() + fmt.Println(string(out)) + // Output: + // foo +} diff --git a/vendor/github.com/ionrock/procs/examples_test.go b/vendor/github.com/ionrock/procs/examples_test.go new file mode 100644 index 000000000..c9b43cc1c --- /dev/null +++ b/vendor/github.com/ionrock/procs/examples_test.go @@ -0,0 +1,43 @@ +package procs_test + +import ( + "fmt" + + "github.com/ionrock/procs" +) + |