Skip to content

Commit

Permalink
Merge pull request #35 from avenga/fix-env-var
Browse files Browse the repository at this point in the history
Fix env var mapping
  • Loading branch information
Alex Schneider authored Oct 5, 2020
2 parents aa46312 + cc30604 commit 41a113a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions eval/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"net/http"
"net/url"
"os"
"sort"
"strconv"

"github.com/hashicorp/hcl/v2"
Expand Down Expand Up @@ -210,14 +209,23 @@ func decodeEnvironmentRefs(src []byte) []string {
needle := []byte("env")
var keys []string
for i, token := range tokens {
if token.Type == hclsyntax.TokenIdent &&
bytes.Equal(token.Bytes, needle) &&
i+2 < len(tokens) {
value := string(tokens[i+2].Bytes)
if sort.SearchStrings(keys, value) == len(keys) {
if token.Type == hclsyntax.TokenDot && i > 0 &&
bytes.Equal(tokens[i-1].Bytes, needle) &&
i+1 < len(tokens) {
value := string(tokens[i+1].Bytes)
if !hasValue(keys, value) {
keys = append(keys, value)
}
}
}
return keys
}

func hasValue(list []string, needle string) bool {
for _, s := range list {
if s == needle {
return true
}
}
return false
}

0 comments on commit 41a113a

Please sign in to comment.