client

package
v0.0.0-...-03200e1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 29 Imported by: 3

Documentation

Index

Constants

View Source
const MulchSSHSubDir = "mulch/"

MulchSSHSubDir is the name of mulch dedicated .ssh sub-directory

View Source
const ProtocolVersion = 1

ProtocolVersion implemented by this client

View Source
const SSHKeyPrefix = "id_"

SSHKeyPrefix is the prefix for SSH keys (was 'id_rsa_' but we switched to ed25519, so let's use a generic name)

View Source
const Version = "1.19.0"

Version of the client (x.y.z format)

Variables

View Source
var GlobalCfgFile string

GlobalCfgFile is the config filename

View Source
var GlobalHome string

GlobalHome is the user HOME

Functions

func CreateSSHMulchDir

func CreateSSHMulchDir() error

CreateSSHMulchDir creates (if needed) user SSH config path and, inside, mulch directory.

func DurationAsSecondsString

func DurationAsSecondsString(d time.Duration) string

DurationAsSecondsString returns a string representation of a duration (seconds)

func GetSSHHost

func GetSSHHost() (string, error)

GetSSHHost returns the SSH server hostname based on mulchd API URL

func GetSSHPath

func GetSSHPath(file string) string

GetSSHPath returns the path of a file in the user SSH config path

func InitExitMessage

func InitExitMessage()

InitExitMessage resets global ExitMessage

func ParseDuration

func ParseDuration(duration string) (time.Duration, error)

ParseDuration returns a duration from string (ex: 1h, 10d, 1y) An empty string is valid (expiration = 0)

func RenderStringTable

func RenderStringTable(headers []string, data [][]string) string

RenderStringTable renders a table as a string

func RenderTable

func RenderTable(headers []string, data [][]string)

RenderTable renders a table to stdout

func RenderTableTruncateCol

func RenderTableTruncateCol(colNum int, headers []string, data [][]string)

RenderTableTruncateCol renders a table to stdout, truncatting the column colNum if table does not fit the screen width

func SFTPCopy

func SFTPCopy(vmName string, user string, filename string) error

SFTPCopy is a WIP

func WriteSSHPair

func WriteSSHPair(reader io.Reader) (string, string, error)

WriteSSHPair overwrites public and private API SSH files, using an APISSHPair reader (see "GET /sshpair") as input. Returns public key filepath, private filepath and error.

Types

type API

type API struct {
	ServerURL string
	APIKey    string
	Trace     bool
	Time      common.MessageTimestamp
}

API describes the basic elements to call the API

var GlobalAPI *API

GlobalAPI is the global API instance

func NewAPI

func NewAPI(server string, apiKey string, trace bool, time common.MessageTimestamp) *API

NewAPI create a new API instance

func (*API) NewCall

func (api *API) NewCall(method string, path string, args map[string]string) *APICall

NewCall create a new APICall

type APICall

type APICall struct {
	Method                 string
	Path                   string
	Args                   map[string]string
	JSONCallback           func(io.Reader, http.Header)
	DestFilePath           string
	DestStream             *os.File
	DisableSpecialMessages bool
	PrintLogTarget         bool
	// contains filtered or unexported fields
}

APICall describes a call to the API

func (*APICall) AddFile

func (call *APICall) AddFile(fieldname string, filename string) error

AddFile to the request (upload)

func (*APICall) Do

func (call *APICall) Do()

Do the actual API call

func (*APICall) TimestampShow

func (call *APICall) TimestampShow(show common.MessageTimestamp)

TimestampShow allow to override -d flags

type ExitMessage

type ExitMessage struct {
	Disabled bool
	Message  string
}

ExitMessage is displayed during client exit

func GetExitMessage

func GetExitMessage() *ExitMessage

GetExitMessage return a pointer to the global ExitMessage

func (*ExitMessage) Disable

func (em *ExitMessage) Disable()

Disable global ExitMessage

func (*ExitMessage) Display

func (em *ExitMessage) Display()

Display global ExitMessage

type RootConfig

type RootConfig struct {
	ConfigFile string

	Server  *ServerConfig
	Aliases map[string]string
	Trace   bool
	Time    common.MessageTimestamp
}

RootConfig describes client application config parameters

var GlobalConfig *RootConfig

GlobalConfig is the global RootConfig instance

type ServerConfig

type ServerConfig struct {
	Name    string
	URL     string
	Key     string
	Alias   string
	SSHPort int
}

ServerConfig describes a server (from config file) Warning: this structure is copied field by field in root_config.go, NewRootConfig(), so remember to update this function if any change is made here.

type VMConfig

type VMConfig struct {
	Name string
}

we only read one field, currently

func NewVMConfigFromFile

func NewVMConfigFromFile(filename string) (*VMConfig, error)

NewVMConfigFromFile creates a new VMConfig from a TOML file

Jump to

Keyboard shortcuts

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