Allow unset 'name' key but print warning if unset (#1208)

* Allow unset name key in config but print warning if unset

* Print deprecation warnings for config to os.Stderr

---------

Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
Daniel Weiße 2023-02-17 09:05:42 +01:00 committed by GitHub
parent d90828cb3c
commit f70447bf7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 4 deletions

View file

@ -11,6 +11,7 @@ import (
"errors"
"fmt"
"io"
"os"
"sort"
"strconv"
"strings"
@ -384,7 +385,7 @@ func validateUpgradeConfig(sl validator.StructLevel) {
if config.Image == "" && config.CSP == cloudprovider.Unknown && config.Measurements == nil {
return
}
fmt.Println("WARNING: the config key `upgrade` will be deprecated in an upcoming version. Please check the documentation for more information.")
fmt.Fprintln(os.Stderr, "WARNING: the config key `upgrade` will be deprecated in an upcoming version. Please check the documentation for more information.")
}
func registerValidateNameError(ut ut.Translator) error {
@ -406,6 +407,12 @@ func (c *Config) translateValidateNameError(ut ut.Translator, fe validator.Field
// Since this value may differ between providers, we can't simply use built-in validation.
// This also allows us to eventually add more validation rules for constellation names if necessary.
func (c *Config) validateName(fl validator.FieldLevel) bool {
// TODO: v2.7: remove fallback to defaultName and make name a required field
if c.Name == "" {
fmt.Fprintln(os.Stderr, "WARNING: the config key `name` is not set. This key will be required in the next version. Falling back to default name.")
c.Name = defaultName
}
if c.Provider.AWS != nil {
return len(fl.Field().String()) <= constants.AWSConstellationNameLength
}