-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
leverage file temaplates with k8s-secret targets
- Loading branch information
Fürst Roman
committed
Feb 11, 2025
1 parent
d563d22
commit 2bd80fd
Showing
20 changed files
with
615 additions
and
204 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package filetemplates | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"text/template" | ||
) | ||
|
||
const SecretGroupPrefix = "conjur.org/conjur-secrets." | ||
const SecretGroupFileTemplatePrefix = "conjur.org/secret-file-template." | ||
|
||
// Secret describes how Conjur secrets are represented in the file-template-rendering context. | ||
type Secret struct { | ||
Alias string | ||
Value string | ||
} | ||
|
||
// templateData describes the form in which data is presented to file templates | ||
type TemplateData struct { | ||
SecretsArray []*Secret | ||
SecretsMap map[string]*Secret | ||
} | ||
|
||
func RenderFile(tpl *template.Template, tplData TemplateData) (*bytes.Buffer, error) { | ||
buf := &bytes.Buffer{} | ||
err := tpl.Execute(buf, tplData) | ||
return buf, err | ||
} | ||
|
||
func GetTemplate(name string, secretsMap map[string]*Secret) *template.Template { | ||
|
||
return template.New(name).Funcs(template.FuncMap{ | ||
// secret is a custom utility function for streamlined access to secret values. | ||
// It panics for secrets aliases not specified on the group. | ||
"secret": func(alias string) string { | ||
v, ok := secretsMap[alias] | ||
if ok { | ||
return v.Value | ||
} | ||
|
||
// Panic in a template function is captured as an error | ||
// when the template is executed. | ||
panic(fmt.Sprintf("secret alias %q not present in specified secrets for group", alias)) | ||
}, | ||
"b64enc": b64encTemplateFunc, | ||
"b64dec": b64decTemplateFunc, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
pkg/secrets/pushtofile/template_functions.go → ...rets/file_templates/template_functions.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package pushtofile | ||
package filetemplates | ||
|
||
import "encoding/base64" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.