Skip to content

Commit

Permalink
Use double slash for relative and tripple slash for absolute path (#48)
Browse files Browse the repository at this point in the history
* Use double slash for relative and tripple slash for absolute path

* Document relative vs absolute path
  • Loading branch information
dex4er authored May 2, 2021
1 parent 96c619b commit e390ce8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ Examples:

### Terraform (tfstate)

- `ref+tfstate://path/to/some.tfstate/RESOURCE_NAME`
- `ref+tfstate://relative/path/to/some.tfstate/RESOURCE_NAME`
- `ref+tfstate:///absolute/path/to/some.tfstate/RESOURCE_NAME`

Examples:

Expand Down Expand Up @@ -362,11 +363,13 @@ Examples:

File provider reads a local text file, or the value for the specific path in a YAML/JSON file.

- `ref+file://path/to/file[#/path/to/the/value]`
- `ref+file://relative/path/to/file[#/path/to/the/value]`
- `ref+file:///absolute/path/to/file[#/path/to/the/value]`

Examples:

- `ref+file://foo/bar` loads the file at `foo/bar`
- `ref+file:///home/foo/bar` loads the file at `/home/foo/bar`
- `ref+file://some.yaml#/foo/bar` loads the YAML file at `some.yaml` and reads the value for the path `$.foo.bar`.
Let's say `some.yaml` contains `{"foo":{"bar":"BAR"}}`, `key1: ref+file://some.yaml#/foo/bar` results in `key1: BAR`.

Expand Down
12 changes: 8 additions & 4 deletions vals.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"crypto/md5"
"errors"
"fmt"
"github.com/variantdev/vals/pkg/config"
"github.com/variantdev/vals/pkg/providers/s3"
"net/url"
"os"
"os/exec"
"strings"

"github.com/variantdev/vals/pkg/config"
"github.com/variantdev/vals/pkg/providers/s3"

lru "github.com/hashicorp/golang-lru"
"github.com/variantdev/vals/pkg/api"
"github.com/variantdev/vals/pkg/expansion"
Expand Down Expand Up @@ -209,9 +210,10 @@ func (r *Runtime) Eval(template map[string]interface{}) (map[string]interface{},
frag = strings.TrimPrefix(frag, "/")

var components []string
var host string

{
host := uri.Host
host = uri.Host

if host != "" {
components = append(components, host)
Expand All @@ -221,7 +223,9 @@ func (r *Runtime) Eval(template map[string]interface{}) (map[string]interface{},
{
path2 := uri.Path
path2 = strings.TrimPrefix(path2, "#")
path2 = strings.TrimPrefix(path2, "/")
if host != "" {
path2 = strings.TrimPrefix(path2, "/")
}

if path2 != "" {
components = append(components, path2)
Expand Down

0 comments on commit e390ce8

Please sign in to comment.