host

package
v1.4.1-beta Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	ErrInvalidArgs  = fmt.Errorf("invalid argument")
	ErrNotSupported = fmt.Errorf("not supported")
)
View Source
var UserHostFile = filepath.Join(ConfigSubdirName, "hosts.json")

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)

CopyAll copies a directory between any combination of local or remote locations

func CopyFile

func CopyFile(srcHost *Host, srcPath string, dstHost *Host, dstPath string) (err error)

CopyFile copies a file between any combination of local or remote locations. Destination can be a directory or a file. Parent directories will be created. Any existing file will be overwritten.

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 ReadConfig added in v1.4.1

func ReadConfig()

ReadConfig loads configuration entries from the default host configuration file. If that fails, it tries the old location and migrates that file to the new location if found.

func UserHostsFilePath

func UserHostsFilePath() string

func WriteConfig added in v1.4.1

func WriteConfig() error

func WriteConfigFile

func WriteConfigFile(file string, username string, perms fs.FileMode, conf *config.Config) (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

Types

type FileStat

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

massaged file stats

type Host

type Host struct {
	*config.Config
	// contains filtered or unexported fields
}
var LOCAL, ALL *Host

func AllHosts

func AllHosts() (hs []*Host)

AllHosts returns a slice of all hosts, including LOCAL

func Get

func Get(name string) (c *Host)

Get returns a pointer to Host value. If passed an empty name, returns nil. If passed the special values LOCALHOST or ALLHOSTS then it will return the respective special values LOCAL or ALL. Otherwise it tries to lookup an existing host with the given name to return or initialises a new value to return. This may not be an existing host.

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

func Match

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

Match returns a slice of all matching Hosts. Intended for use in range loops where the host could be specific or 'all'. If passed an empty string then returns an empty slice.

func RemoteHosts

func RemoteHosts() (hs []*Host)

RemoteHosts returns a slice of al valid remote hosts

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) Filepath

func (h *Host) Filepath(parts ...interface{}) string

Filepath returns an absolute path relative to the Geneos installation directory. Each argument is used as a path component and are joined using filepath.Join(). Each part can be a plain string or a type with a String() method - non-string types are rendered using fmt.Sprint() without further error checking.

func (*Host) FullName

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

func (*Host) Glob

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

func (*Host) Lchown added in v1.3.1

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

change the symlink ownership on local system, issue chown for remotes

func (*Host) Lstat

func (h *Host) Lstat(name string) (f fs.FileInfo, err error)

Lstat wraps the os.Lstat and sftp.Lstat functions

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) Range

func (h *Host) Range(hosts ...*Host) []*Host

Range will either return just the specific host it is called on, or if that is nil than the list of all hosts passed as args. If no args are passed and h is nil then all hosts are returned.

This is a convenience to avoid a double layer of if and range in callers than want to work on specific component types.

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) Run added in v1.4.1

func (h *Host) Run(name string, args ...string) (output []byte, err error)

func (*Host) SetOSReleaseEnv added in v1.4.1

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

func (*Host) Stat

func (h *Host) Stat(name string) (f fs.FileInfo, err error)

Stat wraps the os.Stat and sftp.Stat functions

func (*Host) StatX

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

StatX returns extended Stat info. Needs to be deprecated to support non LInux platforms

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) WriteFile

func (h *Host) WriteFile(name string, data []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