Documentation ¶
Index ¶
- Constants
- Variables
- func ConfigDir() string
- func ConfigFile() string
- func DataDir() string
- func HostsConfigFile() string
- func NewBlankRoot() *yaml.Node
- func StateDir() string
- func StubBackupConfig() func()
- func StubWriteConfig(wc io.Writer, wh io.Writer) func()
- func ValidateKey(key string) error
- func ValidateValue(key, value string) error
- type Config
- type ConfigEntry
- type ConfigMap
- func (cm *ConfigMap) Empty() bool
- func (cm *ConfigMap) FindEntry(key string) (ce *ConfigEntry, err error)
- func (cm *ConfigMap) GetOptionalStringValue(key string) string
- func (cm *ConfigMap) GetStringValue(key string) (string, error)
- func (cm *ConfigMap) RemoveEntry(key string)
- func (cm *ConfigMap) SetStringValue(key, value string) error
- type ConfigOption
- type ConfigStub
- func (c ConfigStub) CheckWriteable(host, key string) error
- func (c ConfigStub) DefaultHost() (string, error)
- func (c ConfigStub) DefaultHostWithSource() (string, string, error)
- func (c ConfigStub) DefaultHostname() string
- func (c ConfigStub) Get(host, key string) (string, error)
- func (c ConfigStub) GetWithSource(host, key string) (string, string, error)
- func (c ConfigStub) HostEntries() ([]*HostConfig, error)
- func (c ConfigStub) Hosts() ([]string, error)
- func (c ConfigStub) HostsTyped() ([]HostConfigTyped, error)
- func (c ConfigStub) MakeConfigForHost(hostname string) *HostConfig
- func (c ConfigStub) SaveTyped(host *HostConfigTyped) error
- func (c ConfigStub) Set(host, key, value string) error
- func (c ConfigStub) UnsetHost(hostname string) error
- func (c ConfigStub) Write() error
- type HostConfig
- type HostConfigMock
- type HostConfigTyped
- type InvalidValueError
- type NotFoundError
Constants ¶
const ( INSTILL_CONFIG_DIR = "INSTILL_CONFIG_DIR" XDG_CONFIG_HOME = "XDG_CONFIG_HOME" XDG_STATE_HOME = "XDG_STATE_HOME" XDG_DATA_HOME = "XDG_DATA_HOME" APP_DATA = "AppData" LOCAL_APP_DATA = "LocalAppData" )
Variables ¶
var BackupConfigFile = func(filename string) error { return os.Rename(filename, filename+".bak") }
var ReadConfigFile = func(filename string) ([]byte, error) { f, err := os.Open(filename) if err != nil { return nil, pathError(err) } defer f.Close() data, err := io.ReadAll(f) if err != nil { return nil, err } return data, nil }
var WriteConfigFile = func(filename string, data []byte) error { err := os.MkdirAll(filepath.Dir(filename), 0771) if err != nil { return pathError(err) } cfgFile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } defer cfgFile.Close() _, err = cfgFile.Write(data) return err }
Functions ¶
func ConfigDir ¶
func ConfigDir() string
ConfigDir returns config dirpath with precedence: 1. INSTILL_CONFIG_DIR 2. XDG_CONFIG_HOME 3. AppData (windows only) 4. HOME
func ConfigFile ¶
func ConfigFile() string
func DataDir ¶
func DataDir() string
DataDir returns data dirpath with precedence: 1. XDG_DATA_HOME 2. LocalAppData (windows only) 3. HOME
func HostsConfigFile ¶
func HostsConfigFile() string
func NewBlankRoot ¶
func NewBlankRoot() *yaml.Node
func StateDir ¶
func StateDir() string
StateDir returns state dirpath with precedence: 1. XDG_CONFIG_HOME 2. LocalAppData (windows only) 3. HOME
func StubBackupConfig ¶
func StubBackupConfig() func()
func ValidateKey ¶
func ValidateValue ¶
Types ¶
type Config ¶
type Config interface { Get(string, string) (string, error) GetWithSource(string, string) (string, string, error) Set(string, string, string) error UnsetHost(string) error Hosts() ([]string, error) HostsTyped() ([]HostConfigTyped, error) HostEntries() ([]*HostConfig, error) DefaultHostname() string CheckWriteable(string, string) error Write() error SaveTyped(*HostConfigTyped) error MakeConfigForHost(hostname string) *HostConfig }
Config is the interface describes interacting with some persistent configuration for inst.
func ConfigStubFactory ¶
func NewBlankConfig ¶
func NewBlankConfig() Config
NewBlankConfig initializes a config file pre-populated with comments and default values
func NewFromString ¶
NewFromString initializes a Config from a yaml string
func ParseDefaultConfig ¶
type ConfigEntry ¶
type ConfigEntry struct { KeyNode *yaml.Node ValueNode *yaml.Node Index int }
type ConfigMap ¶
type ConfigMap struct {
Root *yaml.Node
}
This type implements a low-level get/set config that is backed by an in-memory tree of Yaml nodes. It allows us to interact with a yaml-based config programmatically, preserving any comments that were present when the yaml was parsed.
func (*ConfigMap) FindEntry ¶
func (cm *ConfigMap) FindEntry(key string) (ce *ConfigEntry, err error)
func (*ConfigMap) GetOptionalStringValue ¶
func (*ConfigMap) RemoveEntry ¶
func (*ConfigMap) SetStringValue ¶
type ConfigOption ¶
type ConfigOption struct { Key string Description string DefaultValue string AllowedValues []string }
func ConfigOptions ¶
func ConfigOptions() []ConfigOption
type ConfigStub ¶
func (ConfigStub) CheckWriteable ¶
func (c ConfigStub) CheckWriteable(host, key string) error
func (ConfigStub) DefaultHost ¶
func (c ConfigStub) DefaultHost() (string, error)
func (ConfigStub) DefaultHostWithSource ¶
func (c ConfigStub) DefaultHostWithSource() (string, string, error)
func (ConfigStub) DefaultHostname ¶
func (c ConfigStub) DefaultHostname() string
func (ConfigStub) GetWithSource ¶
func (c ConfigStub) GetWithSource(host, key string) (string, string, error)
func (ConfigStub) HostEntries ¶
func (c ConfigStub) HostEntries() ([]*HostConfig, error)
func (ConfigStub) Hosts ¶
func (c ConfigStub) Hosts() ([]string, error)
func (ConfigStub) HostsTyped ¶
func (c ConfigStub) HostsTyped() ([]HostConfigTyped, error)
func (ConfigStub) MakeConfigForHost ¶
func (c ConfigStub) MakeConfigForHost(hostname string) *HostConfig
func (ConfigStub) SaveTyped ¶
func (c ConfigStub) SaveTyped(host *HostConfigTyped) error
func (ConfigStub) Set ¶
func (c ConfigStub) Set(host, key, value string) error
func (ConfigStub) UnsetHost ¶
func (c ConfigStub) UnsetHost(hostname string) error
func (ConfigStub) Write ¶
func (c ConfigStub) Write() error
type HostConfig ¶
type HostConfigMock ¶
type HostConfigMock struct {
HostConfig
}
type HostConfigTyped ¶
type HostConfigTyped struct { // instance info APIHostname string `example:"api.instill.tech"` IsDefault bool APIVersion string `example:"v1alpha"` // oauth config Oauth2Hostname string `example:"auth.instill.tech"` Oauth2Audience string `example:"https://instill.tech"` Oauth2Issuer string `example:"https://auth.instill.tech/"` Oauth2ClientSecret string Oauth2ClientID string // oauth token TokenType string AccessToken string Expiry string RefreshToken string IDToken string }
HostConfigTyped is a type safe representation of an instance config. TODO keep in sync with `hostConfigToTyped` TODO bind directly to yaml via struct tags TODO validation
func DefaultHostConfig ¶
func DefaultHostConfig() HostConfigTyped
DefaultHostConfig returns default values for an instance config, as a single "source of truth" for other packages.
type InvalidValueError ¶
type InvalidValueError struct {
ValidValues []string
}
func (InvalidValueError) Error ¶
func (e InvalidValueError) Error() string
type NotFoundError ¶
type NotFoundError struct {
// contains filtered or unexported fields
}