secrettmpl

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2026 License: MIT Imports: 2 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

secrettmpl-go

The fleet's one path-placeholder templating engine — the angle-bracket <path:…> syntax with ignore-annotation semantics — so no tool hand-rolls its own placeholder scanner over secret-injection templates.

What

A template is arbitrary text with embedded placeholders:

<path:some/secret/path>

Render(template, resolver) walks the template left-to-right, replaces each placeholder with the value the Resolver returns for that path, and copies all other text verbatim. Two ignore-annotation forms suppress resolution so a literal <path:…> survives into the output:

  • inline: <ignore:path:some/path> renders the literal <path:some/path>
  • block: <ignore> … </ignore> emits its inner text verbatim (placeholders inside are left untouched; the ignore tags are stripped)

The scanner is a single, backtrack-free pass. Unterminated or malformed placeholders, an empty path, an unresolved path, and resolver failures each become a typed, code-carrying error via errors-go (secrettmpl_unterminated / secrettmpl_empty_path / secrettmpl_unresolved / secrettmpl_resolve / secrettmpl_nil_resolver).

Why

Path-placeholder substitution over secret-injection templates recurs across config rendering, env-file generation, and bundle producers. One typed engine means uniform placeholder syntax, uniform ignore/escape semantics, and one place that owns the scanner — never a hand-rolled strings.Replace loop that mishandles escaping or unterminated tags again.

Install

go get github.com/pleme-io/secrettmpl-go

Usage

out, err := secrettmpl.Render(
    "Authorization: Bearer <path:api/token>\n# docs: <ignore:path:api/token>",
    secrettmpl.ResolverFunc(func(p string) (string, error) {
        return store.Get(ctx, p) // any secret backend
    }),
)
if err != nil { return errs.Exit(err) }
// out: "Authorization: Bearer t-abc\n# docs: <path:api/token>"

// Static substitution (tests, fixed sets):
out, _ = secrettmpl.Render("pw=<path:db/pw>", secrettmpl.MapResolver{"db/pw": "x"})

Configuration

None — a pure library. The placeholder paths come from the template; the backend behind the Resolver is the caller's choice (a secret store, a config map, …) and is wired with shikumi-go upstream as needed.

Release

Pull-model (Go modules): an annotated vX.Y.Z tag is the release; pkg.go.dev indexes it. See the GSDS module delivery FSM.

Documentation

Overview

Package secrettmpl is the fleet's one path-placeholder templating engine — the angle-bracket <path:…> syntax with ignore-annotation semantics — so no tool hand-rolls its own placeholder scanner over secret-injection templates.

A template is arbitrary text with embedded placeholders of the form

<path:some/secret/path>

Render walks the template left-to-right and replaces each placeholder with the value returned by a Resolver for that path; all other text is copied verbatim. Two ignore-annotation forms suppress resolution so a literal "<path:…>" can survive into the output (for documentation, nested templates, or escaping):

  • inline: <ignore:path:some/path> → renders the literal "<path:some/path>"
  • block: <ignore> … </ignore> → every placeholder inside is left untouched (emitted verbatim, ignore tags stripped)

The scanner is a single pass with no backtracking; unterminated or malformed placeholders yield typed, code-carrying errors via errors-go. Pure stdlib + errors-go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Render

func Render(template string, resolver Resolver) (string, error)

Render expands every <path:…> placeholder in template using resolver, honoring inline <ignore:path:…> and block <ignore>…</ignore> annotations. It returns the fully substituted string, or a typed code-carrying error on a malformed placeholder ("secrettmpl_unterminated" / "secrettmpl_empty_path") or a resolver failure ("secrettmpl_resolve").

Types

type MapResolver

type MapResolver map[string]string

MapResolver is a Resolver backed by a static map, the convenience form for fixed substitution sets and tests. A path absent from the map resolves to an "secrettmpl_unresolved" error.

func (MapResolver) Resolve

func (m MapResolver) Resolve(path string) (string, error)

Resolve looks up path in the map.

type Resolver

type Resolver interface {
	Resolve(path string) (string, error)
}

Resolver maps a placeholder path to its value. Implementations resolve a path (e.g. a secret store key) to the string substituted into the output. Returning an error aborts the whole render with that error wrapped in a typed "secrettmpl_resolve" error identifying the offending path.

type ResolverFunc

type ResolverFunc func(path string) (string, error)

ResolverFunc adapts a plain function to the Resolver interface.

func (ResolverFunc) Resolve

func (f ResolverFunc) Resolve(path string) (string, error)

Resolve calls the underlying function.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址