host

package
v1.0.1-pre Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2022 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const ALLHOSTS = "all"
View Source
const LOCALHOST = "localhost"
View Source
const UserHostFile = "geneos-hosts.json"

Variables

View Source
var (
	ErrInvalidArgs  = fmt.Errorf("invalid argument")
	ErrNotSupported = fmt.Errorf("not supported")
)

Functions

func Add

func Add(h *Host)

func CleanRelativePath

func CleanRelativePath(path string) (clean string, err error)

given a path return a cleaned version. If the cleaning results in and absolute path or one that tries to ascend the tree then return an error

func CopyAll

func CopyAll(srcHost *Host, srcDir string, dstHost *Host, dstDir string) (err error)

move a directory, between any combination of local or remote locations

func Delete

func Delete(h *Host)

func Geneos

func Geneos() string

return the absolute path to the local Geneos installation

func Init

func Init()

this is called from cmd root

func ReadConfigFile

func ReadConfigFile()

func UserHostsFilePath

func UserHostsFilePath() string

func WriteConfigFile

func WriteConfigFile() error

Types

type FileStat

type FileStat struct {
	St    os.FileInfo
	Uid   uint32
	Gid   uint32
	Mtime int64
}

massaged file stats

type Host

type Host struct {
	// use a viper to store config
	*viper.Viper
	// contains filtered or unexported fields
}
var LOCAL, ALL *Host

func AllHosts

func AllHosts() (hs []*Host)

func Get

func Get(name string) (c *Host)

XXX new needs the top level viper and passes back a Sub()

func Match

func Match(h string) (r []*Host)

returns a slice of all matching Hosts. used mainly for range loops where the host could be specific or 'all'

func (*Host) Chown

func (h *Host) Chown(name string, uid, gid int) (err error)

func (*Host) Close

func (h *Host) Close()

func (*Host) CloseSFTP

func (h *Host) CloseSFTP()

func (*Host) Create

func (h *Host) Create(path string, perms fs.FileMode) (out io.WriteCloser, err error)

func (*Host) CreateTempFile

func (h *Host) CreateTempFile(path string, perms fs.FileMode) (f io.WriteCloser, name string, err error)

based on os.CreatTemp, but allows for hosts and much simplified given a remote and a full path, create a file with a suffix and return an io.File

func (*Host) Dial

func (h *Host) Dial() (s *ssh.Client, err error)

func (*Host) DialSFTP

func (h *Host) DialSFTP() (f *sftp.Client, err error)

succeed or fatal

func (*Host) Exists

func (h *Host) Exists() bool

func (*Host) Failed

func (h *Host) Failed() bool

func (*Host) FullName

func (h *Host) FullName(name string) string

func (*Host) GeneosJoinPath

func (h *Host) GeneosJoinPath(paths ...string) string

return an absolute path anchored in the root directory of the remote host this can also be LOCAL

func (*Host) GetOSReleaseEnv

func (h *Host) GetOSReleaseEnv() (err error)

func (*Host) Glob

func (h *Host) Glob(pattern string) (paths []string, err error)

func (*Host) Lstat

func (h *Host) Lstat(name string) (s FileStat, err error)

lstat() a file and normalise common values

func (*Host) MkdirAll

func (h *Host) MkdirAll(path string, perm os.FileMode) (err error)

func (*Host) Open

func (h *Host) Open(name string) (f io.ReadSeekCloser, err error)

func (*Host) Path

func (h *Host) Path(path string) string

return a string of the form "host:/path" for consistent use in output

func (*Host) ReadCert

func (r *Host) ReadCert(path string) (cert *x509.Certificate, err error)

read a PEM encoded cert from path, return the first found as a parsed certificate

func (*Host) ReadDir

func (h *Host) ReadDir(name string) (dirs []os.DirEntry, err error)

func (*Host) ReadFile

func (h *Host) ReadFile(name string) (b []byte, err error)

func (*Host) ReadKey

func (r *Host) ReadKey(path string) (key *rsa.PrivateKey, err error)

read a PEM encoded RSA private key from path. returns the first found as a parsed key

func (h *Host) Readlink(file string) (link string, err error)

func (*Host) Remove

func (h *Host) Remove(name string) (err error)

func (*Host) RemoveAll

func (h *Host) RemoveAll(name string) (err error)

func (*Host) Rename

func (h *Host) Rename(oldpath, newpath string) (err error)

func (*Host) Stat

func (h *Host) Stat(name string) (s FileStat, err error)

stat() a file and normalise common values

func (*Host) String

func (h *Host) String() string
func (h *Host) Symlink(target, path string) (err error)

shim methods that test Host and direct to ssh / sftp / os at some point this should become interface based to allow other remote protocols cleanly

func (*Host) WriteCert

func (r *Host) WriteCert(path string, cert *x509.Certificate) (err error)

write cert as PEM to path

func (*Host) WriteCerts

func (r *Host) WriteCerts(path string, certs ...*x509.Certificate) (err error)

concatenate certs and write to path

func (*Host) WriteConfigFile

func (h *Host) WriteConfigFile(file string, username string, perms fs.FileMode, config interface{}) (err error)

try to be atomic, lots of edge cases, UNIX/Linux only we know the size of config structs is typically small, so just marshal in memory

func (*Host) WriteFile

func (h *Host) WriteFile(path string, b []byte, perm os.FileMode) (err error)

func (*Host) WriteKey

func (r *Host) WriteKey(path string, key *rsa.PrivateKey) (err error)

write a private key as PEM to path. sets file permissions to 0600 (before umask)

Jump to

Keyboard shortcuts

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