config

package
v2.8.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2018 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SSHBoolFlags = []string{"1", "2", "4", "6", "A", "a", "C", "f", "G", "g", "K", "k", "M", "N", "n", "q", "s", "T", "t", "V", "v", "X", "x", "Y", "y"}

SSHBoolFlags contains list of available SSH boolean options

View Source
var SSHFlags = []cli.Flag{}

SSHFlags is built at init(), it contains urfave/cli string & bool flags for SSH

View Source
var SSHStringFlags = []string{"b", "c", "D", "E", "e", "F", "I", "i", "L", "l", "m", "O", "o", "p", "Q", "R", "S", "W", "w"}

SSHStringFlags contains list of available SSH string options

Functions

func BoolVal

func BoolVal(input string) bool

BoolVal returns a boolean matching a configuration string

func SetASSHBinaryPath

func SetASSHBinaryPath(path string)

SetASSHBinaryPath sets the default assh binary path this value may be overwritten in the assh.yml file using the asshbinarypath variable

Types

type Config

type Config struct {
	Hosts             HostsMap `yaml:"hosts,omitempty,flow" json:"hosts"`
	Templates         HostsMap `yaml:"templates,omitempty,flow" json:"templates"`
	Defaults          Host     `yaml:"defaults,omitempty,flow" json:"defaults,omitempty"`
	Includes          []string `yaml:"includes,omitempty,flow" json:"includes,omitempty"`
	ASSHKnownHostFile string   `yaml:"asshknownhostfile,omitempty,flow" json:"asshknownhostfile,omitempty"`
	ASSHBinaryPath    string   `yaml:"asshbinarypath,omitempty,flow" json:"asshbinarypath,omitempty"`
	// contains filtered or unexported fields
}

Config contains a list of Hosts sections and a Defaults section representing a configuration file

func New

func New() *Config

New returns an instantiated Config object

func Open

func Open(path string) (*Config, error)

Open parses a configuration file and returns a *Config object

func (*Config) DisableAutomaticRewrite

func (c *Config) DisableAutomaticRewrite()

DisableAutomaticRewrite will configure the ~/.ssh/config file to not automatically rewrite the configuration file

func (*Config) GetGatewaySafe

func (c *Config) GetGatewaySafe(name string) *Host

GetGatewaySafe returns gateway Host configuration, a gateway is like a Host, except, the host path is not resolved

func (*Config) GetHost

func (c *Config) GetHost(name string) (*Host, error)

GetHost returns a matching host form Config hosts list

func (*Config) GetHostSafe

func (c *Config) GetHostSafe(name string) *Host

GetHostSafe won't fail, in case the host is not found, it will returns a virtual host matching the pattern

func (*Config) IncludedFiles

func (c *Config) IncludedFiles() []string

IncludedFiles returns the list of the included files

func (*Config) IsConfigOutdated

func (c *Config) IsConfigOutdated(target string) (bool, error)

IsConfigOutdated returns true if .ssh/config needs to be rebuild. The reason may be: - assh.yml (or an included file) was updated recently - <target> matches a regex and was never seen before (not present in known-hosts file)

func (*Config) JSONString

func (c *Config) JSONString() ([]byte, error)

JSONString returns a string representing the JSON of a Config object

func (*Config) KnownHostsFileExists

func (c *Config) KnownHostsFileExists() error

KnownHostsFileExists returns nil if it the file exists and an error if it doesn't

func (*Config) LoadConfig

func (c *Config) LoadConfig(source io.Reader) error

LoadConfig loads the content of an io.Reader source

func (*Config) LoadFile

func (c *Config) LoadFile(filename string) error

LoadFile loads the content of a configuration file in the Config object

func (*Config) LoadFiles

func (c *Config) LoadFiles(pattern string) error

LoadFiles will try to glob the pattern and load each matching entries

func (*Config) LoadKnownHosts

func (c *Config) LoadKnownHosts() error

