Documentation
¶
Overview ¶
Package driver describes the kinds of non-SSH resources komando can talk to (databases, caches, object storage) and the risk levels its safety checks work with.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckRestore ¶
CheckRestore returns an error naming the first line with a client command that could run code or read files where the restore runs.
func JSONValue ¶
JSONValue converts a value from a database, cache or bucket into something JSON keeps exactly: text stays text, binary becomes {"base64": ...}, times become RFC 3339, and integers too large for a JSON number become strings.
func Placeholders ¶
Placeholders counts the parameters in sql ($1.. in postgres, ? in mysql and sqlite), outside strings and comments. ok is false when the count is not known (sqlite named parameters, or SQL that does not parse).
func RuleReason ¶
RuleReason is the human explanation of a rule ID.
Types ¶
type Kind ¶
type Kind struct {
Name string `json:"name"`
Family string `json:"family"` // the command that works with it: db | cache | storage | cluster | registry
Schemes []string `json:"schemes"`
DefaultPort int `json:"default_port,omitempty"`
File bool `json:"file,omitempty"` // a local file, not a network service
Example string `json:"example"`
}
Kind is a resource type komando knows.
type Risk ¶
type Risk int
Risk says how much an operation can change. The safety check (guard) decides from it whether --yes or --allow-dangerous is needed.
func (Risk) MarshalText ¶
type Rule ¶
Rule is a named SQL check, listed by `komando policy`.
type SQLPlan ¶
type SQLPlan struct {
Statements []Statement `json:"statements"`
Verdict
// contains filtered or unexported fields
}
SQLPlan is the result of ClassifySQL: the statements and the overall verdict (the highest risk of any statement).
func ClassifySQL ¶
ClassifySQL splits sql into statements and classifies each one. kind is a conn kind (postgres, mysql, sqlite). Transaction control (BEGIN, COMMIT, ...) is refused: komando owns the transaction, and a COMMIT inside a dry run would make it real.
func (SQLPlan) NeedsWrite ¶
NeedsWrite reports whether a statement must not run without --write. Unknown statements (often typos) that are not otherwise flagged may run in PostgreSQL and SQLite, whose read-only mode refuses them if they do write, and whose error for a typo is clearer than komando's. MySQL's read-only transaction does not cover admin statements, so there an unknown statement needs --write.
type Statement ¶
type Statement struct {
SQL string `json:"sql"`
Keyword string `json:"keyword"`
Risk Risk `json:"risk"`
Rows bool `json:"-"` // returns a result set (SELECT, RETURNING, SHOW, ...)
NoTx bool `json:"no_tx,omitempty"` // cannot run inside a transaction, so cannot be rolled back
Unknown bool `json:"unknown,omitempty"` // keyword not recognised; rated write to be safe
}
Statement is one classified SQL statement.
type Target ¶
type Target struct {
Kind Kind `json:"kind"`
Address string `json:"address,omitempty"` // host:port for network kinds (s3: the endpoint)
Path string `json:"path,omitempty"` // file path for file kinds
User string `json:"user,omitempty"` // s3: the access key ID (not secret)
Database string `json:"database,omitempty"` // SQL database name, or redis DB number
Bucket string `json:"bucket,omitempty"` // s3
Prefix string `json:"prefix,omitempty"` // storage: keys are relative to this folder
Region string `json:"region,omitempty"` // s3
Secure bool `json:"secure,omitempty"` // TLS (rediss, https endpoint)
TLS string `json:"tls,omitempty"` // mysql: the tls= setting (true, skip-verify, preferred, false)
}
Target is a parsed conn URL.
func Parse ¶
Parse reads a conn URL such as postgres://app@db.internal:5432/app or sqlite:///var/lib/app.db. The kind comes from the scheme. URLs that carry a password are refused: passwords belong in the vault.
type Verdict ¶
type Verdict struct {
Risk Risk `json:"risk"`
RuleIDs []string `json:"rules,omitempty"` // matched rules, for error messages
Reasons []string `json:"reasons,omitempty"`
}
Verdict is the result of classifying one operation.
func DataDelete ¶
func DataDelete() Verdict
DataDelete is the verdict for deleting cache keys or stored objects.