cfgssh

package
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrSession        strErr = "%s session: %v"
	ErrSessionAdvRefs strErr = "%s session advertised references: %v"

	ErrAdvRefsEncode   strErr = "%s advertied references encode: %v"
	ErrPackDecode      strErr = "pack decode: %v"
	ErrPackScanAdvRefs strErr = "pack scan [1] advertised references: %v"

	ErrResponseEncode strErr = "%s response encode: %v"
	ErrRequestDecode  strErr = "%s request decode: %v"

	ErrReceivePack strErr = "bad receive pack: %v"
	ErrUploadPack  strErr = "bad upload pack: %v"

	ErrTransportEndpoint strErr = "repo [%s] endpoint invalid: %v"
	ErrEmptyHookData     strErr = "empty receive-pack hook data"
)

returns all of the errors

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(rw ssh.Channel, code uint32)

ExitCode sends a specific exit status back to the SSH channel. If no code is sent then the channel closes with a error code of -1

func NewServer

func NewServer(gs GitServer, opts ...ServerOption) func(*ssh.ServerConn, <-chan ssh.NewChannel, <-chan *ssh.Request, error) error

NewServer returns a function that can wrap a SSH ssh.NewServer() function. It will then handle all requests for SSH

Types

type DebugLogger

type DebugLogger *logg.Logger

DebugLogger wrap *log.Loggers with this to display debug logging

type GitServer

type GitServer interface {
	NewReceivePack(repoName string) ReceivePacker
	NewUploadPack(repoName string) UploadPacker

	WithLogger(...interface{})
	WithPreReceiveHook(cfg.PreReceivePackHookFunc)
	WithPostReceiveHook(cfg.PostReceivePackHookFunc)
}

GitServer is the interface used to interact with the git server via SSH

type GoGitServer

type GoGitServer struct {
	// contains filtered or unexported fields
}

GoGitServer wraps concepts for go-git into a GitServer SSH interface

func LoadGoGit

func LoadGoGit(m map[string]*git.Repository, endpoint string) *GoGitServer

LoadGoGit loads a mapping of git repositories (go-git) to a repository endpoint

func (*GoGitServer) NewReceivePack

func (s *GoGitServer) NewReceivePack(repoName string) ReceivePacker

NewReceivePack returns a new ReceivePack object

func (*GoGitServer) NewUploadPack

func (s *GoGitServer) NewUploadPack(repoName string) UploadPacker

NewUploadPack returns a new UploadPack object

func (*GoGitServer) WithLogger

func (s *GoGitServer) WithLogger(logger ...interface{})

WithLogger takes in logger/s to display debug and info logs for the GoGitServer object

func (*GoGitServer) WithPostReceiveHook

func (s *GoGitServer) WithPostReceiveHook(fn cfg.PostReceivePackHookFunc)

WithPostReceiveHook sets the post-receive hook for receive-pack requests

func (*GoGitServer) WithPreReceiveHook

func (s *GoGitServer) WithPreReceiveHook(fn cfg.PreReceivePackHookFunc)

WithPreReceiveHook sets the pre-receive hook for receive-pack requests

type HandlerFunc

type HandlerFunc func(string, ssh.Channel)

HandlerFunc is an adapter to allow the use of ordinary functions as SSH handlers

type InfoLogger

type InfoLogger *logg.Logger

InfoLogger wrap *log.Loggers with this to display info logging

type Mux

type Mux struct {
	Handlers map[string]HandlerFunc

	NotFoundHandler HandlerFunc
}

Mux holds the handlers and a command associated with it.

func NewMux

func NewMux() *Mux

NewMux returns a new initialized Mux object

func (*Mux) HandlerFunc

func (m *Mux) HandlerFunc(command string, fn HandlerFunc)

HandlerFunc adds a handler with a command to the Mux

type ReceivePack

type ReceivePack struct {
	*GoGitServer
	// contains filtered or unexported fields
}

ReceivePack holds all of the data needed to handle the git interface for receive-pack requests through SSH

func (*ReceivePack) Cleanup

func (rp *ReceivePack) Cleanup()

Cleanup takes any functions that were collected and runs them. This is for deferred processes

func (*ReceivePack) DoSSH

func (rp *ReceivePack) DoSSH(rw ssh.Channel) ReceivePacker

DoSSH takes in a SSH channel and processes what is supposed to happen if there are any errors then this method is skipped, and errors can be checked with the Err() method

func (*ReceivePack) Err

func (rp *ReceivePack) Err() error

Err returns the error that was collected during the receive-pack processing

type ReceivePacker

type ReceivePacker interface {
	DoSSH(ssh.Channel) ReceivePacker
	Cleanup()
	Err() error
}

ReceivePacker returns SSH requests for 'receive-pack'

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server holds the handlers for requests that the git client can make via SSH

func (*Server) ReceivePackHandler

func (s *Server) ReceivePackHandler(repoName string, rw ssh.Channel)

ReceivePackHandler handles SSH calls to 'receive-pack'

func (*Server) ServeSSH

func (s *Server) ServeSSH(chans <-chan ssh.NewChannel, reqs <-chan *ssh.Request, mux *Mux)

ServeSSH provides the internal handling for SSH channels accepted on a connection

func (*Server) UploadPackHandler

func (s *Server) UploadPackHandler(repoName string, rw ssh.Channel)

UploadPackHandler handles SSH calls to 'upload-pack'

func (*Server) WithLogger

func (s *Server) WithLogger(logger ...interface{})

WithLogger takes in logger/s to display debug and info logs for the server object

type ServerOption

type ServerOption func(*Server)

ServerOption is the optional function type used for cfghttp

func WithLogger

func WithLogger(l ...interface{}) ServerOption

WithLogger adds a logger to the library. If *log.Logger is used then both debug and info logs will be populated. wrap a *log.Logger in DebugLogger or InfoLogger to just view the logs for one level

func WithPostReceiveHook

func WithPostReceiveHook(fn func(io.Writer, *cfg.PostReceivePackHookData)) ServerOption

WithPostReceiveHook adds a post-recieve hook to the handler, sending nil to the handler will sucessfully execute the git commad send a non nil error to reject the recieve. All writes the the writer will be done with newlines, otherwise it may be cut off.

func WithPreReceiveHook

WithPreReceiveHook adds a pre-recieve hook to the handler, sending nil to the handler will sucessfully execute the git commad send a non nil error to reject the recieve. All writes the the writer will be done with newlines, otherwise it may be cut off.

type UploadPack

type UploadPack struct {
	*GoGitServer
	// contains filtered or unexported fields
}

UploadPack holds all of the data needed to handle the git interface for upload-pack requests for SSH

func (*UploadPack) Cleanup

func (up *UploadPack) Cleanup()

Cleanup takes any functions that were collected and runs them. This is for deferred processes

func (*UploadPack) DoSSH

func (up *UploadPack) DoSSH(rw ssh.Channel) UploadPacker

DoSSH takes in a ssh channel and decodes what is supposed to happen if there are any errors then this method is skipped, and errors can be checked with the Err() method

func (*UploadPack) Err

func (up *UploadPack) Err() error

Err returns the error that was collected during the upload-pack processing

type UploadPacker

type UploadPacker interface {
	DoSSH(ssh.Channel) UploadPacker
	Cleanup()
	Err() error
}

UploadPacker returns HTTP requests for 'upload-pack'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL