64 lines
1.8 KiB
Go
64 lines
1.8 KiB
Go
package ssh
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/Neur0toxine/sshpoke/internal/server/driver/util"
|
|
)
|
|
|
|
type Params struct {
|
|
Address string `mapstructure:"address" validate:"required"`
|
|
Auth Auth `mapstructure:"auth"`
|
|
KeepAlive KeepAlive `mapstructure:"keepalive"`
|
|
Domain string `mapstructure:"domain"`
|
|
DomainProto string `mapstructure:"domain_proto"`
|
|
DomainExtractRegex string `mapstructure:"domain_extract_regex" validate:"validregexp"`
|
|
Mode DomainMode `mapstructure:"mode" validate:"required,oneof=single multi"`
|
|
Prefix bool `mapstructure:"prefix"`
|
|
}
|
|
|
|
type AuthType string
|
|
|
|
const (
|
|
AuthTypePasswordless AuthType = "passwordless"
|
|
AuthTypePassword AuthType = "password"
|
|
AuthTypeKey AuthType = "key"
|
|
)
|
|
|
|
type DomainMode string
|
|
|
|
const (
|
|
DomainModeSingle DomainMode = "single"
|
|
DomainModeMulti DomainMode = "multi"
|
|
)
|
|
|
|
type Auth struct {
|
|
Type AuthType `mapstructure:"type" validate:"required,oneof=passwordless password key"`
|
|
User string `mapstructure:"user"`
|
|
Password string `mapstructure:"password"`
|
|
Directory string `mapstructure:"directory"`
|
|
Keyfile string `mapstructure:"keyfile"`
|
|
}
|
|
|
|
func (a Auth) validate() error {
|
|
if a.Type == AuthTypePassword && a.Password == "" {
|
|
return fmt.Errorf("password must be provided for authentication type '%s'", AuthTypePassword)
|
|
}
|
|
if a.Type == AuthTypeKey && a.Directory == "" {
|
|
return fmt.Errorf("password must be provided for authentication type '%s'", AuthTypePassword)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
type KeepAlive struct {
|
|
Interval int `mapstructure:"interval" validate:"gte=0"`
|
|
MaxAttempts int `mapstructure:"max_attempts" validate:"gte=1"`
|
|
}
|
|
|
|
func (p *Params) Validate() error {
|
|
if err := util.Validator.Struct(p); err != nil {
|
|
return err
|
|
}
|
|
return p.Auth.validate()
|
|
}
|