Documentation
¶
Overview ¶
Package cdb provides a database abstraction layer for storing and retrieving SSH connection information for the sshcm utility.
Index ¶
- Variables
- func IsValidDefault(name string) bool
- func IsValidIdOrNickname(s string) bool
- func IsValidProperty(property string) bool
- func ValidateId(id string) error
- func ValidateNickname(nickname string) error
- type Connection
- type ConnectionDB
- func (conndb *ConnectionDB) Add(c *Connection) (int64, error)
- func (conndb ConnectionDB) Close()
- func (conndb *ConnectionDB) Exists(id int64) bool
- func (conndb *ConnectionDB) ExistsByProperty(property string, value string) bool
- func (conndb *ConnectionDB) Get(id int64) (Connection, error)
- func (conndb *ConnectionDB) GetAll() ([]*Connection, error)
- func (conndb *ConnectionDB) GetByIdOrNickname(arg string) (Connection, error)
- func (conndb *ConnectionDB) GetByProperty(property string, value string) (Connection, error)
- func (conndb *ConnectionDB) GetDefault(name string) (string, error)
- func (conndb *ConnectionDB) GetEffectiveValue(value string, setting string) (string, error)
- func (conndb *ConnectionDB) SetDefault(setting string, value string) error
- type ConnectionProperty
- type IdProperty
- type NicknameProperty
Constants ¶
This section is empty.
Variables ¶
var ErrConnNoDb = errors.New("connection does not have a parent db attached")
var ErrConnNoId = errors.New("connection does not have an id attached")
var ErrConnNoNickname = errors.New("connection does not have a nickname attached")
var ErrConnectionNotFound = errors.New("connection not found")
var ErrDbVersionNotRecognized = errors.New("connection db schema version not recognized")
var ErrDuplicateNickname = errors.New("duplicate nickname")
var ErrIdNotExist = errors.New("connection id does not exist")
var ErrInvalidConnectionProperty = errors.New("invalid connection property")
var ErrInvalidDefault = errors.New("invalid default")
var ErrInvalidId = errors.New("invalid id")
var ErrInvalidIdOrNickname = errors.New("invalid id or nickname")
var ErrNickNameNotExist = errors.New("connection nickname does not exist")
var ErrNicknameLetter = errors.New("nickname does not begin with a letter")
var ErrPropertyInvalid = errors.New("property is invalid")
var ErrSchemaVerInvalid = errors.New("invalid schema version")
var ValidDefaults = [4]string{
"args",
"command",
"identity",
"user",
}
var ValidProperties = [7]string{
"nickname",
"host",
"user",
"description",
"args",
"identity",
"command",
}
Functions ¶
func IsValidDefault ¶
func IsValidIdOrNickname ¶
func IsValidProperty ¶
func ValidateId ¶
func ValidateNickname ¶
Types ¶
type Connection ¶
type Connection struct {
Id *IdProperty // unique connection id
Nickname *NicknameProperty // unique connection nickname
Host *ConnectionProperty // connection-specific host name/IP address
User *ConnectionProperty // connection-specific user name
Description *ConnectionProperty // connection-specific description (hopefully friendly)
Args *ConnectionProperty // connection-specific arguments to pass to SSH Command
Identity *ConnectionProperty // connection-specific OpenSSH-style identity string (ex. path or name)
Command *ConnectionProperty // connection-specific Command to run (ex. sftp)
Binary *ConnectionProperty // to be deleted
// contains filtered or unexported fields
}
A Connection is an SSH connection, as stored in a ConnectionDB. A Connection could originate from a ConnectionDB (ex. returned by a SELECT from the underlying SQL DB), or could be destined for one (ex. for later INSERTion).
If a connection originated from a ConnectionDB, a pointer to it will be stored in db. This allows methods such as Update to perform database operations from the context of the Connection. Connections originating from a ConnectionDB will also have an Id set.
Connections created detached from a ConnectionDB will not have a db or Id set. This is a primitive safety mechanism to prevent arbitrary writes to the database bypassing validations that avoid throwing SQL errors (like checking for Nickname uniqueness).
func NewConnection ¶
func NewConnection() Connection
NewConnection will create a new, empty Connection struct. Using this function is preferred vs. creating a new struct via literal, as the format of the struct may change in the future.
func (Connection) Delete ¶
func (c Connection) Delete() error
Delete removes a connection from the underlying SQL database. It will return nil if the operation succeeeded and err otherwise. Several checks are implemented that return package-specific errors. These checks are simple and only cover obvious situations that will cause SQL query exceptions.
func (Connection) String ¶
func (c Connection) String() string
String returns a string containing the connection nickname and ID, in the format: "nickname (id)".
func (Connection) Update ¶
func (c Connection) Update() error
Update updates an existing connection in the SQL database. It will return nil if the operation succeeeded and err otherwise. Several checks are implemented that return package-specific errors. These checks are simple and only cover obvious situations that will cause SQL query exceptions.
type ConnectionDB ¶
type ConnectionDB struct {
// contains filtered or unexported fields
}
func Open ¶
func Open(path string) (ConnectionDB, error)
Open opens a connection to a Sqlite database. It returns a new ConnectionDB struct and error.
err will indicate whether a program is able to continue with the database connection or not. It does not hint at actions taken to make the database usable if it wasn't initially (ex. file creation or schema upgrade).
If the open is successful, err will == nil.
If the database file does not exist, this function will create a new empty one one. It will then install the latest table schema and bootstrap default setting values. err will still == nil in this case.
If the database file contains an older table schema, this func will upgrade it. If the schema is upgraded successfully, err wil also == nil.
func (*ConnectionDB) Add ¶
func (conndb *ConnectionDB) Add(c *Connection) (int64, error)
func (ConnectionDB) Close ¶
func (conndb ConnectionDB) Close()
Close Gracefully closes a connection to a database.
func (*ConnectionDB) Exists ¶
func (conndb *ConnectionDB) Exists(id int64) bool
func (*ConnectionDB) ExistsByProperty ¶
func (conndb *ConnectionDB) ExistsByProperty(property string, value string) bool
func (*ConnectionDB) Get ¶
func (conndb *ConnectionDB) Get(id int64) (Connection, error)
func (*ConnectionDB) GetAll ¶
func (conndb *ConnectionDB) GetAll() ([]*Connection, error)
func (*ConnectionDB) GetByIdOrNickname ¶
func (conndb *ConnectionDB) GetByIdOrNickname(arg string) (Connection, error)
GetByIdOrNickname looks up a connection by id or nickname, then returns a Connection struct. If the look up succeeded, err will be nil and it can be assumed that the Connection is safe to use.
func (*ConnectionDB) GetByProperty ¶
func (conndb *ConnectionDB) GetByProperty(property string, value string) (Connection, error)
func (*ConnectionDB) GetDefault ¶
func (conndb *ConnectionDB) GetDefault(name string) (string, error)
func (*ConnectionDB) GetEffectiveValue ¶
func (conndb *ConnectionDB) GetEffectiveValue(value string, setting string) (string, error)
func (*ConnectionDB) SetDefault ¶
func (conndb *ConnectionDB) SetDefault(setting string, value string) error
type ConnectionProperty ¶
func (ConnectionProperty) IsEmpty ¶
func (p ConnectionProperty) IsEmpty() bool
func (ConnectionProperty) SqlNullableValue ¶
func (p ConnectionProperty) SqlNullableValue() sql.NullString
func (ConnectionProperty) String ¶
func (p ConnectionProperty) String() string
func (ConnectionProperty) StringTrimmed ¶
func (p ConnectionProperty) StringTrimmed(len int) string
func (ConnectionProperty) Validate ¶
func (p ConnectionProperty) Validate() error
type IdProperty ¶
func (IdProperty) IsEmpty ¶
func (p IdProperty) IsEmpty() bool
func (IdProperty) SqlNullableValue ¶
func (p IdProperty) SqlNullableValue() sql.NullInt64
func (IdProperty) String ¶
func (p IdProperty) String() string
func (IdProperty) StringTrimmed ¶
func (p IdProperty) StringTrimmed(len int) string
func (IdProperty) Validate ¶
func (p IdProperty) Validate() error
type NicknameProperty ¶
func (NicknameProperty) IsEmpty ¶
func (p NicknameProperty) IsEmpty() bool
func (NicknameProperty) SqlNullableValue ¶
func (p NicknameProperty) SqlNullableValue() sql.NullString
func (NicknameProperty) String ¶
func (p NicknameProperty) String() string
func (NicknameProperty) StringTrimmed ¶
func (p NicknameProperty) StringTrimmed(len int) string
func (NicknameProperty) Validate ¶
func (p NicknameProperty) Validate() error