Skip to content

Commit

Permalink
Merge pull request #1 from vkruoso/binary-secret
Browse files Browse the repository at this point in the history
add support for binary secret
  • Loading branch information
Ulexus authored Nov 8, 2020
2 parents 0fb3d37 + fcd48c1 commit 4724f13
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,40 @@ func (e *Engine) Secret(name string, namespace string, key string) (out string,
return
}

// SecretBinary returns a kubernetes Secret
func (e *Engine) SecretBinary(name string, namespace string, key string) (out []byte, err error) {
s := new(v1.Secret)

if err = e.connectKube(); err != nil {
return
}

namespace, err = getNamespace(namespace)
if err != nil {
return
}

ctx, cancel := boundedContext()
defer cancel()

if err = e.kc.Get(ctx, namespace, name, s); err != nil {
return
}

v, ok := s.GetData()[key]
if !ok {
return nil, fmt.Errorf("key %s not found in Secret %s[%s]", key, name, namespace)
}
out = v

if e.firstRenderCompleted {
return
}

err = e.AddWatched(context.Background(), "Secret", namespace, name)
return
}

// Env returns the value of an environment variable
func (e *Engine) Env(name string) string {
return os.Getenv(name)
Expand Down

0 comments on commit 4724f13

Please sign in to comment.