config: Add system section

This commit is contained in:
Daniele Rondina 2019-12-30 21:56:13 +01:00 committed by Ettore Di Giacinto
parent 8b66127016
commit 7f160a7a89
No known key found for this signature in database
GPG Key ID: 1ADA699B145A2D1C
3 changed files with 32 additions and 6 deletions

View File

@ -30,6 +30,7 @@ var configCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
fmt.Println(config.LuetCfg.GetLogging()) fmt.Println(config.LuetCfg.GetLogging())
fmt.Println(config.LuetCfg.GetGeneral()) fmt.Println(config.LuetCfg.GetGeneral())
fmt.Println(config.LuetCfg.GetSystem())
if len(config.LuetCfg.CacheRepositories) > 0 { if len(config.LuetCfg.CacheRepositories) > 0 {
fmt.Println("cache_repositories:") fmt.Println("cache_repositories:")
for _, r := range config.LuetCfg.CacheRepositories { for _, r := range config.LuetCfg.CacheRepositories {

View File

@ -39,6 +39,12 @@ type LuetGeneralConfig struct {
SpinnerCharset int `mapstructure:"spinner_charset"` SpinnerCharset int `mapstructure:"spinner_charset"`
} }
type LuetSystemConfig struct {
DatabaseEngine string `yaml:"database_engine" mapstructure:"database_engine"`
DatabasePath string `yaml:"database_path" mapstructure:"database_path"`
Rootfs string `yaml:"rootfs" mapstructure:"rootfs"`
}
type LuetRepository struct { type LuetRepository struct {
Name string `yaml:"name" mapstructure:"name"` Name string `yaml:"name" mapstructure:"name"`
Description string `yaml:"description,omitempty" mapstructure:"description"` Description string `yaml:"description,omitempty" mapstructure:"description"`
@ -46,6 +52,7 @@ type LuetRepository struct {
Type string `yaml:"type" mapstructure:"type"` Type string `yaml:"type" mapstructure:"type"`
Mode string `yaml:"mode,omitempty" mapstructure:"mode"` Mode string `yaml:"mode,omitempty" mapstructure:"mode"`
Priority int `yaml:"priority,omitempty" mapstructure:"priority"` Priority int `yaml:"priority,omitempty" mapstructure:"priority"`
Enable bool `yaml:"enable" mapstructure:"enable"`
Authentication map[string]string `yaml:"auth,omitempty" mapstructure:"auth"` Authentication map[string]string `yaml:"auth,omitempty" mapstructure:"auth"`
} }
@ -54,6 +61,7 @@ type LuetConfig struct {
Logging LuetLoggingConfig `mapstructure:"logging"` Logging LuetLoggingConfig `mapstructure:"logging"`
General LuetGeneralConfig `mapstructure:"general"` General LuetGeneralConfig `mapstructure:"general"`
System LuetSystemConfig `mapstructure:"system"`
RepositoriesConfDir []string `mapstructure:"repos_confdir"` RepositoriesConfDir []string `mapstructure:"repos_confdir"`
CacheRepositories []LuetRepository `mapstructure:"cache_repositories"` CacheRepositories []LuetRepository `mapstructure:"cache_repositories"`
@ -61,7 +69,7 @@ type LuetConfig struct {
} }
func (r *LuetRepository) String() string { func (r *LuetRepository) String() string {
return fmt.Sprintf("[%s] prio: %d, type: %s", r.Name, r.Priority, r.Type) return fmt.Sprintf("[%s] prio: %d, type: %s, enable: %t", r.Name, r.Priority, r.Type, r.Enable)
} }
func NewLuetConfig(viper *v.Viper) *LuetConfig { func NewLuetConfig(viper *v.Viper) *LuetConfig {
@ -84,6 +92,10 @@ func GenDefault(viper *v.Viper) {
viper.SetDefault("general.spinner_ms", 100) viper.SetDefault("general.spinner_ms", 100)
viper.SetDefault("general.spinner_charset", 22) viper.SetDefault("general.spinner_charset", 22)
viper.SetDefault("system.database_engine", "boltdb")
viper.SetDefault("system.database_path", "/var/cache/luet")
viper.SetDefault("system.rootfs", "/")
viper.SetDefault("repos_confdir", []string{"/etc/luet/repos.conf.d"}) viper.SetDefault("repos_confdir", []string{"/etc/luet/repos.conf.d"})
viper.SetDefault("cache_repositories", []string{}) viper.SetDefault("cache_repositories", []string{})
viper.SetDefault("system_repositories", []string{}) viper.SetDefault("system_repositories", []string{})
@ -101,6 +113,10 @@ func (c *LuetConfig) GetGeneral() *LuetGeneralConfig {
return &c.General return &c.General
} }
func (c *LuetConfig) GetSystem() *LuetSystemConfig {
return &c.System
}
func (c *LuetGeneralConfig) String() string { func (c *LuetGeneralConfig) String() string {
ans := fmt.Sprintf(` ans := fmt.Sprintf(`
general: general:
@ -108,8 +124,7 @@ general:
debug: %t debug: %t
show_build_output: %t show_build_output: %t
spinner_ms: %d spinner_ms: %d
spinner_charset: %d spinner_charset: %d`, c.Concurrency, c.Debug, c.ShowBuildOutput,
`, c.Concurrency, c.Debug, c.ShowBuildOutput,
c.SpinnerMs, c.SpinnerCharset) c.SpinnerMs, c.SpinnerCharset)
return ans return ans
@ -127,8 +142,18 @@ func (c *LuetLoggingConfig) String() string {
ans := fmt.Sprintf(` ans := fmt.Sprintf(`
logging: logging:
path: %s path: %s
level: %s level: %s`, c.Path, c.Level)
`, c.Path, c.Level)
return ans
}
func (c *LuetSystemConfig) String() string {
ans := fmt.Sprintf(`
system:
database_engine: %s
database_path: %s
rootfs: %s`,
c.DatabaseEngine, c.DatabasePath, c.Rootfs)
return ans return ans
} }

View File

@ -76,7 +76,7 @@ func LoadRepositories(c *LuetConfig) error {
} }
func LoadRepository(data []byte) (*LuetRepository, error) { func LoadRepository(data []byte) (*LuetRepository, error) {
ans := &LuetRepository{} ans := &LuetRepository{Enable: false}
err := yaml.Unmarshal(data, &ans) err := yaml.Unmarshal(data, &ans)
if err != nil { if err != nil {
return nil, err return nil, err