config

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ConfigSchedulerInterval = 300
	ValidSchemes            = []string{"blob", "file", "http", "https", "s3", "S3", "etcd"}
)
View Source
var (
	ConfigCache map[string]map[string][]byte
)

Functions

func CacheConfigs

func CacheConfigs(manager string, files []string) error

CacheConfigs takes in a string of the base directory for the config directory and a slice of config file names and caches those files into memory. It returns an error on the event of error

func CompareAndCopy

func CompareAndCopy(source string, dest string, m string) bool

func CompareHashOnly added in v1.5.0

func CompareHashOnly(source string, storedHash string, m string) (bool, string, error)

CompareHashOnly compares the hash of a source file against a stored hash. Returns true if the file has changed (hashes differ), false if unchanged. This is used in watch-only mode instead of CompareAndCopy.

func ComputeDataHash added in v1.5.0

func ComputeDataHash(data []byte) string

ComputeDataHash computes the SHA256 hash of a byte slice and returns it as a hex string. This is used in watch-only mode to hash downloaded content before comparison.

func ComputeFileHash added in v1.5.0

func ComputeFileHash(filePath string) (string, error)

ComputeFileHash computes the SHA256 hash of a file and returns it as a hex string. This is used in watch-only mode to detect file changes without writing to disk.

func CopyFile

func CopyFile(src string, dst string) error

CopyFile copies the src path string to the dst path string. If there is an error, an error is returned, otherwise nil is returned.

func GetConfigManager

func GetConfigManager(entry string, bc *ConfigSettings) error

func GetManagerStatus

func GetManagerStatus(statusFile string, manager string) bool

func IsValidScheme

func IsValidScheme(s string) bool

func ParseConfig

func ParseConfig(config []byte) error

func ParseMustacheSubs

func ParseMustacheSubs(pairs []string) (map[string]string, error)

func RenderConfigMustache

func RenderConfigMustache(f *os.File, subs map[string]string) error

RenderConfigMustache takes a pointer to an os.File object. It reads the file attempts to parse the mustache

func RestoreCachedConfigs

func RestoreCachedConfigs(manager string, files []string, cleanFiles bool) error

RestoreCachedConfigs takes in a strint of the base directory for the config directory and a slice of config file names and restores those files from the cache back to the filesystem. It returns an error on the event of an error

func SetManagerStatus

func SetManagerStatus(statusFile string, manager string, state bool) error

func ValidateConfig

func ValidateConfig(opts *ValidateOpts) error

ValidateConfig takes a pointer to an os.File object. It scans over the file and ensures that it begins with the proper header, and ends with the proper footer. If it does not begin or end with the proper header/footer, then an error is returned. If the file passes the checks, a nil is returned. If SkipButlerHeader is true, header/footer validation is skipped but other validation (JSON/YAML parsing) still occurs.

func ValidateMustacheSubs

func ValidateMustacheSubs(Subs map[string]string) bool

func WriteManagerStatusFile

func WriteManagerStatusFile(statusFile string, status Status) error

Types

type ButlerConfig

type ButlerConfig struct {
	Client                  *ConfigClient
	Config                  *ConfigSettings
	FirstRun                bool
	LogLevel                log.Level
	PrevCMSchedulerInterval int
	Interval                int
	Timeout                 int
	RawConfig               []byte
	Scheduler               *gocron.Scheduler
	InsecureSkipVerify      bool
	MethodOpts              methods.MethodOpts
	// contains filtered or unexported fields
}

func NewButlerConfig

func NewButlerConfig(opts *ButlerConfigOpts) (*ButlerConfig, error)

func (*ButlerConfig) CheckPaths

func (bc *ButlerConfig) CheckPaths() error

func (*ButlerConfig) GetCMInterval

func (bc *ButlerConfig) GetCMInterval() int

func (*ButlerConfig) GetCMPrevInterval

func (bc *ButlerConfig) GetCMPrevInterval() int

func (*ButlerConfig) GetInterval

func (bc *ButlerConfig) GetInterval() int

