config

package
v0.0.79 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package config contains the configuration for the minder cli and server

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindConfigFlag

func BindConfigFlag[V any](
	v *viper.Viper,
	flags *pflag.FlagSet,
	viperPath string,
	cmdLineArg string,
	defaultValue V,
	help string,
	binder FlagInst[V],
) error

BindConfigFlag is a helper function that binds a configuration value to a flag.

Parameters: - v: The viper.Viper object used to retrieve the configuration value. - flags: The pflag.FlagSet object used to retrieve the flag value. - viperPath: The path used to retrieve the configuration value from Viper. - cmdLineArg: The flag name used to check if the flag has been set and to retrieve its value. - help: The help text for the flag. - defaultValue: A default value used to determine the type of the flag (string, int, etc.). - binder: A function that creates a flag and returns a pointer to the value.

func BindConfigFlagWithShort

func BindConfigFlagWithShort[V any](
	v *viper.Viper,
	flags *pflag.FlagSet,
	viperPath string,
	cmdLineArg string,
	short string,
	defaultValue V,
	help string,
	binder FlagInstShort[V],
) error

BindConfigFlagWithShort is a helper function that binds a configuration value to a flag.

Parameters: - v: The viper.Viper object used to retrieve the configuration value. - flags: The pflag.FlagSet object used to retrieve the flag value. - viperPath: The path used to retrieve the configuration value from Viper. - cmdLineArg: The flag name used to check if the flag has been set and to retrieve its value. - short: The short name for the flag. - help: The help text for the flag. - defaultValue: A default value used to determine the type of the flag (string, int, etc.). - binder: A function that creates a flag and returns a pointer to the value.

func GetConfigFileData

func GetConfigFileData(cfgFilePath string) (interface{}, error)

GetConfigFileData returns the data from the given configuration file.

func GetKeysWithNullValueFromYAML

func GetKeysWithNullValueFromYAML(data interface{}, currentPath string) []string

GetKeysWithNullValueFromYAML returns a list of paths to null values in the given configuration data.

func GetRelevantCfgPath

func GetRelevantCfgPath(paths []string) string

GetRelevantCfgPath returns the first path that exists (and is a config file).

func ReadConfigFromViper

func ReadConfigFromViper[CFG any](v *viper.Viper) (*CFG, error)

ReadConfigFromViper reads the configuration from the given Viper instance. This will return the already-parsed and validated configuration, or an error.

func ReadKey

func ReadKey(keypath string) ([]byte, error)

ReadKey reads a key from a file

func RegisterDatabaseFlags

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

RegisterDatabaseFlags registers the flags for the database configuration

func RegisterGRPCClientConfigFlags

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

RegisterGRPCClientConfigFlags registers the flags for the gRPC client

func SetViperStructDefaults

func SetViperStructDefaults(v *viper.Viper, prefix string, s any)

SetViperStructDefaults recursively sets the viper default values for the given struct.

Per https://github.com/spf13/viper/issues/188#issuecomment-255519149, and https://github.com/spf13/viper/issues/761, we need to call viper.SetDefault() for each field in the struct to be able to use env var overrides. This also lets us use the struct as the source of default values, so yay?

Types

type DatabaseConfig

type DatabaseConfig struct {
	Host            string `mapstructure:"dbhost" default:"localhost"`
	Port            int    `mapstructure:"dbport" default:"5432"`
	User            string `mapstructure:"dbuser" default:"postgres"`
	Password        string `mapstructure:"dbpass" default:"postgres"`
	Name            string `mapstructure:"dbname" default:"minder"`
	SSLMode         string `mapstructure:"sslmode" default:"disable"`
	IdleConnections int    `mapstructure:"idle_connections" default:"0"`
}

DatabaseConfig is the configuration for the database

func (*DatabaseConfig) GetDBConnection

func (c *DatabaseConfig) GetDBConnection(ctx context.Context) (*sql.DB, string, error)

GetDBConnection returns a connection to the database

type FlagInst

type FlagInst[V any] func(name string, value V, usage string) *V

FlagInst is a function that creates a flag and returns a pointer to the value

type FlagInstShort

type FlagInstShort[V any] func(name, shorthand string, value V, usage string) *V

FlagInstShort is a function that creates a flag and returns a pointer to the value

type GRPCClientConfig

type GRPCClientConfig struct {
	// Host is the host to connect to
	Host string `mapstructure:"host" yaml:"host" json:"host" default:"api.stacklok.com"`

	// Port is the port to connect to
	Port int `mapstructure:"port" yaml:"port" json:"port" default:"443"`

	// Insecure is whether to allow establishing insecure connections
	Insecure bool `mapstructure:"insecure" yaml:"insecure" json:"insecure" default:"false"`
}

GRPCClientConfig is the configuration for a service to connect to minder gRPC server

Directories

Path Synopsis
Package client contains the configuration for the minder cli
Package client contains the configuration for the minder cli
Package reminder contains configuration options for the reminder service.
Package reminder contains configuration options for the reminder service.
Package server contains a centralized structure for all configuration options.
Package server contains a centralized structure for all configuration options.

Jump to

Keyboard shortcuts

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