2023-11-17 20:39:00 +03:00
|
|
|
package util
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/config"
|
|
|
|
"github.com/mitchellh/mapstructure"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ValidationAvailable interface {
|
|
|
|
Validate() error
|
|
|
|
}
|
|
|
|
|
|
|
|
func UnmarshalParams(params config.DriverParams, target ValidationAvailable) error {
|
2023-11-20 22:23:58 +03:00
|
|
|
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
|
|
|
|
Result: target,
|
|
|
|
WeaklyTypedInput: true,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := dec.Decode(params); err != nil {
|
2023-11-17 20:39:00 +03:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if val, canValidate := target.(ValidationAvailable); canValidate {
|
|
|
|
return val.Validate()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|