Skip to content
Snippets Groups Projects
config.go 1.35 KiB
Newer Older
package runner

import (
	"github.com/spf13/viper"
)

Florent Aide's avatar
Florent Aide committed
// Variable ...
type Variable struct {
	Name  string `mapstructure:"name"`
	Value string `mapstructure:"value"`
}

Florent Aide's avatar
Florent Aide committed
// Value ...
type Value struct {
	Key   string `mapstructure:"key"`
	Value string `mapstructure:"value"`
type HelmChart struct {
Florent Aide's avatar
Florent Aide committed
	Type   string      `mapstructure:"type"`
	Name   string      `mapstructure:"name"`
	Values interface{} `mapstructure:"values"`
}

type YttChart struct {
	Type   string  `mapstructure:"type"`
	Name   string  `mapstructure:"name"`
	Values []Value `mapstructure:"values"`
}

type Charts struct {
	Helm map[string]HelmChart `mapstructure:"helm"`
	Ytt  map[string]YttChart  `mapstructure:"ytt"`
}

Florent Aide's avatar
Florent Aide committed
// Spec ...
type Spec struct {
	Variables []Variable `mapstructure:"variables"`
	Charts    Charts     `mapstructure:"charts"`
Florent Aide's avatar
Florent Aide committed
}

// Config is the configuration we get after parsing our beaver.yml file
type Config struct {
	APIVersion string `mapstructure:"apiVersion"`
	Kind       string `mapstructure:"kind"`
	Spec       Spec   `mapstructure:"spec"`
}

Florent Aide's avatar
Florent Aide committed
// NewConfig returns a *Config
steeve.chailloux's avatar
steeve.chailloux committed
func NewConfig(configDir string) (*Config, error) {
	v := viper.New()
	v.SetConfigName("beaver")
	v.AddConfigPath(configDir)
	if err := v.ReadInConfig(); err != nil {
		return nil, err
	}
	var config Config
Florent Aide's avatar
Florent Aide committed
	cfg := &config
steeve.chailloux's avatar
steeve.chailloux committed
	if err := v.Unmarshal(&cfg); err != nil {
Florent Aide's avatar
Florent Aide committed

	return cfg, nil
}