2023-07-20 09:26:25 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
2023-10-12 09:53:58 +00:00
|
|
|
"git.badhouseplants.net/allanger/shoebill/pkg/cluster"
|
|
|
|
"git.badhouseplants.net/allanger/shoebill/pkg/release"
|
|
|
|
"git.badhouseplants.net/allanger/shoebill/pkg/repository"
|
2023-07-20 09:26:25 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Repositories repository.Repositories
|
|
|
|
Releases release.Releases
|
|
|
|
Clusters cluster.Clusters
|
2023-09-22 11:02:56 +00:00
|
|
|
ConfigPath string `yaml:"-"`
|
2023-10-11 12:14:20 +00:00
|
|
|
SopsBin string `yaml:"-"`
|
2023-07-20 09:26:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfigFromFile populates the config struct from a configuration yaml file
|
|
|
|
func NewConfigFromFile(path string) (*Config, error) {
|
|
|
|
var config Config
|
2023-10-11 12:14:20 +00:00
|
|
|
logrus.Infof("readig the config file: %s", path)
|
2023-07-20 09:26:25 +00:00
|
|
|
configFile, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if err := yaml.Unmarshal(configFile, &config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2023-09-22 11:02:56 +00:00
|
|
|
config.ConfigPath = path
|
2023-07-20 09:26:25 +00:00
|
|
|
return &config, nil
|
|
|
|
}
|