LoadKnownHosts loads known hosts list from disk

func (*Config) SSHConfigPath

func (c *Config) SSHConfigPath() string

SSHConfigPath returns the ~/.ssh/config file path

func (*Config) SaveNewKnownHost

func (c *Config) SaveNewKnownHost(target string)

SaveNewKnownHost registers the target as a new known host and save the full known hosts list on disk

func (*Config) SaveSSHConfig

func (c *Config) SaveSSHConfig() error

SaveSSHConfig saves the configuration to ~/.ssh/config

func (*Config) String

func (c *Config) String() string

String returns the JSON output

func (*Config) Validate

func (c *Config) Validate() []error

Validate checks for values errors

func (*Config) ValidateSummary

func (c *Config) ValidateSummary() error

ValidateSummary summaries Validate() errors slice

func (*Config) WriteSSHConfigTo

func (c *Config) WriteSSHConfigTo(w io.Writer) error

WriteSSHConfigTo returns a .ssh/config valid file containing assh configuration

type Host

type Host struct {
	// ssh-config fields
	AddKeysToAgent                   string                    `yaml:"addkeystoagent,omitempty,flow" json:"AddKeysToAgent,omitempty"`
	AddressFamily                    string                    `yaml:"addressfamily,omitempty,flow" json:"AddressFamily,omitempty"`
	AskPassGUI                       string                    `yaml:"askpassgui,omitempty,flow" json:"AskPassGUI,omitempty"`
	BatchMode                        string                    `yaml:"batchmode,omitempty,flow" json:"BatchMode,omitempty"`
	BindAddress                      string                    `yaml:"bindaddress,omitempty,flow" json:"BindAddress,omitempty"`
	CanonicalDomains                 string                    `yaml:"canonicaldomains,omitempty,flow" json:"CanonicalDomains,omitempty"`
	CanonicalizeFallbackLocal        string                    `yaml:"canonicalizefallbacklocal,omitempty,flow" json:"CanonicalizeFallbackLocal,omitempty"`
	CanonicalizeHostname             string                    `yaml:"canonicalizehostname,omitempty,flow" json:"CanonicalizeHostname,omitempty"`
	CanonicalizeMaxDots              string                    `yaml:"canonicalizemaxDots,omitempty,flow" json:"CanonicalizeMaxDots,omitempty"`
	CanonicalizePermittedCNAMEs      string                    `yaml:"canonicalizepermittedcnames,omitempty,flow" json:"CanonicalizePermittedCNAMEs,omitempty"`
	ChallengeResponseAuthentication  string                    `yaml:"challengeresponseauthentication,omitempty,flow" json:"ChallengeResponseAuthentication,omitempty"`
	CheckHostIP                      string                    `yaml:"checkhostip,omitempty,flow" json:"CheckHostIP,omitempty"`
	Cipher                           string                    `yaml:"cipher,omitempty,flow" json:"Cipher,omitempty"`
	Ciphers                          composeyaml.Stringorslice `yaml:"ciphers,omitempty,flow" json:"Ciphers,omitempty"`
	ClearAllForwardings              string                    `yaml:"clearallforwardings,omitempty,flow" json:"ClearAllForwardings,omitempty"`
	Compression                      string                    `yaml:"compression,omitempty,flow" json:"Compression,omitempty"`
	CompressionLevel                 int                       `yaml:"compressionlevel,omitempty,flow" json:"CompressionLevel,omitempty"`
	ConnectionAttempts               string                    `yaml:"connectionattempts,omitempty,flow" json:"ConnectionAttempts,omitempty"`
	ConnectTimeout                   int                       `yaml:"connecttimeout,omitempty,flow" json:"ConnectTimeout,omitempty"`
	ControlMaster                    string                    `yaml:"controlmaster,omitempty,flow" json:"ControlMaster,omitempty"`
	ControlPath                      string                    `yaml:"controlpath,omitempty,flow" json:"ControlPath,omitempty"`
	ControlPersist                   string                    `yaml:"controlpersist,omitempty,flow" json:"ControlPersist,omitempty"`
	DynamicForward                   composeyaml.Stringorslice `yaml:"dynamicforward,omitempty,flow" json:"DynamicForward,omitempty"`
	EnableSSHKeysign                 string                    `yaml:"enablesshkeysign,omitempty,flow" json:"EnableSSHKeysign,omitempty"`
	EscapeChar                       string                    `yaml:"escapechar,omitempty,flow" json:"EscapeChar,omitempty"`
	ExitOnForwardFailure             string                    `yaml:"exitonforwardfailure,omitempty,flow" json:"ExitOnForwardFailure,omitempty"`
	FingerprintHash                  string                    `yaml:"fingerprinthash,omitempty,flow" json:"FingerprintHash,omitempty"`
	ForwardAgent                     string                    `yaml:"forwardagent,omitempty,flow" json:"ForwardAgent,omitempty"`
	ForwardX11                       string                    `yaml:"forwardx11,omitempty,flow" json:"ForwardX11,omitempty"`
	ForwardX11Timeout                int                       `yaml:"forwardx11timeout,omitempty,flow" json:"ForwardX11Timeout,omitempty"`
	ForwardX11Trusted                string                    `yaml:"forwardx11trusted,omitempty,flow" json:"ForwardX11Trusted,omitempty"`
	GatewayPorts                     string                    `yaml:"gatewayports,omitempty,flow" json:"GatewayPorts,omitempty"`
	GlobalKnownHostsFile             composeyaml.Stringorslice `yaml:"globalknownhostsfile,omitempty,flow" json:"GlobalKnownHostsFile,omitempty"`
	GSSAPIAuthentication             string                    `yaml:"gssapiauthentication,omitempty,flow" json:"GSSAPIAuthentication,omitempty"`
	GSSAPIClientIdentity             string                    `yaml:"gssapiclientidentity,omitempty,flow" json:"GSSAPIClientIdentity,omitempty"`
	GSSAPIDelegateCredentials        string                    `yaml:"gssapidelegatecredentials,omitempty,flow" json:"GSSAPIDelegateCredentials,omitempty"`
	GSSAPIKeyExchange                string                    `yaml:"gssapikeyexchange,omitempty,flow" json:"GSSAPIKeyExchange,omitempty"`
	GSSAPIRenewalForcesRekey         string                    `yaml:"gssapirenewalforcesrekey,omitempty,flow" json:"GSSAPIRenewalForcesRekey,omitempty"`
	GSSAPIServerIdentity             string                    `yaml:"gssapiserveridentity,omitempty,flow" json:"GSSAPIServerIdentity,omitempty"`
	GSSAPITrustDNS                   string                    `yaml:"gssapitrustdns,omitempty,flow" json:"GSSAPITrustDNS,omitempty"`
	HashKnownHosts                   string                    `yaml:"hashknownhosts,omitempty,flow" json:"HashKnownHosts,omitempty"`
	HostbasedAuthentication          string                    `yaml:"hostbasedauthentication,omitempty,flow" json:"HostbasedAuthentication,omitempty"`
	HostbasedKeyTypes                string                    `yaml:"hostbasedkeytypes,omitempty,flow" json:"HostbasedKeyTypes,omitempty"`
	HostKeyAlgorithms                string                    `yaml:"hostkeyalgorithms,omitempty,flow" json:"HostKeyAlgorithms,omitempty"`
	HostKeyAlias                     string                    `yaml:"hostkeyalias,omitempty,flow" json:"HostKeyAlias,omitempty"`
	IdentitiesOnly                   string                    `yaml:"identitiesonly,omitempty,flow" json:"IdentitiesOnly,omitempty"`
	IdentityFile                     composeyaml.Stringorslice `yaml:"identityfile,omitempty,flow" json:"IdentityFile,omitempty"`
	IgnoreUnknown                    string                    `yaml:"ignoreunknown,omitempty,flow" json:"IgnoreUnknown,omitempty"`
	IPQoS                            composeyaml.Stringorslice `yaml:"ipqos,omitempty,flow" json:"IPQoS,omitempty"`
	KbdInteractiveAuthentication     string                    `yaml:"kbdinteractiveauthentication,omitempty,flow" json:"KbdInteractiveAuthentication,omitempty"`
	KbdInteractiveDevices            composeyaml.Stringorslice `yaml:"kbdinteractivedevices,omitempty,flow" json:"KbdInteractiveDevices,omitempty"`
	KexAlgorithms                    composeyaml.Stringorslice `yaml:"kexalgorithms,omitempty,flow" json:"KexAlgorithms,omitempty"`
	KeychainIntegration              string                    `yaml:"keychainintegration,omitempty,flow" json:"KeychainIntegration,omitempty"`
	LocalCommand                     string                    `yaml:"localcommand,omitempty,flow" json:"LocalCommand,omitempty"`
	LocalForward                     composeyaml.Stringorslice `yaml:"localforward,omitempty,flow" json:"LocalForward,omitempty"`
	LogLevel                         string                    `yaml:"loglevel,omitempty,flow" json:"LogLevel,omitempty"`
	MACs                             composeyaml.Stringorslice `yaml:"macs,omitempty,flow" json:"MACs,omitempty"`
	Match                            string                    `yaml:"match,omitempty,flow" json:"Match,omitempty"`
	NoHostAuthenticationForLocalhost string                    `yaml:"nohostauthenticationforlocalhost,omitempty,flow" json:"NoHostAuthenticationForLocalhost,omitempty"`
	NumberOfPasswordPrompts          string                    `yaml:"numberofpasswordprompts,omitempty,flow" json:"NumberOfPasswordPrompts,omitempty"`
	PasswordAuthentication           string                    `yaml:"passwordauthentication,omitempty,flow" json:"PasswordAuthentication,omitempty"`
	PermitLocalCommand               string                    `yaml:"permitlocalcommand,omitempty,flow" json:"PermitLocalCommand,omitempty"`
	PKCS11Provider                   string                    `yaml:"pkcs11provider,omitempty,flow" json:"PKCS11Provider,omitempty"`
	Port                             string                    `yaml:"port,omitempty,flow" json:"Port,omitempty"`
	PreferredAuthentications         string                    `yaml:"preferredauthentications,omitempty,flow" json:"PreferredAuthentications,omitempty"`
	Protocol                         composeyaml.Stringorslice `yaml:"protocol,omitempty,flow" json:"Protocol,omitempty"`
	ProxyUseFdpass                   string                    `yaml:"proxyusefdpass,omitempty,flow" json:"ProxyUseFdpass,omitempty"`
	PubkeyAcceptedKeyTypes           string                    `yaml:"pubkeyacceptedkeytypes,omitempty,flow" json:"PubkeyAcceptedKeyTypes,omitempty"`
	PubkeyAuthentication             string                    `yaml:"pubkeyauthentication,omitempty,flow" json:"PubkeyAuthentication,omitempty"`
	RekeyLimit                       string                    `yaml:"rekeylimit,omitempty,flow" json:"RekeyLimit,omitempty"`
	RemoteForward                    composeyaml.Stringorslice `yaml:"remoteforward,omitempty,flow" json:"RemoteForward,omitempty"`
	RequestTTY                       string                    `yaml:"requesttty,omitempty,flow" json:"RequestTTY,omitempty"`
	RevokedHostKeys                  string                    `yaml:"revokedhostkeys,omitempty,flow" json:"RevokedHostKeys,omitempty"`
	RhostsRSAAuthentication          string                    `yaml:"rhostsrsaauthentication,omitempty,flow" json:"RhostsRSAAuthentication,omitempty"`
	RSAAuthentication                string                    `yaml:"rsaauthentication,omitempty,flow" json:"RSAAuthentication,omitempty"`
	SendEnv                          composeyaml.Stringorslice `yaml:"sendenv,omitempty,flow" json:"SendEnv,omitempty"`
	ServerAliveCountMax              int                       `yaml:"serveralivecountmax,omitempty,flow" json:"ServerAliveCountMax,omitempty"`
	ServerAliveInterval              int                       `yaml:"serveraliveinterval,omitempty,flow" json:"ServerAliveInterval,omitempty"`
	StreamLocalBindMask              string                    `yaml:"streamlocalbindmask,omitempty,flow" json:"StreamLocalBindMask,omitempty"`
	StreamLocalBindUnlink            string                    `yaml:"streamlocalbindunlink,omitempty,flow" json:"StreamLocalBindUnlink,omitempty"`
	StrictHostKeyChecking            string                    `yaml:"stricthostkeychecking,omitempty,flow" json:"StrictHostKeyChecking,omitempty"`
	TCPKeepAlive                     string                    `yaml:"tcpkeepalive,omitempty,flow" json:"TCPKeepAlive,omitempty"`
	Tunnel                           string                    `yaml:"tunnel,omitempty,flow" json:"Tunnel,omitempty"`
	TunnelDevice                     string                    `yaml:"tunneldevice,omitempty,flow" json:"TunnelDevice,omitempty"`
	UpdateHostKeys                   string                    `yaml:"updatehostkeys,omitempty,flow" json:"UpdateHostKeys,omitempty"`
	UseKeychain                      string                    `yaml:"usekeychain,omitempty,flow" json:"UseKeychain,omitempty"`
	UsePrivilegedPort                string                    `yaml:"useprivilegedport,omitempty,flow" json:"UsePrivilegedPort,omitempty"`
	User                             string                    `yaml:"user,omitempty,flow" json:"User,omitempty"`
	UserKnownHostsFile               composeyaml.Stringorslice `yaml:"userknownhostsfile,omitempty,flow" json:"UserKnownHostsFile,omitempty"`
	VerifyHostKeyDNS                 string                    `yaml:"verifyhostkeydns,omitempty,flow" json:"VerifyHostKeyDNS,omitempty"`
	VisualHostKey                    string                    `yaml:"visualhostkey,omitempty,flow" json:"VisualHostKey,omitempty"`
	XAuthLocation                    string                    `yaml:"xauthlocation,omitempty,flow" json:"XAuthLocation,omitempty"`

	// ssh-config fields with a different behavior
	HostName     string `yaml:"hostname,omitempty,flow" json:"HostName,omitempty"`
	ProxyCommand string `yaml:"proxycommand,omitempty,flow" json:"ProxyCommand,omitempty"`

	Inherits           composeyaml.Stringorslice `yaml:"inherits,omitempty,flow" json:"Inherits,omitempty"`
	Gateways           composeyaml.Stringorslice `yaml:"gateways,omitempty,flow" json:"Gateways,omitempty"`
	ResolveNameservers composeyaml.Stringorslice `yaml:"resolvenameservers,omitempty,flow" json:"ResolveNameservers,omitempty"`
	ResolveCommand     string                    `yaml:"resolvecommand,omitempty,flow" json:"ResolveCommand,omitempty"`
	ControlMasterMkdir string                    `yaml:"controlmastermkdir,omitempty,flow" json:"ControlMasterMkdir,omitempty"`
	Aliases            composeyaml.Stringorslice `yaml:"aliases,omitempty,flow" json:"Aliases,omitempty"`
	Hooks              *HostHooks                `yaml:"hooks,omitempty,flow" json:"Hooks,omitempty"`
	Comment            composeyaml.Stringorslice `yaml:"comment,omitempty,flow" json:"Comment,omitempty"`
	RateLimit          string                    `yaml:"ratelimit,omitempty,flow" json:"RateLimit,omitempty"`
	// contains filtered or unexported fields
}

