config

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config loads reusable Directory client context configuration.

Index

Constants

View Source
const (
	// DefaultEnvPrefix is the default environment variable prefix for client config.
	DefaultEnvPrefix = dirclient.DefaultEnvPrefix

	// ClientContextEnv is the DIRECTORY_CLIENT-prefixed context selection environment variable.
	ClientContextEnv = "DIRECTORY_CLIENT_CONTEXT"
)

Variables

This section is empty.

Functions

func ClearExtractor added in v1.6.0

func ClearExtractor(path string) error

ClearExtractor removes the machine-wide extractor section, preserving all other config. It is a genuine no-op when the section is already absent (or no config file exists): it does not create or rewrite the file in that case.

func DefaultPath

func DefaultPath() (string, error)

DefaultPath returns the default reusable client config file path.

func ResolveConfigured added in v1.7.0

func ResolveConfigured(localOpts ...sdk.Option) (extractor.Extractor, error)

ResolveConfigured resolves the extractor from the machine-wide config saved by `dirctl init`, returning the Extractor interface. It honors a persisted RemoteAddr (remote backend) and otherwise loads the provisioned local assets. localOpts tune the local backend only. It errors clearly when init has not run.

func ResolveDoctor

func ResolveDoctor(opts ResolveOptions) (*Doctor, *ResolvedContext, error)

ResolveDoctor resolves diagnostic-only settings for the selected context.

func SaveContext added in v1.6.0

func SaveContext(path string, name string, ctx Context, setCurrent bool) error

SaveContext adds or replaces a named context, preserving the other recognized config (current_context, extractor, and the other contexts). When setCurrent is true it also marks that context as current_context. Callers that must not overwrite an existing context should check first (e.g. ListContexts).

func SaveExtractor added in v1.6.0

func SaveExtractor(path string, e *Extractor) error

SaveExtractor persists the machine-wide extractor section, preserving all other config (contexts, current_context).

func SaveFile

func SaveFile(path string, file *File) error

SaveFile writes a reusable client context config file.

Preserving unrecognized top-level sections requires file to have come from the tolerant load path, which is where they are captured; every writer in this package does that. A File built by hand, or loaded through the strict LoadFile, carries none, so saving it drops any section this binary does not model. Only whole-document rewrites should do that deliberately.

Types

type Context

type Context struct {
	ServerAddress    string   `yaml:"server_address"`
	TlsSkipVerify    bool     `yaml:"tls_skip_verify"`
	TlsCertFile      string   `yaml:"tls_cert_file"`
	TlsKeyFile       string   `yaml:"tls_key_file"`
	TlsCAFile        string   `yaml:"tls_ca_file"`
	SpiffeSocketPath string   `yaml:"spiffe_socket_path"`
	SpiffeToken      string   `yaml:"spiffe_token"`
	AuthMode         string   `yaml:"auth_mode"`
	JWTAudience      string   `yaml:"jwt_audience"`
	OIDCIssuer       string   `yaml:"oidc_issuer"`
	OIDCClientID     string   `yaml:"oidc_client_id"`
	OIDCScopes       []string `yaml:"oidc_scopes"`
	OIDCAudience     string   `yaml:"oidc_audience"`
	AuthToken        string   `yaml:"auth_token"`
	Doctor           Doctor   `yaml:"doctor"`
}

Context is a named client configuration block.

type ContextSummary

type ContextSummary struct {
	Name    string
	Current bool
}

ContextSummary is a list entry for a configured context.

func ListContexts

func ListContexts(path string) ([]ContextSummary, error)

ListContexts lists configured contexts in name order.

type ContextValidation

type ContextValidation struct {
	Name  string
	Error error
}

ContextValidation describes the validation result for a configured context.

func ValidateContexts

func ValidateContexts(path string, name string) ([]ContextValidation, error)

ValidateContexts validates stored context definitions without applying environment overrides.

type Doctor

type Doctor struct {
	BootstrapPeers []string `yaml:"bootstrap_peers"`
}

Doctor holds diagnostic-only settings for dirctl doctor.

type Extractor added in v1.6.0

type Extractor struct {
	OASFURL  string `yaml:"oasf_url"`
	AssetDir string `yaml:"asset_dir"`
	// RemoteAddr is an optional gRPC OASF-SDK server address. When set,
	// consumers resolve the remote extractor backend instead of loading the
	// in-process assets under AssetDir.
	RemoteAddr string `yaml:"remote_addr,omitempty"`
}

Extractor is the machine-wide OASF taxonomy extractor provisioning record, written by `dirctl init` so import/search consumers can load the provisioned assets in-process without re-choosing the endpoint or asset location.

func LoadExtractor added in v1.6.0

func LoadExtractor(path string) (*Extractor, error)

LoadExtractor returns the persisted machine-wide extractor section, or nil when it is unset or the config file does not exist.

type File

type File struct {
	CurrentContext string             `yaml:"current_context"`
	Contexts       map[string]Context `yaml:"contexts"`
	Extractor      *Extractor         `yaml:"extractor,omitempty"`
	// contains filtered or unexported fields
}

File is the top-level reusable client context configuration file.

func LoadFile

func LoadFile(path string) (*File, error)

LoadFile loads a reusable client context config file from path.

func LoadFileWithOptions

func LoadFileWithOptions(path string, opts LoadOptions) (*File, error)

LoadFileWithOptions loads a reusable client context config file from path with parsing options.

type LoadOptions

type LoadOptions struct {
	// AllowUnknownFields permits forward-compatible parsing for callers that only
	// need known client fields from a config that may include command extensions.
	AllowUnknownFields bool
}

LoadOptions controls how a reusable client context config file is loaded.

type ResolveOptions

type ResolveOptions struct {
	// Path is the config file path. If empty, DefaultPath is used.
	Path string

	// Context is an explicit context name override.
	Context string

	// EnvPrefix is the client environment variable prefix. If empty,
	// DefaultEnvPrefix is used.
	EnvPrefix string

	// Overrides contains explicit values, typically from CLI flags.
	Overrides *dirclient.Config

	// OverrideFields lists schema field names from Overrides that should be
	// applied, including zero values. If empty, non-zero override values are
	// applied.
	OverrideFields []string

	// SkipValidation skips required-field validation for callers that only need
	// a subset of client config, such as auth token cache commands.
	SkipValidation bool

	// AllowUnknownFields permits forward-compatible parsing for callers that only
	// need known client fields from a config that may include command extensions.
	AllowUnknownFields bool
}

ResolveOptions controls context and client configuration resolution.

type ResolvedContext

type ResolvedContext struct {
	Name   string
	Source string
	Path   string
}

ResolvedContext describes which context was selected during resolution.

func CurrentContext

func CurrentContext(path string) (*ResolvedContext, error)

CurrentContext returns the persisted current_context without resolving client settings.

func Resolve

Resolve resolves the effective Directory client config.

func SetCurrentContext

func SetCurrentContext(path string, name string) (*ResolvedContext, error)

SetCurrentContext persists name as the active context.

Jump to

Keyboard shortcuts

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