agent

package
v0.0.0-...-fb9536f Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2016 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PROD_URL = "https://www.appcanary.com"
	DEV_URL  = "http://localhost:4000"

	DEFAULT_CONF_PATH = "/etc/appcanary/"
	DEFAULT_CONF_FILE = DEFAULT_CONF_PATH + "agent.conf"
	DEFAULT_VAR_PATH  = "/var/db/appcanary/"
	DEFAULT_VAR_FILE  = DEFAULT_VAR_PATH + "server.conf"

	DEFAULT_HEARTBEAT_DURATION = 1 * time.Hour
	DEV_HEARTBEAT_DURATION     = 10 * time.Second

	DEFAULT_SYNC_ALL_DURATION = 24 * time.Hour
	DEV_SYNC_ALL_DURATION     = 30 * time.Second

	DEFAULT_LOG_FILE = "/var/log/appcanary.log"
)

env vars

View Source
const (
	API_VERSION   = "/api/v1/agent/"
	API_HEARTBEAT = API_VERSION + "heartbeat"
	API_SERVERS   = API_VERSION + "servers"
)

api endpoints

View Source
const (
	DEFAULT_POLL_SLEEP = 5 * time.Minute
	// test env.PollSleep is 1second
	// test poll sleep is double to give the fs time to flush
	DEV_POLL_SLEEP  = time.Second
	TEST_POLL_SLEEP = (time.Second + (150 * time.Millisecond)) * 2
)

file polling

