chore: add user/password validations

This commit is contained in:
andig 2023-03-19 13:28:26 +01:00
parent 31ab90e638
commit f30725962b
19 changed files with 67 additions and 8 deletions

View file

@ -76,6 +76,10 @@ func NewEaseeFromConfig(other map[string]interface{}) (api.Charger, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
return NewEasee(cc.User, cc.Password, cc.Charger)
}

View file

@ -69,7 +69,7 @@ func NewZaptecFromConfig(other map[string]interface{}) (api.Charger, error) {
}
if cc.User == "" || cc.Password == "" {
return nil, errors.New("need user and password")
return nil, api.ErrMissingCredentials
}
return NewZaptec(cc.User, cc.Password, cc.Id, cc.Priority, cc.Cache)

View file

@ -51,7 +51,7 @@ func TestClass(t *testing.T, class Class, instantiate func(t *testing.T, values
} else {
values[ModbusKeyRS485TCPIP] = true
}
tmpl.ModbusValues(TemplateRenderModeInstance, values)
tmpl.ModbusValues(TemplateRenderModeUnitTest, values)
}
usages := tmpl.Usages()

View file

@ -198,14 +198,14 @@ type Param struct {
ID int `json:"-"` // device specific default for modbus ID
}
// return a default value or example value depending on the renderMode
// DefaultValue returns a default or example value depending on the renderMode
func (p *Param) DefaultValue(renderMode string) interface{} {
// return empty list to allow iterating over in template
if p.Type == TypeStringList {
return []string{}
}
if renderMode == TemplateRenderModeDocs && p.Default == "" {
if (renderMode == TemplateRenderModeDocs || renderMode == TemplateRenderModeUnitTest) && p.Default == "" {
return p.Example
}

View file

@ -39,6 +39,10 @@ func NewAiwaysFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Aiways{
embed: &cc.embed,
}

View file

@ -43,6 +43,10 @@ func NewEtronFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Etron{
embed: &cc.embed,
}

View file

@ -41,6 +41,10 @@ func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Audi{
embed: &cc.embed,
}

View file

@ -44,8 +44,12 @@ func NewNiuFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" || cc.Serial == "" {
return nil, errors.New("missing user, password or serial")
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
if cc.Serial == "" {
return nil, errors.New("missing serial")
}
log := util.NewLogger("niu").Redact(cc.User, cc.Password)

View file

@ -51,6 +51,10 @@ func NewRenaultDaciaFromConfig(brand string, other map[string]interface{}) (api.
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
log := util.NewLogger(brand).Redact(cc.User, cc.Password, cc.VIN)
v := &Renault{

View file

@ -41,6 +41,10 @@ func NewCupraFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Cupra{
embed: &cc.embed,
}

View file

@ -41,6 +41,10 @@ func NewSeatFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Seat{
embed: &cc.embed,
}

View file

@ -1,7 +1,6 @@
package vehicle
import (
"errors"
"strings"
"time"
@ -37,7 +36,7 @@ func NewSilenceFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}
if cc.User == "" || cc.Password == "" {
return nil, errors.New("missing user or password")
return nil, api.ErrMissingCredentials
}
log := util.NewLogger("s01").Redact(cc.User, cc.Password)

View file

@ -39,6 +39,10 @@ func NewEnyaqFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Enyaq{
embed: &cc.embed,
}

View file

@ -41,6 +41,10 @@ func NewSkodaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &Skoda{
embed: &cc.embed,
}

View file

@ -37,6 +37,10 @@ func NewSmartFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
log := util.NewLogger("smart").Redact(cc.User, cc.Password, cc.VIN)
v := &Smart{

View file

@ -36,6 +36,10 @@ func NewVolvoConnectedFromConfig(other map[string]interface{}) (api.Vehicle, err
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
// if cc.ClientID == "" && cc.ClientSecret == "" {
// return nil, errors.New("missing credentials")
// }

View file

@ -38,6 +38,10 @@ func NewVolvoFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
basicAuth := transport.BasicAuthHeader(cc.User, cc.Password)
log := util.NewLogger("volvo").Redact(cc.User, cc.Password, cc.VIN, basicAuth)

View file

@ -39,6 +39,10 @@ func NewIDFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &ID{
embed: &cc.embed,
}

View file

@ -40,6 +40,10 @@ func NewVWFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}
if cc.User == "" || cc.Password == "" {
return nil, api.ErrMissingCredentials
}
v := &VW{
embed: &cc.embed,
}