Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for binary secret #1

Merged
merged 1 commit into from
Nov 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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