hieraeyaml

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: BSD-3-Clause Imports: 7 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.

Documentation

Overview

Package hieraeyaml is a pure-Go (no cgo) adapter mirroring the Ruby hiera-eyaml gem: it reads eyaml YAML data, decrypts the ENC[...] scalars it contains, and exposes an "eyaml" data_hash backend for the github.com/go-hiera/hiera engine.

The cryptography lives entirely in github.com/go-eyaml/eyaml; this package is the thin, hiera-facing layer on top of it:

  • a Config/New pair that builds a Backend from PEM key material, supplied either inline (PublicKeyPEM/PrivateKeyPEM) or by path through an injectable FS seam (PublicKeyPath/PrivateKeyPath) so callers and tests never need real files;
  • Backend.EncryptString / Backend.DecryptString for single scalars, and Backend.DecryptValue to walk a decoded value tree decrypting every ENC[...] token it finds (block and inline string forms alike);
  • Backend.DataHash, a func(data []byte, path string) (map[string]any, error) that YAML-parses a data file and decrypts it, matching the signature go-hiera's Hiera.RegisterDataHash expects;
  • Backend.Register, which registers DataHash under the name "eyaml" on a *hiera.Hiera so a hierarchy level can select "data_hash: eyaml".

Only the pkcs7 scheme is supported, inherited from go-eyaml; the hiera-eyaml gpg encryptor is deferred there and therefore here too.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend decrypts and encrypts eyaml data. Construct one with New.

func New

func New(cfg Config) (*Backend, error)

New builds a Backend from cfg. It errors if a configured path cannot be read, if the PEM material is invalid, or if no key material is supplied at all.

func (*Backend) DataHash

func (b *Backend) DataHash(data []byte, path string) (map[string]any, error)

DataHash is the go-hiera data_hash backend seam: it YAML-parses data and decrypts every ENC[...] scalar, returning the resulting hash. path is used only for error context. Its signature matches the argument gohiera.Hiera.RegisterDataHash expects.

func (*Backend) DecryptString

func (b *Backend) DecryptString(s string) (string, error)

DecryptString decrypts s when it is an ENC[...] token and returns it verbatim otherwise, so plaintext scalars pass through unchanged.

func (*Backend) DecryptValue

func (b *Backend) DecryptValue(v any) (any, error)

DecryptValue walks a decoded value tree (as produced by YAML parsing) and decrypts every ENC[...] scalar, leaving other scalars untouched. Maps and slices are copied; the input is not mutated.

func (*Backend) EncryptString

func (b *Backend) EncryptString(s string) (string, error)

EncryptString seals s into an ENC[PKCS7,...] token.

func (*Backend) Register

func (b *Backend) Register(h *gohiera.Hiera)

Register installs Backend.DataHash as the "eyaml" data_hash backend on h, so a hierarchy level may select it with "data_hash: eyaml".

type Config

type Config struct {
	// PublicKeyPEM / PrivateKeyPEM are inline PEM blocks.
	PublicKeyPEM  []byte
	PrivateKeyPEM []byte
	// PublicKeyPath / PrivateKeyPath are read through FS when the matching
	// inline field is empty.
	PublicKeyPath  string
	PrivateKeyPath string
	// FS overrides the file-access seam (defaults to the OS filesystem).
	FS FS
}

Config configures a Backend. Key material is the RSA private key and the matching X.509 certificate (hiera-eyaml's "public key"). Supply either the inline PEM fields or the *Path fields; inline PEM wins when both are set. Provide only the certificate for an encrypt-only backend, only the private key for a decrypt-only backend, or both for round trips.

type FS

type FS interface {
	ReadFile(name string) ([]byte, error)
}

FS is the file-access seam New uses to read PEM material from a path. The default is the operating-system filesystem; tests supply an in-memory implementation so they need no disk.

Jump to

Keyboard shortcuts

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