func (*ButlerConfig) GetLogLevel

func (bc *ButlerConfig) GetLogLevel() log.Level

func (*ButlerConfig) GetManager

func (bc *ButlerConfig) GetManager(m string) *Manager

func (*ButlerConfig) GetManagers

func (bc *ButlerConfig) GetManagers() map[string]*Manager

func (*ButlerConfig) GetStatusFile

func (bc *ButlerConfig) GetStatusFile() string

func (*ButlerConfig) Handler

func (bc *ButlerConfig) Handler() error

func (*ButlerConfig) Host added in v1.4.1

func (bc *ButlerConfig) Host() string

func (*ButlerConfig) Init

func (bc *ButlerConfig) Init() error

func (*ButlerConfig) Opts added in v1.4.1

func (bc *ButlerConfig) Opts() methods.MethodOpts

func (*ButlerConfig) Path added in v1.4.1

func (bc *ButlerConfig) Path() string

func (*ButlerConfig) RunCMHandler

func (bc *ButlerConfig) RunCMHandler() error

func (*ButlerConfig) Scheme added in v1.4.1

func (bc *ButlerConfig) Scheme() string

func (*ButlerConfig) SetCMInterval

func (bc *ButlerConfig) SetCMInterval(i int) error

func (*ButlerConfig) SetCMPrevInterval

func (bc *ButlerConfig) SetCMPrevInterval(i int) error

func (*ButlerConfig) SetInterval

func (bc *ButlerConfig) SetInterval(t int) error

func (*ButlerConfig) SetLogLevel

func (bc *ButlerConfig) SetLogLevel(level log.Level)

func (*ButlerConfig) SetMethodOpts added in v1.4.1

func (bc *ButlerConfig) SetMethodOpts(opts methods.MethodOpts) error

func (*ButlerConfig) SetPath

func (bc *ButlerConfig) SetPath(p string) error

func (*ButlerConfig) SetScheduler

func (bc *ButlerConfig) SetScheduler(s *gocron.Scheduler) error

func (*ButlerConfig) SetScheme

func (bc *ButlerConfig) SetScheme(s string) error

func (*ButlerConfig) SetTimeout

func (bc *ButlerConfig) SetTimeout(t int) error

func (*ButlerConfig) SetURL added in v1.4.1

func (bc *ButlerConfig) SetURL(u *url.URL)

func (*ButlerConfig) URL added in v1.4.1

func (bc *ButlerConfig) URL() *url.URL

type ButlerConfigOpts added in v1.4.1

type ButlerConfigOpts struct {
	InsecureSkipVerify bool
	LogLevel           log.Level
	URL                *url.URL
}

type ChanEvent

type ChanEvent interface {
	CanCopyFiles() bool
	CleanTmpFiles() error
	GetTmpFileMap() []TmpFile
	SetSuccess(string, string, error) error
	SetTmpFile(string, string, string) error
	CopyPrimaryConfigFiles(map[string]*ManagerOpts) bool
	CopyAdditionalConfigFiles(string) bool
	// Watch-only mode methods - compare hashes without writing files
	ComparePrimaryConfigHashes(map[string]*ManagerOpts, map[string]string) (bool, map[string]string)
	CompareAdditionalConfigHashes(map[string]string) (bool, map[string]string)
}

ChanEvent is the interface which gets passed along to the different retrieval mechanisms which ultimately keeps track of which files have been downlaoded, changed, etc.

type ConfigChanEvent

type ConfigChanEvent struct {
	HasChanged bool
	TmpFile    *os.File
	ConfigFile *string
	Manager    string
	Repo       map[string]*RepoFileEvent
}

ConfigChanEvent is the object passed around in the channel which contains information on whether the file has changed, the path to the tempfile, the config name, and repository event information

func NewConfigChanEvent

func NewConfigChanEvent() *ConfigChanEvent

func (*ConfigChanEvent) CanCopyFiles

func (c *ConfigChanEvent) CanCopyFiles() bool

