config

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAuthor       = "Zachi Nachshon <zachi.nachshon@gmail.com>"
	DefaultLicense      = "Apache"
	DefaultRemoteBranch = "master"
)
View Source
const (
	Identifier string = "config-manager"
)

Variables

View Source
var CreateFakeConfigManager = func() *fakeConfigManager {
	return &fakeConfigManager{}
}
View Source
var CreateFakeViperConfigAdapter = func() *fakeViperConfigAdapter {
	return &fakeViperConfigAdapter{}
}
View Source
var GetCustomTestConfigText = func(items TemplateItems) string {
	var yamlConfig, err = templates.TemplateToText(configYamlTemplate, &items)
	if err != nil {

		logger.Fatalf("Failed to generate config template with substitutions. error: %s", err)
	}
	return yamlConfig
}
View Source
var GetDefaultTestConfigText = func() string {
	var yamlConfig, err = templates.TemplateToText(configYamlTemplate, nil)
	if err != nil {

		logger.Fatalf("Failed to generate config template. error: %s", err)
	}
	return yamlConfig
}

Functions

func ConfigObjToYaml

func ConfigObjToYaml(cfg *AnchorConfig) (string, error)

func NewManager

func NewManager() *configManagerImpl

func SetInContext

func SetInContext(ctx common.Context, config *AnchorConfig)

Types

type AnchorConfig

type AnchorConfig struct {
	Config  *Config `yaml:"config"`
	Author  string  `yaml:"author"`
	License string  `yaml:"license"`
}

func FromContext

func FromContext(ctx common.Context) *AnchorConfig

func YamlToConfigObj

func YamlToConfigObj(yamlText string) (*AnchorConfig, error)

type Config

type Config struct {
	CurrentContext string     `yaml:"currentContext"`
	Contexts       []*Context `yaml:"contexts"`
	ActiveContext  *Context   `yaml:"-"` // being set programmatically
}

type ConfigManager

type ConfigManager interface {
	SetupConfigFileLoader() error
	SetupConfigInMemoryLoader(yaml string) error
	ListenOnConfigFileChanges(ctx common.Context)

	OverrideConfig(cfgToUpdate *AnchorConfig) error
	OverrideConfigEntry(entryName string, value interface{}) error
	ReadConfig(key string) string

	SwitchActiveConfigContextByName(cfg *AnchorConfig, cfgCtxName string) error
	CreateConfigObject(shouldValidateCfgSchema bool) (*AnchorConfig, error)

	GetConfigFilePath() (string, error)
	SetDefaultsPostCreation(anchorConfig *AnchorConfig) error
}

type ConfigViperAdapter

type ConfigViperAdapter interface {
	SetConfigPath(dirPath string) error

	LoadConfigFromFile() error
	LoadConfigFromText(yaml string) error
	RegisterConfigChangesListener(callback func(e fsnotify.Event))

	UpdateAll(cfgToUpdate *AnchorConfig) error
	UpdateEntry(entryName string, value interface{}) error
	GetConfigByKey(key string) string

	SetDefaults() error
	SetEnvVars() error
	AppendConfig(anchorConfig interface{}) error
	// contains filtered or unexported methods
}

func NewAdapter

func NewAdapter() ConfigViperAdapter

type Context

type Context struct {
	Name    string       `yaml:"name"`
	Context *ContextItem `yaml:"context"`
}

func AppendEmptyConfigContext added in v0.2.0

func AppendEmptyConfigContext(cfg *AnchorConfig, name string) *Context

func TryGetConfigContext

func TryGetConfigContext(contexts []*Context, cfgCtxName string) *Context

type ContextItem

type ContextItem struct {
	Repository *Repository `yaml:"repository"`
}

type Local

type Local struct {
	Path string `yaml:"path"`
}

type Remote

type Remote struct {
	Url        string `yaml:"url"`
	Revision   string `yaml:"revision"`
	Branch     string `yaml:"branch"`
	ClonePath  string `yaml:"clonePath"`
	AutoUpdate bool   `yaml:"autoUpdate"`
}

type Repository

type Repository struct {
	Remote *Remote `yaml:"remote"`
	Local  *Local  `yaml:"local"`
}

type TemplateItems

type TemplateItems struct {
	Author                          string
	License                         string
	CurrentContext                  string
	FirstContextName                string
	FirstContextClonePath           string
	FirstContextRemoteRepoUrl       string
	FirstContextRemoteRepoRevision  string
	FirstContextRemoteRepoBranch    string
	FirstContextLocalRepoPath       string
	SecondContextName               string
	SecondContextClonePath          string
	SecondContextRemoteRepoUrl      string
	SecondContextRemoteRepoRevision string
	SecondContextRemoteRepoBranch   string
	SecondContextLocalRepoPath      string
}

Jump to

Keyboard shortcuts

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