secretmapping

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: 3 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

tundra-secret-mapping

A typed JSON-secret field-mapping with per-secret overrides — project a JSON secret onto canonical credential fields, once, for the whole fleet.

What

A Mapping declares which JSON keys of a secret supply the canonical credential Fields (username, password, private_key, passphrase, …). A Default field map applies to every secret; per-secret-path Overrides shadow the default per-field. Apply(path, secretJSON) returns the projected map[Field]string. It is a pure, generic field-mapping primitive: it models any JSON secret and names no particular project — the concrete mapping values a deployment uses are its own data.

Why

Integration adapters (ServiceNow, ESO, UI rotators) each otherwise fork the same "pull username/password/key out of this secret JSON" logic in a different language. tundra-secret-mapping is the one shared, typed mapping so every adapter projects secrets the same way, with per-secret overrides for the inevitable odd-shaped secret.

Install

go get github.com/pleme-io/tundra-secret-mapping

Nix (via substrate):

outputs = { self, nixpkgs, substrate, ... }:
  (import substrate.goLibraryFlakeBuilder { inherit nixpkgs; }) {
    name = "tundra-secret-mapping"; version = "0.1.0"; src = self;
  };

Usage

Built on: errors-go (typed, code-carrying errors).

m := secretmapping.New(
    secretmapping.WithDefault(secretmapping.FieldMap{
        secretmapping.Username: "user",
        secretmapping.Password: "pass",
    }),
    secretmapping.WithOverride("/ssh/host", secretmapping.FieldMap{
        secretmapping.Username:   "login",
        secretmapping.PrivateKey: "key",
    }),
)

creds, err := m.Apply("/ssh/host", secretJSON)
if err != nil { return errs.Exit(err) }
// creds[secretmapping.Username], creds[secretmapping.PrivateKey], …

Configuration

The Mapping is itself the configuration shape — a consumer loads its Default/Overrides from a configured source via shikumi-go and constructs the Mapping from the loaded typed values. The library performs no config loading of its own.

Release

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

Documentation

Overview

Package secretmapping is the fleet's one typed JSON-secret field-mapping — so no integration adapter (ServiceNow, ESO, a UI rotator) forks its own "pull these fields out of the secret JSON" logic. A Mapping declares which JSON keys of a secret map to canonical credential fields (username, password, private key, passphrase, …), with per-secret-path overrides.

It is a pure, generic field-mapping primitive: it models any JSON secret and names no particular project. The mapping itself is the public shape; the concrete per-secret mapping values a deployment uses are its own data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field string

Field is a canonical credential field name an integration consumes. New fields are additive.

const (
	Username   Field = "username"
	Password   Field = "password"
	PrivateKey Field = "private_key"
	Passphrase Field = "passphrase"
)

Canonical credential fields.

type FieldMap

type FieldMap map[Field]string

FieldMap maps a canonical Field to the JSON key in the secret that supplies it. E.g. {Username: "user", Password: "pass"} reads secret["user"] into the canonical "username" slot.

type Mapping

type Mapping struct {
	// Default maps canonical fields to JSON keys for all secrets.
	Default FieldMap
	// Overrides maps a secret path to a FieldMap that replaces the Default for
	// that path (per-field: an override entry shadows the default entry).
	Overrides map[string]FieldMap
}

Mapping is a typed JSON-secret field-mapping with per-secret overrides. The Default map applies to every secret; Overrides keyed by secret path replace the default for that path. The zero value (no default, no overrides) is valid but maps nothing; build it through New.

func New

func New(opts ...Option) *Mapping

New builds a Mapping from options.

func (*Mapping) Apply

func (m *Mapping) Apply(path string, secretJSON []byte) (map[Field]string, error)

Apply reads the raw JSON secret bytes and projects them onto the canonical fields, using the mapping for the given secret path. It returns a map keyed by canonical Field. A canonical field whose mapped JSON key is absent from the secret is omitted from the result (not an error) — so callers can detect missing optional fields.

func (*Mapping) Validate

func (m *Mapping) Validate() error

Validate reports the first structural problem with the mapping as a typed, code-carrying error. A valid mapping has non-empty JSON keys for every entry.

type Option

type Option func(*Mapping)

Option configures a Mapping.

func WithDefault

func WithDefault(fm FieldMap) Option

WithDefault sets the default field map.

func WithOverride

func WithOverride(path string, fm FieldMap) Option

WithOverride sets a per-secret-path override field map. Override entries shadow the corresponding default entries for that path.

Jump to

Keyboard shortcuts

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