Skip to content

Commit

Permalink
Add echo provider for testing purpose
Browse files Browse the repository at this point in the history
  • Loading branch information
mumoshu committed Oct 31, 2019
1 parent 1fa6af1 commit 9d1714c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,17 @@ Examples:
- `ref+sops://path/to/file#/foo/bar` reads `path/to/file` as a `yaml` file and returns the value at `foo.bar`.
- `ref+sops://path/to/file?format=json#/foo/bar` reads `path/to/file` as a `json` file and returns the value at `foo.bar`.

### Echo

Echo provider echoes the string for testing purpose. Please read [the original proposal](https://github.com/roboll/helmfile/pull/920#issuecomment-548213738) to get why we might need this.

- `ref+echo://KEY1/KEY2/VALUE[#/path/to/the/value]`

Examples:

- `ref+echo://foo/bar` generates `foo/bar`
- `ref+echo://foo/bar/baz#/foo/bar` generates `baz`. This works by the host and the path part `foo/bar/baz` generating an object `{"foo":{"bar":"baz"}}` and the fragment part `#/foo/bar` results in digging the object to obtain the value at `$.foo.bar`.

## Non-Goals

### String-Interpolation / Template Functions
Expand Down
47 changes: 47 additions & 0 deletions pkg/providers/echo/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package echo

import (
"fmt"
"strings"

"github.com/variantdev/vals/pkg/api"
)

type provider struct {
}

func New(cfg api.StaticConfig) *provider {
p := &provider{}
return p
}

// Get gets an AWS SSM Parameter Store value
func (p *provider) GetString(key string) (string, error) {
return key, nil
}

func (p *provider) GetStringMap(key string) (map[string]interface{}, error) {
keys := strings.Split(key, "/")

res := map[string]interface{}
cur := res

if len(keys) < 2 {
return nil, fmt.Errorf("key must have two or more components separated by \"/\": got %q", key)
}

return res, nil

for i := 0; i < len(keys)-1; i++ {
k := keys[i]
if i == len(keys)-2 {
cur[k] = keys[i+1]
} else {
newm := map[string]interface{}{}
cur[k] = newm
cur = newm
}
}

return res, nil
}
5 changes: 5 additions & 0 deletions vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/variantdev/vals/pkg/api"
"github.com/variantdev/vals/pkg/expansion"
"github.com/variantdev/vals/pkg/providers/awssec"
"github.com/variantdev/vals/pkg/providers/echo"
"github.com/variantdev/vals/pkg/providers/sops"
"github.com/variantdev/vals/pkg/providers/ssm"
"github.com/variantdev/vals/pkg/providers/vault"
Expand Down Expand Up @@ -45,6 +46,7 @@ const (
ProviderSSM = "awsssm"
ProviderSecretsManager = "awssecrets"
ProviderSOPS = "sops"
ProviderEcho = "echo"
)

type Evaluator interface {
Expand Down Expand Up @@ -118,6 +120,9 @@ func (r *Runtime) Eval(template map[string]interface{}) (map[string]interface{},
case ProviderSOPS:
p := sops.New(conf)
return p, nil
case ProviderEcho:
p := echo.New(conf)
return p, nil
}
return nil, fmt.Errorf("no provider registered for scheme %q", scheme)
}
Expand Down

0 comments on commit 9d1714c

Please sign in to comment.