CanCopyFiles returns a boolean which tells whether or not butler is able to copy the files from the repository to the local filesystem. The assumption is that ALL files have to pass before butler attempts to copy over.

func (*ConfigChanEvent) CleanTmpFiles

func (c *ConfigChanEvent) CleanTmpFiles() error

CleanTmpFiles returns an error, or not, depending on whether butler was able to delete all the tempfiles that were created during the config file retrieval from the remote repository

func (*ConfigChanEvent) CompareAdditionalConfigHashes added in v1.5.0

func (c *ConfigChanEvent) CompareAdditionalConfigHashes(storedHashes map[string]string) (bool, map[string]string)

CompareAdditionalConfigHashes compares hashes of additional config files without writing to disk. This is used in watch-only mode. Returns true if any file has changed, along with updated hashes.

func (*ConfigChanEvent) ComparePrimaryConfigHashes added in v1.5.0

func (c *ConfigChanEvent) ComparePrimaryConfigHashes(opts map[string]*ManagerOpts, storedHashes map[string]string) (bool, map[string]string)

ComparePrimaryConfigHashes compares hashes of primary config files without writing to disk. This is used in watch-only mode. Returns true if any file has changed, along with updated hashes.

func (*ConfigChanEvent) CopyAdditionalConfigFiles

func (c *ConfigChanEvent) CopyAdditionalConfigFiles(destDir string) bool

func (*ConfigChanEvent) CopyPrimaryConfigFiles

func (c *ConfigChanEvent) CopyPrimaryConfigFiles(opts map[string]*ManagerOpts) bool

func (*ConfigChanEvent) GetTmpFileMap

func (c *ConfigChanEvent) GetTmpFileMap() []TmpFile

GetTmpFileMap returns a slice of SORTED TmpFile objects which contain the names of all the temp files creted during the config file retrieval from the remote repository.

func (*ConfigChanEvent) SetFailure

func (c *ConfigChanEvent) SetFailure(repo string, file string, err error) error

SetFailure sets the value for the file argument in the repo argument to false

func (*ConfigChanEvent) SetSuccess

func (c *ConfigChanEvent) SetSuccess(repo string, file string, err error) error

SetSuccess sets the value for the file argument in the repo argument to true

func (*ConfigChanEvent) SetTmpFile

func (c *ConfigChanEvent) SetTmpFile(repo string, file string, tmpfile string) error

type ConfigClient

type ConfigClient struct {
	Scheme     string
	Method     methods.Method
	HTTPClient *retryablehttp.Client
}

func NewConfigClient

func NewConfigClient(bc *ButlerConfig) (*ConfigClient, error)

func (*ConfigClient) Get

func (c *ConfigClient) Get(val *url.URL) (*methods.Response, error)

func (*ConfigClient) SetRetryMax

func (c *ConfigClient) SetRetryMax(val int)

func (*ConfigClient) SetRetryWaitMax

func (c *ConfigClient) SetRetryWaitMax(val int)

func (*ConfigClient) SetRetryWaitMin

func (c *ConfigClient) SetRetryWaitMin(val int)

func (*ConfigClient) SetTimeout

func (c *ConfigClient) SetTimeout(val int)

type ConfigFileMap

type ConfigFileMap struct {
	TmpFile string
	Success bool
}

type ConfigGlobals

type ConfigGlobals struct {
	Managers             []string `mapstructure:"config-managers" json:"-"`
	SchedulerInterval    int      `json:"scheduler-interval"`
	CfgEnableHTTPLog     string   `mapstructure:"enable-http-log" json:"-"`
	EnableHTTPLog        bool     `json:"enable-http-log"`
	CfgSchedulerInterval string   `mapstructure:"scheduler-interval" json:"-"`
	CfgExitOnFailure     string   `mapstructure:"exit-on-config-failure" json:"-"`
	ExitOnFailure        bool     `json:"exit-on-failure"`
	CfgStatusFile        string   `mapstructure:"status-file" json:"-"`
	StatusFile           string   `json:"status-file"`
	CfgHTTPProto         string   `mapstructure:"http-proto" json:"-"`
	HTTPProto            string   `json:"http-proto"`
	CfgHTTPPort          string   `mapstructure:"http-port" json:"-"`
	HTTPPort             int      `json:"http-port"`
	CfgHTTPTLSCert       string   `mapstructure:"http-tls-cert" json:"-"`
	HTTPTLSCert          string   `json:"http-tls-cert"`
	CfgHTTPTLSKey        string   `mapstructure:"http-tls-key" json:"-"`
	HTTPTLSKey           string   `json:"http-tls-key"`
}