Host defines the configuration flags of a host

func NewHost

func NewHost(name string) *Host

NewHost returns a host with name

func (*Host) AddKnownHost

func (h *Host) AddKnownHost(target string)

AddKnownHost append target to the host' known hosts list

func (*Host) ApplyDefaults

func (h *Host) ApplyDefaults(defaults *Host)

ApplyDefaults ensures a Host is valid by filling the missing fields with defaults

func (*Host) Clone

func (h *Host) Clone() *Host

Clone returns a copy of an existing Host

func (*Host) ExpandString

func (h *Host) ExpandString(input string, gateway string) string

func (*Host) Matches

func (h *Host) Matches(needle string) bool

Matches returns true if the host matches a given string

func (*Host) Name

func (h *Host) Name() string

Name returns the name of a host

func (*Host) Options

func (h *Host) Options() OptionsList

Options returns a map of set options

func (*Host) Prototype

func (h *Host) Prototype() string

Prototype returns a prototype representation of the host, used in listings

func (*Host) RawName

func (h *Host) RawName() string

RawName returns the raw name of a host without pattern computing

func (*Host) String

func (h *Host) String() string

String returns the JSON output

func (*Host) Validate

func (h *Host) Validate() []error

Validate checks for values errors

func (*Host) WriteSSHConfigTo

