Documentation
¶
Overview ¶
Package secretspec is a Go SDK for SecretSpec, a declarative secrets manager.
It is a thin client over the libsecretspec C ABI. Resolution (providers, chains, profiles, generation, as_path) happens entirely in the Rust core; this package marshals a JSON request to secretspec_resolve, parses the response envelope, and exposes it with the same vocabulary as the Rust derive crate.
Three build modes select the native resolver:
- default (no build tag): purego (dlopen, no cgo). The library is located via the SECRETSPEC_FFI_LIB environment variable, an embedded copy, or a Cargo target directory. This keeps `go get` toolchain-free.
- `-tags static`: cgo statically links libsecretspec.a, so the resolver is embedded in the Go binary (fully static on Linux/musl).
- `-tags pkgconfig` (0.19+): cgo links the installed static or shared library described by libsecretspec.pc. See README.
All bindings implement the same hooks (ensureLoaded, nativeResolve, nativeABIVersion); the code below is binding-agnostic.
Index ¶
- func ABIVersion() (string, error)
- type Builder
- func (b *Builder) Load() (*Resolved, error)
- func (b *Builder) Report() (*Report, error)
- func (b *Builder) WithCaller(caller CallerContext) *Builder
- func (b *Builder) WithInlineSpec(spec any, baseDir string) *Builder
- func (b *Builder) WithNoValues(v bool) *Builder
- func (b *Builder) WithPath(path string) *Builder
- func (b *Builder) WithProfile(p string) *Builder
- func (b *Builder) WithProvider(p string) *Builder
- func (b *Builder) WithReason(reason string) *Builder
- func (b *Builder) WithScope(scope string) *Builder
- type CallerContext
- type Error
- type MissingRequiredError
- type Report
- type Resolved
- type ResolvedSecret
- type SecretReport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ABIVersion ¶
ABIVersion returns the version reported by the native resolver.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder configures a resolution, mirroring the derive crate's SecretSpec::builder().
func (*Builder) Load ¶
Load resolves the secrets. It returns *MissingRequiredError if a required secret is missing, and *Error for any other failure.
func (*Builder) Report ¶
Report resolves the value-free report (the inventory/preflight view, the same one the CLI exposes as `check --json`). It never returns *MissingRequiredError: a missing required secret appears as a SecretReport with Status "missing_required". It returns *Error for a genuine failure.
func (*Builder) WithCaller ¶ added in v0.20.0
func (b *Builder) WithCaller(caller CallerContext) *Builder
func (*Builder) WithInlineSpec ¶ added in v0.20.0
WithInlineSpec resolves a strict, versioned inline declaration instead of a filesystem manifest. `spec` is serialized as the native inline-spec v1 document (project/profiles/secrets); `baseDir` resolves relative provider paths just like the directory of a manifest. Available since SecretSpec 0.20.
The native library must export `secretspec_call`. If it is older, Load and Report return a capability error rather than falling back to a manifest search.
func (*Builder) WithNoValues ¶
func (*Builder) WithProfile ¶
func (*Builder) WithProvider ¶
func (*Builder) WithReason ¶
type CallerContext ¶ added in v0.20.0
type CallerContext struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
Operation string `json:"operation,omitempty"`
Resource string `json:"resource,omitempty"`
}
CallerContext identifies the software integration invoking SecretSpec. It is caller-asserted audit metadata and never supplies an access reason. Available since SecretSpec 0.20.
type MissingRequiredError ¶
type MissingRequiredError struct {
Missing []string
}
MissingRequiredError reports required secrets that were not found anywhere.
func (*MissingRequiredError) Error ¶
func (e *MissingRequiredError) Error() string
type Report ¶
type Report struct {
Provider string
Profile string
// Scope is the selected manifest scope, or nil for a full-profile report (0.17+).
Scope *string
Secrets []SecretReport
}
Report is a value-free resolution snapshot: every declared secret and how it would resolve, never a value. Unlike Load, a missing required secret is reported as a SecretReport with Status "missing_required" rather than an error, so it describes a profile even when its secrets are not all available.
type Resolved ¶
type Resolved struct {
Provider string
Profile string
// Scope is the selected manifest scope, or nil for a full-profile resolve (0.17+).
Scope *string
Secrets map[string]ResolvedSecret
MissingOptional []string
}
Resolved is a successful resolution, mirroring the Rust Resolved wrapper.
func (*Resolved) Close ¶
Close removes the temp files backing any as_path secrets in this result. The resolver persists those files (mode 0400) so their paths stay valid after resolve returns; the caller owns their lifetime. Call it (e.g. `defer resolved.Close()`) when done so secret files do not accumulate in the temp dir. Non-as_path secrets and a no_values result hold no path and are skipped, and a file already gone is not an error.
func (*Resolved) Fields ¶
Fields returns a flat map of SECRET_NAME -> value (the file path for as_path). A secret with no usable value (e.g. under no_values) maps to a nil pointer, which marshals to JSON null, matching the null the Python, Ruby, and Node SDKs emit; the value is a non-nil pointer otherwise.
func (*Resolved) FieldsJSON ¶
FieldsJSON marshals Fields() to JSON (a `{SECRET_NAME: value-or-null}` object), the input for a quicktype-generated deserializer (e.g. UnmarshalSecretSpec). See `secretspec schema`.
type ResolvedSecret ¶
type ResolvedSecret struct {
Value *string
Path *string
AsPath bool
Source string
SourceProvider *string
}
ResolvedSecret is one resolved secret. Exactly one of Value / Path is set.
func (ResolvedSecret) Get ¶
func (s ResolvedSecret) Get() string
Get returns the usable string: the file path for as_path secrets, else the value. It is the empty string when no usable value is present; use Usable to distinguish an absent value from a genuinely empty one.
func (ResolvedSecret) Usable ¶
func (s ResolvedSecret) Usable() (string, bool)
Usable returns the secret's usable string and whether one is present: the file path for as_path secrets, otherwise the value. Both are absent when a value-less response (e.g. no_values) strips them, in which case ok is false. This is the null-aware accessor; the other SDKs express the same thing as a get() that returns null/None/nil.
type SecretReport ¶
type SecretReport struct {
Name string
Status string // "resolved" | "missing_required" | "missing_optional"
Required bool
SourceProvider *string
DefaultApplied bool
Generated bool
AsPath bool
}
SecretReport is the value-free resolution outcome for one declared secret: how it would resolve and from where, never the value itself.