Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions core/config/backend_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,15 @@ func (c *BackendConfig) UnmarshalYAML(value *yaml.Node) error {
return err
}
*c = BackendConfig(aux)

c.KnownUsecases = GetUsecasesFromYAML(c.KnownUsecaseStrings)
// Make sure the usecases are valid, we rewrite with what we identified
c.KnownUsecaseStrings = []string{}
for k, usecase := range GetAllBackendConfigUsecases() {
if c.HasUsecases(usecase) {
c.KnownUsecaseStrings = append(c.KnownUsecaseStrings, k)
}
}
return nil
}

Expand Down Expand Up @@ -410,15 +418,6 @@ func (cfg *BackendConfig) SetDefaults(opts ...ConfigLoaderOption) {
cfg.Debug = &trueV
}

if len(cfg.KnownUsecaseStrings) == 0 {
// Infer use case if not provided
for k, usecase := range GetAllBackendConfigUsecases() {
if cfg.HasUsecases(usecase) {
cfg.KnownUsecaseStrings = append(cfg.KnownUsecaseStrings, k)
}
}
}

guessDefaultsFromFile(cfg, lo.modelPath)
}

Expand Down Expand Up @@ -491,14 +490,18 @@ func GetAllBackendConfigUsecases() map[string]BackendConfigUsecases {
}
}

func stringToFlag(s string) string {
return "FLAG_" + strings.ToUpper(s)
}

func GetUsecasesFromYAML(input []string) *BackendConfigUsecases {
if len(input) == 0 {
return nil
}
result := FLAG_ANY
flags := GetAllBackendConfigUsecases()
for _, str := range input {
flag, exists := flags["FLAG_"+strings.ToUpper(str)]
flag, exists := flags[stringToFlag(str)]
if exists {
result |= flag
}
Expand Down
Loading