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) (*ssh.Permissions, error)
KeygenConfig SSHKeygenConfig
CommandsCallbacks map[string]func(args string) error
// Logger based on the interface defined in sshooks/log
Log log.Log
}
func Listen(config *ServerConfig)
In this example we setup a server responding to the command git-upload-pack
commands (e.g: sent by git clone ssh://git@localhost:1337/dgellow/nanogit.git
). You can read the example program for more details.
func publicKeyHandler(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions, error) {
// Do something with the public key
return &ssh.Permissions{}, nil
}
func handleUploadPack(args string) error {
// Do something with the args
return nil
}
func main() {
logger = &Logger{LogLevel: 0, Prefix: "example"}
commandsHandlers := map[string]func (string) error {
"git-upload-pack": handleUploadPack,
}
config := &sshooks.ServerConfig{
Host: "localhost",
Port: 1337,
PrivatekeyPath: "key.rsa",
KeygenConfig: sshooks.SSHKeygenConfig{"rsa", ""},
PublicKeyCallback: publicKeyHandler,
CommandsCallbacks: commandsHandlers,
Log: logger,
}
sshooks.Listen(config)
// Keep the program running
for {
}
}