feat: add Go template support for secret data rendering#256
Open
christian-deleon wants to merge 6 commits into1Password:mainfrom
Open
feat: add Go template support for secret data rendering#256christian-deleon wants to merge 6 commits into1Password:mainfrom
christian-deleon wants to merge 6 commits into1Password:mainfrom
Conversation
Add ID, SectionID, and FieldType fields to ItemField. Add ItemSection struct and Sections slice to Item. Enrich FromConnectItem and FromSDKItem to populate section metadata from the respective SDK types. This metadata is needed to support Go template rendering where users can reference fields by section (e.g. .Sections.Database.username).
Add SecretTemplate struct with a Data map[string]string field and an optional Template pointer on OnePasswordItemSpec. Regenerate deepcopy methods and CRD manifests. This allows users to define Go template strings per secret key in their OnePasswordItem resources.
Add pkg/template with BuildTemplateContext and ProcessTemplate functions. BuildTemplateContext constructs a TemplateContext from a model.Item with three access patterns: .Fields (flat by label), .Sections (nested by section title), and .FieldsByID (by unique field ID). ProcessTemplate parses and executes a Go template string against the context, returning the rendered bytes.
…lers Update BuildKubernetesSecretData to accept a model.Item and optional SecretTemplate instead of decomposed fields/urls/files. When a template is provided, render each key through the Go template engine and return only the templated keys. Fall back to default field/URL/file mapping when no template is set. Thread the SecretTemplate parameter through CreateKubernetesSecretFromItem and BuildKubernetesSecretFromOnePasswordItem. The OnePasswordItem controller extracts the template from the resource spec; the deployment controller and secret update handler pass nil (no template support for annotation-based secrets). Update all existing test call sites and add template-specific unit tests covering multi-key templates, section access, hyphenated keys via index, invalid template handling, nil template fallback, and end-to-end secret creation. Add integration tests for template rendering in the controller test suite.
Document the template feature in USAGEGUIDE.md including basic usage, multiple keys, template context reference (.Fields, .Sections, .FieldsByID, index for special characters), and behaviour notes.
7 tasks
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
✨ Summary
Adds Go template support to
OnePasswordItem, allowing users to define custom secret data keys using Go templates rendered against the 1Password item's fields, sections, and metadata.Motivation: The current 1:1 field-to-key mapping is limiting for use cases that require combining fields, reformatting values, or constructing connection strings (e.g. DSNs, URIs). This feature lets users express those transformations declaratively in the CRD spec.
Example:
What's included:
SecretTemplatetype added toOnePasswordItemSpecwithtemplate.datamappkg/template/) withBuildTemplateContextandProcessTemplate.Fields(flat),.Sections(nested by section label), and.FieldsByIDpkg/onepassword/model/(ID, SectionID, FieldType)BuildKubernetesSecretDataas priority 2 (after imagePullSecret, before default)🔗 Resolves:
N/A — new feature
✅ Checklist
pkg/template/template_test.go), model metadata tests🕵️ Review Notes &⚠️ Risks
BuildKubernetesSecretData: Template rendering is priority 2. If a template is defined, it completely replaces the default field/URL/file mapping. This is intentional — templates give full control over output.templatefield is optional. ExistingOnePasswordItemresources withouttemplatebehave identically to before.OnePasswordItemCR to retrieve template config when re-rendering secrets during polling, instead of passingnil./ok-to-test.