type ConfigSettings

type ConfigSettings struct {
	Managers map[string]*Manager `json:"managers"`
	Globals  ConfigGlobals       `json:"globals"`
}

func NewConfigSettings

func NewConfigSettings() *ConfigSettings

func (*ConfigSettings) GetAllConfigLocalPaths

func (b *ConfigSettings) GetAllConfigLocalPaths(mgr string) []string

func (*ConfigSettings) ParseConfig

func (c *ConfigSettings) ParseConfig(config []byte) error

type Manager

type Manager struct {
	Name                string                  `json:"name"`
	Repos               []string                `mapstructure:"repos" json:"repos"`
	CfgCleanFiles       string                  `mapstructure:"clean-files" json:"-"`
	CleanFiles          bool                    `json:"clean-files"`
	GoodCache           bool                    `json:"good-cache"`
	LastRun             time.Time               `json:"last-run"`
	MustacheSubsArray   []string                `mapstructure:"mustache-subs" json:"-"`
	MustacheSubs        map[string]string       `json:"mustache-subs"`
	CfgEnableCache      string                  `mapstructure:"enable-cache" json:"-"`
	EnableCache         bool                    `json:"enable-cache"`
	CachePath           string                  `mapstructure:"cache-path" json:"cache-path"`
	DestPath            string                  `mapstructure:"dest-path" json:"dest-path"`
	PrimaryConfigName   string                  `mapstructure:"primary-config-name" json:"primary-config-name"`
	CfgManagerTimeoutOk string                  `mapstructure:"manager-timeout-ok" json:"-"`
	ManagerTimeoutOk    bool                    `json:"manager-timeout-ok"`
	CfgSkipButlerHeader string                  `mapstructure:"skip-butler-header" json:"-"`
	SkipButlerHeader    bool                    `json:"skip-butler-header"`
	CfgWatchOnly        string                  `mapstructure:"watch-only" json:"-"`
	WatchOnly           bool                    `json:"watch-only"`
	FileHashes          map[string]string       `json:"-"` // In-memory hash storage for watch-only mode
	ManagerOpts         map[string]*ManagerOpts `json:"opts"`
	Reloader            reloaders.Reloader      `mapstructure:"-" json:"reloader,omitempty"`
	ReloadManager       bool                    `json:"-"`
}

func (*Manager) DownloadAdditionalConfigFiles

func (bm *Manager) DownloadAdditionalConfigFiles(c chan ChanEvent) error

func (*Manager) DownloadPrimaryConfigFiles

func (bm *Manager) DownloadPrimaryConfigFiles(c chan ChanEvent) error

func (*Manager) GetAllLocalPaths

func (bm *Manager) GetAllLocalPaths() []string

func (*Manager) PathCleanup

func (bm *Manager) PathCleanup(path string, f os.FileInfo, err error) error

PathCleanup

func (*Manager) Reload

func (bm *Manager) Reload() error

type ManagerOpts

type ManagerOpts struct {
	Method                          string         `mapstructure:"method" json:"method"`
	RepoPath                        string         `mapstructure:"repo-path" json:"repo-path"`
	Repo                            string         `json:"repo"`
	PrimaryConfig                   []string       `mapstructure:"primary-config" json:"primary-config"`
	AdditionalConfig                []string       `mapstructure:"additional-config" json:"additional-config"`
	PrimaryConfigsFullURLs          []string       `json:"-"`
	AdditionalConfigsFullURLs       []string       `json:"-"`
	PrimaryConfigsFullLocalPaths    []string       `json:"-"`
	AdditionalConfigsFullLocalPaths []string       `json:"-"`
	ContentType                     string         `mapstructure:"content-type" json:"content-type"`
	Opts                            methods.Method `json:"opts"`
	// contains filtered or unexported fields
}

