-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserverconf.go
47 lines (42 loc) · 1.05 KB
/
serverconf.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package sshooks
import (
"os/exec"
"github.com/dgellow/sshooks/errors"
"github.com/dgellow/sshooks/log"
"golang.org/x/crypto/ssh"
)
type SSHKeygenConfig struct {
// Default to rsa
Type string
// Default to no password (empty string)
Passphrase string
}
type ServerConfig struct {
// Default to localhost
Host string
Port uint
PrivatekeyPath string
PublicKeyCallback func(conn ssh.ConnMetadata, key ssh.PublicKey) (keyId string, err error)
KeygenConfig SSHKeygenConfig
CommandsCallbacks map[string]func(keyId string, cmd string, args string) (*exec.Cmd, error)
// Logger based on the interface defined in sshooks/log
Log log.Log
}
func (sc *ServerConfig) Validate() error {
if sc.PublicKeyCallback == nil {
return errors.ErrNoPubKeyCallback
}
if sc.CommandsCallbacks == nil {
return errors.ErrNoCmdsCallbacks
}
if sc.PrivatekeyPath == "" {
return errors.ErrEmptyPrivKeyPath
}
if sc.KeygenConfig.Type == "" {
sc.KeygenConfig.Passphrase = "rsa"
}
if sc.Host == "" {
sc.Host = "localhost"
}
return nil
}