SSHSecure/config/validator.go

35 lines
527 B
Go
Raw Normal View History

package config
import (
"fmt"
"github.com/oleiade/reflections"
"github.com/pkg/errors"
)
var err error
func (c *SshdConf) Validate() (bool, error) {
for k, v := range validSshdSingleVals {
realV, err := reflections.GetField(c, k)
if err != nil {
return false, err
}
valid := false
for _, i := range v {
if i == realV {
valid = true
break
}
}
if !valid {
e := fmt.Sprintf(
"field %v value %v is not allowed",
k, realV)
return false, errors.New(e)
}
}
return true, nil
}