config

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0, MIT Imports: 4 Imported by: 0

Documentation

Overview

Package config loads hilt service configuration from a config file, environment variables (HILT_ prefix), and built-in defaults.

Index

Constants

View Source
const (
	StorageTypeMemory   = "memory"
	StorageTypePostgres = "postgres"
)

Valid values for StorageConfig.Type.

View Source
const (
	VaultTypeMemory    = "memory"
	VaultTypeHashicorp = "hashicorp"
)

Valid values for VaultConfig.Type.

View Source
const (
	VaultAuthToken   = "token"
	VaultAuthAppRole = "approle"
)

Valid values for HashicorpConfig.AuthMethod.

Variables

This section is empty.

Functions

func BindEnvVars

func BindEnvVars(v *viper.Viper)

BindEnvVars sets up environment variable binding with the HILT_ prefix. Each known config key is bound explicitly so env vars resolve on Unmarshal even when no flag or config file provides the key (viper's AutomaticEnv alone does not populate nested keys during Unmarshal) — this is what lets the `hilt client` commands pick up e.g. HILT_IDENTITY_KEY_FILE.

func BindFlags

func BindFlags(v *viper.Viper, flags *pflag.FlagSet) error

BindFlags binds known server flags from the flag set to their config keys, so a flag set on the command line overrides env vars, the config file, and defaults. Flags that are absent from the set are skipped.

func SetDefaults

func SetDefaults(v *viper.Viper)

SetDefaults configures default values for viper.

Types

type AppRoleConfig

type AppRoleConfig struct {
	// RoleID is the AppRole role ID.
	RoleID string `mapstructure:"role_id"`
	// SecretID is the AppRole secret ID.
	SecretID string `mapstructure:"secret_id"`
	// Mount is the AppRole auth method mount path. Defaults to "approle".
	Mount string `mapstructure:"mount"`
}

AppRoleConfig holds HashiCorp Vault AppRole authentication credentials.

type AuthConfig

type AuthConfig struct {
	// PartnerKey is the pre-shared bearer token required on Tenant API requests.
	// CSV of keys is supported, e.g. "key1,key2".
	PartnerKey string `mapstructure:"partner_key"`
}

AuthConfig holds authentication settings for the Tenant API.

type Config

type Config struct {
	Identity IdentityConfig `mapstructure:"identity"`
	Server   ServerConfig   `mapstructure:"server"`
	Log      LogConfig      `mapstructure:"log"`
	Storage  StorageConfig  `mapstructure:"storage"`
	Vault    VaultConfig    `mapstructure:"vault"`
	PLC      PLCConfig      `mapstructure:"plc"`
	Auth     AuthConfig     `mapstructure:"auth"`
	Upload   UploadConfig   `mapstructure:"upload"`
}

Config holds the hilt service configuration.

func Load

func Load(configFile string, opts ...LoadOption) (*Config, error)

Load creates a viper instance and loads configuration from the given config file (if provided), environment variables, and defaults.

func LoadWithViper

func LoadWithViper(configFile string, opts ...LoadOption) (*Config, *viper.Viper, error)

LoadWithViper creates a viper instance and loads configuration, returning both the Config struct and the viper instance for flag binding.

type HashicorpConfig

type HashicorpConfig struct {
	// Address is the Vault server address, e.g. "http://127.0.0.1:8200".
	Address string `mapstructure:"address"`
	// Mount is the KV v2 secrets engine mount path. Defaults to "secret".
	Mount string `mapstructure:"mount"`
	// AuthMethod selects how to authenticate: "token" or "approle". Defaults to
	// "approle".
	AuthMethod string `mapstructure:"auth_method"`
	// Token is the Vault auth token (used when AuthMethod is "token").
	Token string `mapstructure:"token"`
	// AppRole holds the AppRole credentials (used when AuthMethod is "approle").
	AppRole AppRoleConfig `mapstructure:"approle"`
}

HashicorpConfig holds settings for the HashiCorp Vault backend.

type IdentityConfig

type IdentityConfig struct {
	// KeyFile is the path to a PEM-encoded Ed25519 private key. When empty, an
	// ephemeral key is generated at startup (its DID changes each restart).
	KeyFile string `mapstructure:"key_file"`
	// ServiceID is an optional did:web identity to wrap the key with, allowing
	// the service to accept UCANs addressed to the did:web (e.g.
	// "did:web:hilt.example.com"). When empty, the key's did:key is used.
	ServiceID string `mapstructure:"service_id"`
}

IdentityConfig holds the Hilt service identity used to sign and receive UCAN invocations on the UCAN RPC API.

type LoadOption

type LoadOption func(*viper.Viper) error

LoadOption customizes how configuration is loaded.

func WithFlagSet

func WithFlagSet(flags *pflag.FlagSet) LoadOption

WithFlagSet binds command-line flags (see BindFlags) to the config so they take precedence over env vars, the config file, and defaults.

type LogConfig

type LogConfig struct {
	Level string `mapstructure:"level"`
}

LogConfig holds logging settings.

type PLCConfig

type PLCConfig struct {
	// Directory is the did:plc directory endpoint used to resolve and publish
	// PLC operations, e.g. "https://plc.directory".
	Directory string `mapstructure:"directory"`
}

PLCConfig holds settings for the did:plc directory.

type PostgresConfig

type PostgresConfig struct {
	// DSN is a libpq-style connection string, e.g.
	// "postgres://user:pass@host:5432/db?sslmode=disable".
	DSN string `mapstructure:"dsn"`
	// MaxConns is the maximum number of connections the pool will hold.
	MaxConns int32 `mapstructure:"max_conns"`
	// MinConns is the minimum number of idle connections the pool maintains.
	MinConns int32 `mapstructure:"min_conns"`
	// SkipMigrations disables automatic goose migrations on startup.
	SkipMigrations bool `mapstructure:"skip_migrations"`
}

PostgresConfig holds PostgreSQL settings.

type ServerConfig

type ServerConfig struct {
	Host string `mapstructure:"host"`
	Port int    `mapstructure:"port"`
	// InsecureDIDResolution resolves did:web DIDs over HTTP instead of HTTPS on
	// the UCAN RPC server. This is insecure and intended only for local
	// development against services that serve their DID document over plain
	// HTTP; it must never be enabled in production.
	InsecureDIDResolution bool `mapstructure:"insecure_did_resolution"`
}

ServerConfig holds HTTP server settings.

type StorageConfig

type StorageConfig struct {
	// Type selects the backend: "memory" or "postgres". Defaults to "postgres".
	Type     string         `mapstructure:"type"`
	Postgres PostgresConfig `mapstructure:"postgres"`
}

StorageConfig selects and configures the store backend.

type UploadConfig

type UploadConfig struct {
	// ServiceID is the Sprue service's DID (e.g. "did:web:sprue.example.com").
	ServiceID string `mapstructure:"service_id"`
	// ServiceURL is the Sprue service's HTTP endpoint.
	ServiceURL string `mapstructure:"service_url"`
	// ProductID is the Sprue product/plan DID that tenants are registered under
	// when Hilt provisions them (the /customer/add product argument).
	ProductID string `mapstructure:"product_id"`
	// Proofs is the UCAN delegation container the upload client presents to Sprue
	// — either an inline (codec-prefixed) encoded container or a path to a file
	// containing one. Empty means no proofs (only self-issued calls will work).
	Proofs string `mapstructure:"proofs"`
}

UploadConfig holds settings for the Sprue upload service, which Hilt calls to provision a bucket's storage space.

type VaultConfig

type VaultConfig struct {
	// Type selects the backend: "hashicorp" or "memory". Defaults to "hashicorp".
	Type      string          `mapstructure:"type"`
	Hashicorp HashicorpConfig `mapstructure:"hashicorp"`
}

VaultConfig selects and configures the vault backend for private key material.

Jump to

Keyboard shortcuts

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