func GetManagerOpts

func GetManagerOpts(entry string, bc *ConfigSettings) (*ManagerOpts, error)

func (*ManagerOpts) AppendAdditionalConfigFile

func (bmo *ManagerOpts) AppendAdditionalConfigFile(c string) error

func (*ManagerOpts) AppendAdditionalConfigURL added in v1.4.1

func (bmo *ManagerOpts) AppendAdditionalConfigURL(c string) error

func (*ManagerOpts) AppendPrimaryConfigFile

func (bmo *ManagerOpts) AppendPrimaryConfigFile(c string) error

func (*ManagerOpts) AppendPrimaryConfigURL added in v1.4.1

func (bmo *ManagerOpts) AppendPrimaryConfigURL(c string) error

func (*ManagerOpts) DownloadConfigFile

func (bmo *ManagerOpts) DownloadConfigFile(file string) *os.File

Really need to come up with a better method for this.

func (*ManagerOpts) GetAdditionalConfigURLs added in v1.4.1

func (bmo *ManagerOpts) GetAdditionalConfigURLs() []string

func (*ManagerOpts) GetAdditionalLocalConfigFiles

func (bmo *ManagerOpts) GetAdditionalLocalConfigFiles() []string

func (*ManagerOpts) GetAdditionalRemoteConfigFiles

func (bmo *ManagerOpts) GetAdditionalRemoteConfigFiles() []string

func (*ManagerOpts) GetPrimaryConfigURLs added in v1.4.1

func (bmo *ManagerOpts) GetPrimaryConfigURLs() []string

func (*ManagerOpts) GetPrimaryLocalConfigFiles

func (bmo *ManagerOpts) GetPrimaryLocalConfigFiles() []string

func (*ManagerOpts) GetPrimaryRemoteConfigFiles

func (bmo *ManagerOpts) GetPrimaryRemoteConfigFiles() []string

func (*ManagerOpts) SetParentManager

func (bmo *ManagerOpts) SetParentManager(c string) error

type RepoFileEvent

type RepoFileEvent struct {
	Success map[string]bool
	Error   map[string]error
	TmpFile map[string]string
}

func (*RepoFileEvent) SetFailure

func (r *RepoFileEvent) SetFailure(file string, err error) error

func (*RepoFileEvent) SetSuccess

func (r *RepoFileEvent) SetSuccess(file string, err error) error

func (*RepoFileEvent) SetTmpFile

func (r *RepoFileEvent) SetTmpFile(file string, tmpfile string) error

type Status

type Status struct {
	Manager map[string]bool `json:"manager"`
}

func ReadManagerStatusFile

func ReadManagerStatusFile(statusFile string) (*Status, error)

type TmpFile

type TmpFile struct {
	Name string
	File string
}

type ValidateOpts

type ValidateOpts struct {
	ContentType      string
	Data             interface{}
	FileName         string
	Manager          string
	SkipButlerHeader bool
}

func NewValidateOpts

func NewValidateOpts() *ValidateOpts

func (*ValidateOpts) WithContentType

func (o *ValidateOpts) WithContentType(t string) *ValidateOpts

func (*ValidateOpts) WithData

func (o *ValidateOpts) WithData(d interface{}) *ValidateOpts

func (*ValidateOpts) WithFileName

func (o *ValidateOpts) WithFileName(f string) *ValidateOpts

func (*ValidateOpts) WithManager

func (o *ValidateOpts) WithManager(m string) *ValidateOpts

func (*ValidateOpts) WithSkipButlerHeader added in v1.4.1

func (o *ValidateOpts) WithSkipButlerHeader(s bool) *ValidateOpts

Jump to

Keyboard shortcuts

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