feat: allow to override model config (#323)

This commit is contained in:
Ettore Di Giacinto 2023-05-20 17:03:53 +02:00 committed by GitHub
parent 7bc08797f9
commit 05a3d569b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 269 additions and 64 deletions

View file

@ -8,6 +8,7 @@ import (
"os"
"path/filepath"
"github.com/imdario/mergo"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v2"
)
@ -92,13 +93,17 @@ func verifyPath(path, basePath string) error {
return inTrustedRoot(c, basePath)
}
func Apply(basePath, nameOverride string, config *Config) error {
func Apply(basePath, nameOverride string, config *Config, configOverrides map[string]interface{}) error {
// Create base path if it doesn't exist
err := os.MkdirAll(basePath, 0755)
if err != nil {
return fmt.Errorf("failed to create base path: %v", err)
}
if len(configOverrides) > 0 {
log.Debug().Msgf("Config overrides %+v", configOverrides)
}
// Download files and verify their SHA
for _, file := range config.Files {
log.Debug().Msgf("Checking %q exists and matches SHA", file.Filename)
@ -231,6 +236,10 @@ func Apply(basePath, nameOverride string, config *Config) error {
configMap["name"] = name
if err := mergo.Merge(&configMap, configOverrides, mergo.WithOverride); err != nil {
return err
}
// Write updated config file
updatedConfigYAML, err := yaml.Marshal(configMap)
if err != nil {