Skip to content

Latest commit

 

History

History
80 lines (63 loc) · 2.16 KB

README.md

File metadata and controls

80 lines (63 loc) · 2.16 KB

Build Status Coverage Status Go Report Card

sshooks - React to ssh commands

API

struct SSHKeygenConfig

type SSHKeygenConfig struct {
	// Default to rsa
	Type string
	// Default to no password (empty string)
	Passphrase string
}

struct ServerConfig

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

func Listen(config *ServerConfig)

Example

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 {
	}
}