Setup: warn on illegal names
This commit is contained in:
parent
f8a10aecd6
commit
042a472aa9
1 changed files with 19 additions and 4 deletions
23
cmd/setup.go
23
cmd/setup.go
|
|
@ -153,6 +153,13 @@ func (c networkConfig) URI() string {
|
|||
return fmt.Sprintf("%s://%s", c.Schema, c.HostPort())
|
||||
}
|
||||
|
||||
func nameValid(name string) error {
|
||||
if !nameRE.MatchString(name) {
|
||||
return fmt.Errorf("name must not contain special characters or spaces: %s", name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadConfigFile(conf *globalConfig) error {
|
||||
err := viper.ReadInConfig()
|
||||
|
||||
|
|
@ -186,6 +193,10 @@ func configureMeters(static []config.Named, names ...string) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if err := nameValid(cc.Name); err != nil {
|
||||
log.WARN.Printf("create meter %d: %v", i+1, err)
|
||||
}
|
||||
|
||||
instance, err := meter.NewFromConfig(cc.Type, cc.Other)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot create meter '%s': %w", cc.Name, err)
|
||||
|
|
@ -234,6 +245,10 @@ func configureChargers(static []config.Named, names ...string) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if err := nameValid(cc.Name); err != nil {
|
||||
log.WARN.Printf("create charger %d: %v", i+1, err)
|
||||
}
|
||||
|
||||
g.Go(func() error {
|
||||
instance, err := charger.NewFromConfig(cc.Type, cc.Other)
|
||||
if err != nil {
|
||||
|
|
@ -271,10 +286,6 @@ func configureChargers(static []config.Named, names ...string) error {
|
|||
}
|
||||
|
||||
func vehicleInstance(cc config.Named) (api.Vehicle, error) {
|
||||
if !nameRE.MatchString(cc.Name) {
|
||||
return nil, fmt.Errorf("vehicle name must not contain special characters or spaces: %s", cc.Name)
|
||||
}
|
||||
|
||||
instance, err := vehicle.NewFromConfig(cc.Type, cc.Other)
|
||||
if err != nil {
|
||||
var ce *util.ConfigError
|
||||
|
|
@ -312,6 +323,10 @@ func configureVehicles(static []config.Named, names ...string) error {
|
|||
continue
|
||||
}
|
||||
|
||||
if err := nameValid(cc.Name); err != nil {
|
||||
return fmt.Errorf("cannot create vehicle %d: %w", i+1, err)
|
||||
}
|
||||
|
||||
g.Go(func() error {
|
||||
instance, err := vehicleInstance(cc)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue