agent

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2019 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAgentPort = 2222
)

Variables

This section is empty.

Functions

func EnvKeyEscape

func EnvKeyEscape(s string) string

func LookupGroup

func LookupGroup(id string) (int, error)

func LookupUser

func LookupUser(id string) (int, error)

func LookupUserStruct

func LookupUserStruct(id string) (*user.User, error)

func NewAgentListener

func NewAgentListener(sess *Session) (net.Listener, string, error)

I borrowed this code from https://github.com/gliderlabs/ssh/blob/47df570d18ad49f77cf66f76bc3fce3e92400768/agent.go#L38 And modify code to remove temporary directory after closing

func ShellEscape

func ShellEscape(s string) string

func Start

func Start(configFile string) error

Types

type Agent

type Agent struct {
	Config         *Config
	Logger         *log.Logger
	SessionManager *SessionManager
}

func NewAgent

func NewAgent(config *Config) *Agent

func (*Agent) Close

func (a *Agent) Close()

func (*Agent) CreateSandBoxDirIfNotExist

func (a *Agent) CreateSandBoxDirIfNotExist(sess *Session) (string, error)

func (*Agent) LookupFunction added in v0.17.0

func (a *Agent) LookupFunction(name string) *FunctionConfig

func (*Agent) SandboxDir added in v0.17.0

func (a *Agent) SandboxDir(sess *Session) string

func (*Agent) Start

func (a *Agent) Start() error

type Config

type Config struct {
	LogLevel           string                     `toml:"log_level" json:"log_level"`
	Addr               string                     `toml:"addr" json:"addr"`
	AuthorizedKeysFile string                     `toml:"authorized_keys_file" json:"authorized_keys_file"`
	AuthorizedKeys     []string                   `toml:"authorized_keys" json:"authorized_keys"`
	DisableLocalAuth   bool                       `toml:"disable_local_auth" json:"disable_local_auth"`
	HostKeyFile        string                     `toml:"host_key_file" json:"-"`
	HostKey            string                     `toml:"host_key" json:"-"`
	SandboxesDirectory string                     `toml:"sandboxes_directory" json:"sandboxes_directory"`
	KeepSandboxes      int                        `toml:"keep_sandboxes" json:"keep_sandboxes"`
	Environment        []string                   `toml:"environment" json:"environment"`
	EnvironmentFile    string                     `toml:"environment_file" json:"environment_file"`
	HotReload          bool                       `toml:"hot_reload" json:"hot_reload"`
	Functions          map[string]*FunctionConfig `toml:"functions" json:"services"`
	Include            *IncludeConfig             `toml:"include" json:"include"`
	// contains filtered or unexported fields
}

func NewConfig

func NewConfig() *Config

func (*Config) LoadConfigFile

func (c *Config) LoadConfigFile(path string) error

func (*Config) Reload

func (c *Config) Reload() (*Config, error)

type FunctionConfig added in v0.17.0

type FunctionConfig struct {
	// name
	Name string `toml:"-" json:"name"`
	// AuthorizedKeysFile
	AuthorizedKeysFile *string `toml:"authorized_keys_file" json:"authorized_keys_file"`
	// AuthorizedKeys
	AuthorizedKeys []string `toml:"authorized_keys" json:"authorized_keys"`
	// User
	User string `toml:"user" json:"user"`
	// Group
	Group string `toml:"group" json:"group"`
	// Entrypoint
	Entrypoint []string `toml:"entrypoint" json:"entrypoint"`
	// Command
	Command []string `toml:"command" json:"command"`
	// MaxProcesses
	MaxProcesses int `toml:"max_processes" json:"max_processes"`
	// Timeout
	Timeout int64 `toml:"timeout" json:"timeout"`
}

type IncludeConfig added in v0.17.0

type IncludeConfig struct {
	Files []string `toml:"files" json:"files"`
}

type Session

type Session struct {
	ssh.Session
	ID                   string
	Sandbox              string
	Agt                  *Agent
	Uid                  int
	Gid                  int
	UserStruct           *user.User
	ForwardAgentListener net.Listener
	Fn                   *FunctionConfig
}

func NewSession

func NewSession(a *Agent, sshSession ssh.Session) *Session

func (*Session) First

func (sess *Session) First() string

func (*Session) JSON

func (sess *Session) JSON(i interface{}) error

func (*Session) JSONPretty

func (sess *Session) JSONPretty(i interface{}) error

func (*Session) String

func (sess *Session) String(in string) error

func (*Session) Stringf

func (sess *Session) Stringf(format string, a ...interface{}) error

func (*Session) Terminate

func (sess *Session) Terminate()

type SessionManager

type SessionManager struct {
	Agt        *Agent
	Sessions   map[string]*Session
	FnSessions map[string]map[string]*Session
	// contains filtered or unexported fields
}

func NewSessionManager

func NewSessionManager(a *Agent) *SessionManager

func (*SessionManager) HasSession

func (m *SessionManager) HasSession(sessionID string) bool

func (*SessionManager) IsActiveSandbox

func (m *SessionManager) IsActiveSandbox(sandbox string) bool

func (*SessionManager) RemoveOldSandboxes

func (m *SessionManager) RemoveOldSandboxes()

func (*SessionManager) RemoveSession

func (m *SessionManager) RemoveSession(sess *Session)

func (*SessionManager) SetSession

func (m *SessionManager) SetSession(sess *Session) error

Directories

Path Synopsis
This code is highly inspired by https://github.com/joho/godotenv Copyright (c) 2013 John Barton MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
This code is highly inspired by https://github.com/joho/godotenv Copyright (c) 2013 John Barton MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

Jump to

Keyboard shortcuts

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