config

package
v0.68.1 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package config provides access to fsoc configuration, both to obtain the current configuration and to incrementally or fully modify the configuration. The fsoc configuration has two dimension: a config file and a context within the config file. Each config file contains one or more contexts plus a setting indicating which of them is the current one.

Index

Constants

View Source
const (
	FSOC_PROFILE_ENVVAR = "FSOC_PROFILE"
	FSOC_CONFIG_ENVVAR  = "FSOC_CONFIG"
)
View Source
const (
	DefaultConfigFile = "~/.fsoc"
	DefaultContext    = "default"
	AppdPid           = "appd-pid"
	AppdTid           = "appd-tid"
	AppdPty           = "appd-pty"
)
View Source
const (
	// No authentication (used in local/dev environments)
	AuthMethodNone = "none"
	// OAuth using the same user credentials as in a browser
	AuthMethodOAuth = "oauth"
	// Use JWT token directly
	AuthMethodJWT = "jwt"
	// Use a service principal
	AuthMethodServicePrincipal = "service-principal"
	// Use an agent principal
	AuthMethodAgentPrincipal = "agent-principal"
	// Use Session Manager (experimental)
	AuthMethodSessionManager = "session-manager"
	// Use for local setup
	AuthMethodLocal = "local"
)

Supported authentication methods

View Source
const (
	AnnotationForConfigBypass = "config/bypass-check"
)

Variables

View Source
var ErrProfileNotFound = errors.New("profile not found")

Functions

func DeleteContext

func DeleteContext(name string) error

DeleteContext deletes specified profile and updates the config file If the deleted context is the default one, xxx

func DeleteSubsystemSetting

func DeleteSubsystemSetting(ctx *Context, subsystemName string, settingName string) error

DeleteSubsystemSetting removes a subsystem-specific configuration value, without updating the config store or saving the file (see note on SetSubsystemSetting)

func ForceSetActiveProfileName added in v0.63.0

func ForceSetActiveProfileName(profile string)

ForceSetActiveProfileName sets the name of the profile to the specified value. This is used primarily when managing profiles, for commands where the profile name is given as an argument (which takes precedence over any name set in env var or config file's default). Note that this function does not validate the profile name or even its existence.

func GetCurrentProfileName

func GetCurrentProfileName() string

GetCurrentProfileName returns the profile name that is used to select the context. This is mostly the same as returned by GetCurrentContext().Name, except for the case when a new profile is being created.

func GetDefaultContextName

func GetDefaultContextName() string

GetDefaultContextName gets the default context name for the config file Note that the default context may be different from the active (current) context

func GetRegisteredSubsystems

func GetRegisteredSubsystems() []string

GetRegisteredSubsystems returns the names of subsystems that have registered a config template

func GetSubsytemConfigTemplate

func GetSubsytemConfigTemplate(subsystemName string) (any, error)

GetSubsytemConfig returns a pointer to config storage for a given subsystem

func ListAllContexts

func ListAllContexts() []string

ListAllContexts returns a list of all context names

func ListContexts

func ListContexts(prefix string) []string

ListContexts returns a list of context names which begin with `prefix`, used for the command line autocompletion

func RegisterSubsystemConfigStorage

func RegisterSubsystemConfigStorage(subsystemName string, store any) error

RegisterSubsystemConfigStorage registers storage (a pointer to a struct) for a subsystem's configuration. In addition to using the storage itself, this function uses the structure to introspect it for setting names, types and even help strings.

func RegisterTypeDecodeHooks

func RegisterTypeDecodeHooks(y ...mapstructure.DecodeHookFunc)

RegisterTypeDecodeHook registers a mapstructure type decode hook for subsystem- specific configuration types, primarily to enforce formats and parse directly into types that are convenient for the subsystems to use.

func ReplaceCurrentContext

func ReplaceCurrentContext(ctx *Context)

ReplaceCurrentContext updates the all values within the current context. It accepts a Context structure, which may or may not be returned by GetCurrentContext(). Note that the Context.Name must match the current context.

func SetActiveProfile

func SetActiveProfile(cmd *cobra.Command, args []string, emptyOK bool)

SetActiveProfile sets the name of the profile that should be used instead of the config file's current profile value.

func SetDefaultContextName

func SetDefaultContextName(name string) error

SetDefaultContextName sets the default context name in the config file and updates the file

func SetSubsystemSetting

func SetSubsystemSetting(ctx *Context, subsystemName string, settingName string, value any) error

SetSubsystemSetting updates a single value into the subsystem-specific settings of the context. It does not update the config file, nor it updates the subsystem-specific config storage (if needed, call UpdateSubsystemConfigs and UpsertContext when all settings are in ready; this ensures that the subsystem configs are parsed with all changes).

func UpdateSubsystemConfigs

func UpdateSubsystemConfigs(ctx *Context) error

UpdateSubsystemConfigs updates the subsystem-specific configurations from the config context into subsystem-provided structured store. If update fails for a subsystem, an error for it will be recorded and updates to other subsystem configurations continue. This allows callers to ignore subsystems with failed configuration while still getting configs for correctly configured systems. Returns nil or a slice of errors (the slice, if not nil, will never be empty)

func UpsertContext

func UpsertContext(ctx *Context) error

UpsertContext updates or adds a context and updates the file The context pointer may or may not have been returned by GetContext()/GetCurrentContext()

Types

type Context

type Context struct {
	Name             string                    `json:"name" yaml:"name" mapstructure:"name"`
	AuthMethod       string                    `json:"auth_method" yaml:"auth_method" mapstructure:"auth_method"`
	Server           string                    `json:"server,omitempty" yaml:"server,omitempty" mapstructure:"server,omitempty"` // deprecated
	URL              string                    `json:"url" yaml:"url" mapstructure:"url"`
	Tenant           string                    `json:"tenant,omitempty" yaml:"tenant,omitempty" mapstructure:"tenant,omitempty"`
	User             string                    `json:"user,omitempty" yaml:"user,omitempty" mapstructure:"user,omitempty"`
	Token            string                    `json:"token,omitempty" yaml:"token,omitempty" mapstructure:"token,omitempty"` // access token
	RefreshToken     string                    `json:"refresh_token,omitempty" yaml:"refresh_token,omitempty" mapstructure:"refresh_token,omitempty"`
	CsvFile          string                    `json:"csv_file,omitempty" yaml:"csv_file,omitempty" mapstructure:"csv_file,omitempty"`
	SecretFile       string                    `json:"secret_file,omitempty" yaml:"secret_file,omitempty" mapstructure:"secret_file,omitempty"`
	EnvType          string                    `json:"env_type,omitempty" yaml:"env_type,omitempty" mapstructure:"env_type,omitempty"`
	LocalAuthOptions LocalAuthOptions          `json:"auth-options,omitempty" yaml:"auth-options,omitempty" mapstructure:"auth-options,omitempty"`
	SubsystemConfigs map[string]map[string]any `json:"subsystems,omitempty" yaml:"subsystems,omitempty" mapstructure:"subsystems,omitempty"`
}

Struct Context defines a full configuration context (aka access profile). The Name field contains the name of the context (which is unique within the config file); the remaining fields define the access profile.

func GetContext

func GetContext(name string) (*Context, error)

GetContext

func GetCurrentContext

func GetCurrentContext() *Context

GetCurrentContext returns the context (access profile) selected by the user for the particular invocation of the fsoc utility. Returns nil if no current context is defined (and the only commands allowed in this state are `config create|set`, which will create the context). Note that GetCurrentContext returns a pointer into the config file's overall configuration; it can be modified and then updated using ReplaceCurrentContext().

type ErrSubsystemConfig

type ErrSubsystemConfig struct {
	Errors []error
}

func (*ErrSubsystemConfig) Error

func (e *ErrSubsystemConfig) Error() string

func (*ErrSubsystemConfig) WrappedErrors

func (e *ErrSubsystemConfig) WrappedErrors() []error

type ErrSubsystemNotFound

type ErrSubsystemNotFound struct {
	SubsystemName string
}

func (*ErrSubsystemNotFound) Error

func (e *ErrSubsystemNotFound) Error() string

type ErrSubsystemParsingError

type ErrSubsystemParsingError struct {
	SubsystemName string
	ParsingError  error
}

func (*ErrSubsystemParsingError) Error

func (e *ErrSubsystemParsingError) Error() string

func (*ErrSubsystemParsingError) Unwrap

func (e *ErrSubsystemParsingError) Unwrap() error

type ErrSubsystemSettingNotFound

type ErrSubsystemSettingNotFound struct {
	SubsystemName string
	SettingName   string
}

func (*ErrSubsystemSettingNotFound) Error

type LocalAuthOptions

type LocalAuthOptions struct {
	AppdPty string `json:"appd-pty" yaml:"appd-pty" mapstructure:"appd-pty"`
	AppdTid string `json:"appd-tid" yaml:"appd-tid" mapstructure:"appd-tid"`
	AppdPid string `json:"appd-pid" yaml:"appd-pid" mapstructure:"appd-pid"`
}

func (*LocalAuthOptions) String

func (o *LocalAuthOptions) String() string

type Validator

type Validator interface {
	ValidateAndSet(v any) error
}

Jump to

Keyboard shortcuts

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