kelpos

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 16 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BotInstance

type BotInstance struct {
	Bot   *model2.Bot
	State BotState
}

BotInstance is an instance of a given bot along with the metadata

type BotState

type BotState uint8
const (
	BotStateInitializing BotState = iota
	BotStateStopped
	BotStateRunning
	BotStateStopping
)

func InitState

func InitState() BotState

InitState is the first state of the bot

func (BotState) String

func (bs BotState) String() string

String impl

type KelpOS

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

KelpOS is a struct that manages all subprocesses started by this Kelp process

func GetKelpOS

func GetKelpOS() *KelpOS

GetKelpOS gets the singleton instance

func (*KelpOS) Background

func (kos *KelpOS) Background(userID string, namespace string, cmd string) (*Process, error)

Background runs the provided bash command in the background and registers the command

func (*KelpOS) Blocking

func (kos *KelpOS) Blocking(userID string, namespace string, cmd string) ([]byte, error)

Blocking runs a bash command and blocks

func (*KelpOS) BotDataForUser added in v1.12.0

func (kos *KelpOS) BotDataForUser(user *User) *UserBotData

BotDataForUser gets the UserBotData for a given user

func (*KelpOS) GetBinDir added in v1.9.0

func (kos *KelpOS) GetBinDir() *OSPath

GetBinDir accessor

func (*KelpOS) GetDotKelpWorkingDir added in v1.9.0

func (kos *KelpOS) GetDotKelpWorkingDir() *OSPath

GetDotKelpWorkingDir accessor

func (*KelpOS) GetProcess

func (kos *KelpOS) GetProcess(userID string, namespace string) (*Process, bool)

GetProcess gets the process tied to the provided namespace

func (*KelpOS) Mkdir

func (kos *KelpOS) Mkdir(userID string, dirPath *OSPath) error

Mkdir function with a neat error message

func (*KelpOS) RegisteredProcesses

func (kos *KelpOS) RegisteredProcesses() []string

RegisteredProcesses returns the list of registered processes

func (*KelpOS) SafeUnregister

func (kos *KelpOS) SafeUnregister(userID string, namespace string)

SafeUnregister ignores erros when unregistering the command at the provided namespace

func (*KelpOS) SetSilentRegistrations

func (kos *KelpOS) SetSilentRegistrations()

SetSilentRegistrations does not log every time we register and unregister commands

func (*KelpOS) Stop

func (kos *KelpOS) Stop(userID string, namespace string) error

Stop unregisters and stops the command at the provided namespace

func (*KelpOS) StreamOutput

func (kos *KelpOS) StreamOutput(command *exec.Cmd) error

StreamOutput runs the provided command in a streaming fashion

func (*KelpOS) Unregister

func (kos *KelpOS) Unregister(userID string, namespace string) error

Unregister unregisters the command at the provided namespace, returning an error if needed

type OSPath added in v1.9.0

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

OSPath encapsulates the pair of the native path (i.e. windows or unix) and the unix path this allows certain commands which are unix-specific to have access to the path instead of running transformations

func MakeOsPathBase added in v1.9.0

func MakeOsPathBase() (*OSPath, error)

MakeOsPathBase is a factory method for the OSPath struct based on the current binary's directory

func (*OSPath) AsString added in v1.9.0

func (o *OSPath) AsString() string

AsString produces a string representation and we intentionally don't use the Stringer API because this can mistakenly be used in place of a string path which will produce hidden runtime errors which is dangerous

func (*OSPath) IsRelative added in v1.9.0

func (o *OSPath) IsRelative() bool

IsRelative returns true if this is a relative path, otherwise false

func (*OSPath) Join added in v1.9.0

func (o *OSPath) Join(elem ...string) *OSPath

Join makes a new OSPath struct by modifying the internal path representations together

func (*OSPath) JoinRelPath added in v1.9.0

func (o *OSPath) JoinRelPath(relPaths ...*OSPath) (*OSPath, error)

JoinRelPath makes a new OSPath struct by modifying the internal path representations together

func (*OSPath) MakeFromNativePath added in v1.9.0

func (o *OSPath) MakeFromNativePath(targetNativePath string) (*OSPath, error)

MakeFromNativePath returns a new OSPath at the passed in native path string by using the existing OSPath

func (*OSPath) MakeFromUnixPath added in v1.9.0

func (o *OSPath) MakeFromUnixPath(targetUnixPath string) (*OSPath, error)

MakeFromUnixPath returns a new OSPath at the passed in unix path string by using the existing OSPath

func (*OSPath) Native added in v1.9.0

func (o *OSPath) Native() string

Native returns the native representation of the path as a string

func (*OSPath) RelFromPath added in v1.9.0

func (o *OSPath) RelFromPath(basepath *OSPath) (*OSPath, error)

RelFromPath returns a *OSPath that is relative from the provided path

func (*OSPath) String added in v1.9.0

func (o *OSPath) String() string

String() is the Stringer method which is unsupprted

func (*OSPath) Unix added in v1.9.0

func (o *OSPath) Unix() string

Unix returns the unix representation of the path as a string

type Process

type Process struct {
	Cmd    *exec.Cmd
	Stdin  io.WriteCloser
	Stdout io.ReadCloser
}

Process contains all the pieces that can be used to control a given process

type User added in v1.12.0

type User struct {
	// for now this is just userID, but later this may be expanded to become host:userID (UUID) for example
	ID string
}

User is a struct that represents a user

func MakeUser added in v1.12.0

func MakeUser(
	ID string,
) *User

MakeUser is a factory method to create a User

func (*User) String added in v1.12.0

func (u *User) String() string

String is the standard stringer method

type UserBotData added in v1.12.0

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

UserBotData represents the Bot registration map and other items related to a given user

func (*UserBotData) AdvanceBotState added in v1.12.0

func (ubd *UserBotData) AdvanceBotState(botName string, expectedCurrentState BotState) error

AdvanceBotState advances the state of the given bot atomically, ensuring the bot is currently at the expected state

func (*UserBotData) GetBot added in v1.12.0

func (ubd *UserBotData) GetBot(botName string) (*BotInstance, error)

GetBot fetches the bot state for the given name

func (*UserBotData) QueryBotState added in v1.12.0

func (ubd *UserBotData) QueryBotState(botName string) (BotState, error)

QueryBotState checks to see if the bot is actually running and returns the state accordingly

func (*UserBotData) RegisterBot added in v1.12.0

func (ubd *UserBotData) RegisterBot(bot *model2.Bot) error

RegisterBot registers a new bot, returning an error if one already exists with the same name

func (*UserBotData) RegisterBotWithState added in v1.12.0

func (ubd *UserBotData) RegisterBotWithState(bot *model2.Bot, state BotState) error

RegisterBotWithState registers a new bot with a given state, returning an error if one already exists with the same name

func (*UserBotData) RegisterBotWithStateUpsert added in v1.12.0

func (ubd *UserBotData) RegisterBotWithStateUpsert(bot *model2.Bot, state BotState)

RegisterBotWithStateUpsert registers a new bot with a given state, it always registers the bot even if it is already registered, never returning an error

func (*UserBotData) RegisteredBots added in v1.12.0

func (ubd *UserBotData) RegisteredBots() []string

RegisteredBots returns the list of registered bots

func (*UserBotData) SafeUnregisterBot added in v1.12.0

func (ubd *UserBotData) SafeUnregisterBot(botName string)

SafeUnregisterBot unregister a bot without any errors

Jump to

Keyboard shortcuts

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