Skip to content

Commit 8a9b15a

Browse files
Merge pull request #1 from sourcepole/support-secret-vaults
Make `passLookup` more generic to allow using other command to get secrets
2 parents e291696 + 39e06fa commit 8a9b15a

5 files changed

Lines changed: 75 additions & 7 deletions

File tree

go.mod

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
module github.com/sourcepole/kontemplate
2+
3+
go 1.20
4+
5+
replace github.com/imdario/mergo => dario.cat/mergo v0.3.11
6+
7+
require (
8+
github.com/Masterminds/sprig v2.22.0+incompatible
9+
github.com/alecthomas/kingpin/v2 v2.3.2
10+
github.com/ghodss/yaml v1.0.0
11+
github.com/tazjin/kontemplate v1.8.0
12+
)
13+
14+
require (
15+
github.com/Masterminds/goutils v1.1.1 // indirect
16+
github.com/Masterminds/semver v1.5.0 // indirect
17+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 // indirect
18+
github.com/google/uuid v1.3.1 // indirect
19+
github.com/huandu/xstrings v1.4.0 // indirect
20+
github.com/imdario/mergo v0.0.0-00010101000000-000000000000 // indirect
21+
github.com/mitchellh/copystructure v1.2.0 // indirect
22+
github.com/mitchellh/reflectwalk v1.0.2 // indirect
23+
github.com/xhit/go-str2duration/v2 v2.1.0 // indirect
24+
golang.org/x/crypto v0.14.0 // indirect
25+
gopkg.in/yaml.v2 v2.3.0 // indirect
26+
)

go.sum

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
dario.cat/mergo v0.3.11 h1:6gDCVFOJzmrUnsglMtA+chGRmK8Q3gyBRNFtaObvjc4=
2+
dario.cat/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA=
3+
github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI=
4+
github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU=
5+
github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww=
6+
github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
7+
github.com/Masterminds/sprig v2.22.0+incompatible h1:z4yfnGrZ7netVz+0EDJ0Wi+5VZCSYp4Z0m2dk6cEM60=
8+
github.com/Masterminds/sprig v2.22.0+incompatible/go.mod h1:y6hNFY5UBTIWBxnzTeuNhlNS5hqE0NB0E6fgfo2Br3o=
9+
github.com/alecthomas/kingpin/v2 v2.3.2 h1:H0aULhgmSzN8xQ3nX1uxtdlTHYoPLu5AhHxWrKI6ocU=
10+
github.com/alecthomas/kingpin/v2 v2.3.2/go.mod h1:0gyi0zQnjuFk8xrkNKamJoyUo382HRL7ATRpFZCw6tE=
11+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137 h1:s6gZFSlWYmbqAuRjVTiNNhvNRfY2Wxp9nhfyel4rklc=
12+
github.com/alecthomas/units v0.0.0-20211218093645-b94a6e3cc137/go.mod h1:OMCwj8VM1Kc9e19TLln2VL61YJF0x1XFtfdL4JdbSyE=
13+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
14+
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
15+
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
16+
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
17+
github.com/google/uuid v1.3.1 h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
18+
github.com/google/uuid v1.3.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
19+
github.com/huandu/xstrings v1.4.0 h1:D17IlohoQq4UcpqD7fDk80P7l+lwAmlFaBHgOipl2FU=
20+
github.com/huandu/xstrings v1.4.0/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
21+
github.com/mitchellh/copystructure v1.2.0 h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
22+
github.com/mitchellh/copystructure v1.2.0/go.mod h1:qLl+cE2AmVv+CoeAwDPye/v+N2HKCj9FbZEVFJRxO9s=
23+
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
24+
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
25+
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
26+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
27+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
28+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
29+
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
30+
github.com/tazjin/kontemplate v1.8.0 h1:JAMdWuNDiaeKusvOLE5NHIO4ZL/CeMvwXkNw24AKF/s=
31+
github.com/tazjin/kontemplate v1.8.0/go.mod h1:DEOFvhww39A4SLkfzdrqP6PH9uKeSvsQhHmIZMbUIUA=
32+
github.com/xhit/go-str2duration/v2 v2.1.0 h1:lxklc02Drh6ynqX+DdPyp5pCKLUQpRT8bp8Ydu2Bstc=
33+
github.com/xhit/go-str2duration/v2 v2.1.0/go.mod h1:ohY8p+0f07DiV6Em5LKB0s2YpLtXVyJfNt1+BlmyAsU=
34+
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
35+
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
36+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
37+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
38+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
39+
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
40+
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
41+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ import (
2222
"strings"
2323

2424
"github.com/tazjin/kontemplate/context"
25-
"github.com/tazjin/kontemplate/templater"
26-
"gopkg.in/alecthomas/kingpin.v2"
25+
"github.com/sourcepole/kontemplate/templater"
26+
"github.com/alecthomas/kingpin/v2"
2727
)
2828

2929
const version string = "1.8.0"

templater/pass.go renamed to templater/password_from_external_command.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919
"strings"
2020
)
2121

22-
func GetFromPass(key string) (string, error) {
23-
fmt.Fprintf(os.Stderr, "Attempting to look up %s in pass\n", key)
24-
pass := exec.Command("pass", "show", key)
22+
func GetPasswordFromExternalCommand(command string) (string, error) {
23+
fmt.Fprintf(os.Stderr, "Attempting to look up secret with %s\n", command)
24+
_command := strings.Split(command, " ")
25+
result := exec.Command(_command[0], _command[1:]...)
2526

26-
output, err := pass.CombinedOutput()
27+
output, err := result.CombinedOutput()
2728
if err != nil {
2829
return "", fmt.Errorf("Pass lookup failed: %s (%v)", output, err)
2930
}

templater/templater.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func templateFuncs(c *context.Context, rs *context.ResourceSet) template.FuncMap
186186
b, _ := json.Marshal(data)
187187
return string(b)
188188
}
189-
m["passLookup"] = GetFromPass
189+
m["GetPasswordFromExternalCommand"] = GetPasswordFromExternalCommand
190190
m["gitHEAD"] = func() (string, error) {
191191
out, err := exec.Command("git", "-C", c.BaseDir, "rev-parse", "HEAD").Output()
192192
if err != nil {

0 commit comments

Comments
 (0)