func (h *Host) WriteSSHConfigTo(w io.Writer) error

WriteSSHConfigTo writes an ~/.ssh/config file compatible host definition to a writable stream

type HostHooks

type HostHooks struct {
	AfterConfigWrite  hooks.Hooks `yaml:"afterconfigwrite,omitempty,flow" json:"AfterConfigWrite,omitempty"`
	BeforeConfigWrite hooks.Hooks `yaml:"beforeconfigwrite,omitempty,flow" json:"BeforeConfigWrite,omitempty"`
	BeforeConnect     hooks.Hooks `yaml:"beforeconnect,omitempty,flow" json:"BeforeConnect,omitempty"`
	OnConnect         hooks.Hooks `yaml:"onconnect,omitempty,flow" json:"OnConnect,omitempty"`
	OnConnectError    hooks.Hooks `yaml:"onconnecterror,omitempty,flow" json:"OnConnectError,omitempty"`
	OnDisconnect      hooks.Hooks `yaml:"ondisconnect,omitempty,flow" json:"OnDisconnect,omitempty"`
}

HostHooks represents a static list of Hooks

func (*HostHooks) Length

func (hh *HostHooks) Length() int

Length returns the quantity of hooks of any type

func (*HostHooks) String

func (hh *HostHooks) String() string

String returns the JSON output

type HostsList

type HostsList []*Host

HostsList is a list of *Host

func (HostsList) Len

func (hl HostsList) Len() int

func (HostsList) Less

func (hl HostsList) Less(i, j int) bool

func (HostsList) Swap

func (hl HostsList) Swap(i, j int)

type HostsMap

type HostsMap map[string]*Host

HostsMap is a map of **Host).Name -> *Host

func (*HostsMap) SortedList

func (hm *HostsMap) SortedList() HostsList

SortedList returns a list of hosts sorted by their name

func (*HostsMap) ToList

func (hm *HostsMap) ToList() HostsList

ToList returns a slice of *Hosts

type Option

type Option struct {
	Name  string
	Value string
}

Option is an host option

func (*Option) String

func (o *Option) String() string

type OptionsList

type OptionsList []Option

OptionsList is a list of options

func (*OptionsList) Get

func (ol *OptionsList) Get(name string) string

Get returns the option value matching the name or "" if the key is not found

func (*OptionsList) Remove

func (ol *OptionsList) Remove(key string)

Remove removes an option from the list based on its key

func (*OptionsList) ToStringList

func (ol *OptionsList) ToStringList() []string

ToStringList returns a list of string with the following format: `key=value`

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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