View Source
const (

                                                                                
                                                                                
     __     _____   _____     ___     __      ___      __     _ __   __  __     
   /'__` + "`" + `\  /\ '__` + "`" + `\/\ '__` + "`" + `\  /'___\ /'__` + "`" + `\  /' _ ` + "`" + `\  /'__` + "`" + `\  /\` + "`" + `'__\/\ \/\ \    
  /\ \L\.\_\ \ \L\ \ \ \L\ \/\ \__//\ \L\.\_/\ \/\ \/\ \L\.\_\ \ \/ \ \ \_\ \   
  \ \__/.\_\\ \ ,__/\ \ ,__/\ \____\ \__/.\_\ \_\ \_\ \__/.\_\\ \_\  \/` + "`" + `____ \  
   \/__/\/_/ \ \ \/  \ \ \/  \/____/\/__/\/_/\/_/\/_/\/__/\/_/ \/_/   ` + "`" + `/___/> \ 
              \ \_\   \ \_\                                              /\___/ 
               \/_/    \/_/                                              \/__/  
                                                                                
                                                                                
`
)

trolol

Variables

View Source
var (
	ErrApi        = errors.New("api error")
	ErrDeprecated = errors.New("api deprecated")
)
View Source
var CanaryVersion string
View Source
var DEV_CONF_FILE string
View Source
var DEV_CONF_PATH string

consts can't be outputs of functions?

View Source
var DEV_VAR_FILE string
View Source
var DEV_VAR_PATH string

Functions

func ApiHeartbeatPath

func ApiHeartbeatPath(ident string) string

func ApiPath

func ApiPath(resource string) string

func ApiServerPath

func ApiServerPath(ident string) string

func ApiServersPath

func ApiServersPath() string

func FetchLog

func FetchLog() *logging.Logger

func InitEnv

func InitEnv(env_str string)

func InitLogging

func InitLogging()

Types

type Agent

type Agent struct {
	DoneChannel chan os.Signal
	// contains filtered or unexported fields
}

func NewAgent

func NewAgent(version string, conf *Conf, clients ...Client) *Agent

func (*Agent) BuildAndSyncWatchers

func (agent *Agent) BuildAndSyncWatchers()

func (*Agent) CloseWatches

func (agent *Agent) CloseWatches()

This has to be called before exiting

func (*Agent) FirstRun

func (agent *Agent) FirstRun() bool

func (*Agent) Heartbeat

func (agent *Agent) Heartbeat() error

func (*Agent) OnChange

func (agent *Agent) OnChange(file Watcher)

func (*Agent) PerformUpgrade

func (agent *Agent) PerformUpgrade()

func (*Agent) RegisterServer

func (agent *Agent) RegisterServer() error

func (*Agent) StartPolling

func (agent *Agent) StartPolling()

instantiate structs, fs hook

func (*Agent) SyncAllFiles

func (agent *Agent) SyncAllFiles()

type CanaryClient

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

func NewClient

func NewClient(apiKey string, server *Server) *CanaryClient

func (*CanaryClient) CreateServer

func (c *CanaryClient) CreateServer(srv *Server) (string, error)

func (*CanaryClient) FetchUpgradeablePackages

func (client *CanaryClient) FetchUpgradeablePackages() (map[string]string, error)

func (*CanaryClient) Heartbeat

func (client *CanaryClient) Heartbeat(uuid string, files Watchers) error

func (*CanaryClient) SendFile

func (client *CanaryClient) SendFile(path string, kind string, contents []byte) error

type ChangeHandler

type ChangeHandler func(Watcher)

type Client

type Client interface {
	Heartbeat(string, Watchers) error
	SendFile(string, string, []byte) error
	CreateServer(*Server) (string, error)
	FetchUpgradeablePackages() (map[string]string, error)
}

type Conf

type Conf struct {
	ApiKey     string `toml:"api_key"`
	LogPath    string `toml:"log_path"`
	ServerName string `toml:"server_name"`
	detect.LinuxOSInfo
	Files      []*FileConf `toml:"files"`
	ServerConf *ServerConf `toml:"-"`
}

func NewConf

func NewConf() *Conf

func NewConfFromEnv

func NewConfFromEnv() *Conf

func (*Conf) OSInfo

func (c *Conf) OSInfo() *detect.LinuxOSInfo

func (*Conf) Save

func (c *Conf) Save()

type Env

type Env struct {
	Env               string
	Prod              bool
	DryRun            bool
	FailOnConflict    bool
	BaseUrl           string
	ConfFile          string
	VarFile           string
	LogFile           string
	LogFileHandle     *os.File
	HeartbeatDuration time.Duration
	SyncAllDuration   time.Duration
	PollSleep         time.Duration
}

func FetchEnv

func FetchEnv() *Env

type FileConf

type FileConf struct {
	Path    string `toml:"path"`
	Process string `toml:"process"`
}

type MockClient

type MockClient struct {
	mock.Mock
}

func (*MockClient) CreateServer

func (m *MockClient) CreateServer(_a0 *Server) (string, error)

func (*MockClient) FetchUpgradeablePackages

func (m *MockClient) FetchUpgradeablePackages() (map[string]string, error)

func (*MockClient) Heartbeat

func (m *MockClient) Heartbeat(_a0 string, _a1 Watchers) error

func (*MockClient) SendFile

func (m *MockClient) SendFile(_a0 string, _a1 string, _a2 []byte) error

type Server

type Server struct {
	Hostname string `json:"hostname"`
	Uname    string `json:"uname"`
	Ip       string `json:"ip"`
	Name     string `json:"name"`
	UUID     string `json:"uuid,omitempty"`
	Distro   string `json:"distro,omitempty"`
	Release  string `json:"release,omitempty"`
}

func NewServer

func NewServer(agentConf *Conf, conf *ServerConf) *Server

Creates a new server and syncs conf if needed

func (*Server) IsNew

func (server *Server) IsNew() bool

func (*Server) IsUbuntu

func (server *Server) IsUbuntu() bool

type ServerConf

type ServerConf struct {
	UUID string `toml:"uuid"`
}

type UpgradeCommand

type UpgradeCommand struct {
	Name string
	Args []string
}

type UpgradeSequence

type UpgradeSequence []UpgradeCommand

type Watcher

type Watcher interface {
	Start()
	Stop()
	Contents() ([]byte, error)
	Path() string
	Kind() string
	MarshalJSON() ([]byte, error)
}

func NewFileWatcher

func NewFileWatcher(path string, callback ChangeHandler) Watcher

only used for tests

func NewFileWatcherWithHook

func NewFileWatcherWithHook(path string, callback ChangeHandler) Watcher

TODO: time.Now() needs to be called whenever it updates

func NewProcessWatcher

func NewProcessWatcher(process string, callback ChangeHandler) Watcher

func NewProcessWatcherWithHook

func NewProcessWatcherWithHook(path string, callback ChangeHandler) Watcher

type Watchers

type Watchers []Watcher

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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