Documentation ¶
Overview ¶
Package dbconfigs provides the registration for command line options to collect db connection parameters. Once registered and collected, it provides variables and functions to build connection parameters for connecting to the database.
Index ¶
- Constants
- Variables
- func RegisterFlags(userKeys ...string)
- type Connector
- type CredentialsServer
- type DBConfigs
- func (dbcfgs *DBConfigs) AllPrivsConnector() Connector
- func (dbcfgs *DBConfigs) AllPrivsWithDB() Connector
- func (dbcfgs *DBConfigs) AppDebugWithDB() Connector
- func (dbcfgs *DBConfigs) AppWithDB() Connector
- func (dbcfgs *DBConfigs) Clone() *DBConfigs
- func (dbcfgs *DBConfigs) DbaConnector() Connector
- func (dbcfgs *DBConfigs) DbaWithDB() Connector
- func (dbcfgs *DBConfigs) ExternalRepl() Connector
- func (dbcfgs *DBConfigs) ExternalReplWithDB() Connector
- func (dbcfgs *DBConfigs) FilteredWithDB() Connector
- func (dbcfgs *DBConfigs) HasGlobalSettings() bool
- func (dbcfgs *DBConfigs) InitWithSocket(defaultSocketFile string, collationEnv *collations.Environment)
- func (dbcfgs *DBConfigs) IsZero() bool
- func (dbcfgs *DBConfigs) MarshalJSON() ([]byte, error)
- func (dbcfgs *DBConfigs) Redacted() *DBConfigs
- func (dbcfgs *DBConfigs) ReplConnector() Connector
- func (dbcfgs *DBConfigs) SetDbParams(dbaParams, appParams, filteredParams mysql.ConnParams)
- func (dbcfgs *DBConfigs) String() string
- type FileCredentialsServer
- type UserConfig
- type VaultCredentialsServer
Constants ¶
const ( App = "app" AppDebug = "appdebug" // AllPrivs user should have more privileges than App (should include possibility to do // schema changes and write to internal Vitess tables), but it shouldn't have SUPER // privilege like Dba has. AllPrivs = "allprivs" Dba = "dba" Filtered = "filtered" Repl = "repl" ExternalRepl = "erepl" )
config flags
Variables ¶
var AllCredentialsServers = make(map[string]CredentialsServer)
AllCredentialsServers contains all the known CredentialsServer implementations. Note we will only access this after flags have been parsed.
var ( // ErrUnknownUser is returned by credential server when the // user doesn't exist ErrUnknownUser = errors.New("unknown user") )
Functions ¶
func RegisterFlags ¶
func RegisterFlags(userKeys ...string)
RegisterFlags registers the base DBFlags, credentials flags, and the user specific ones for the specified system users for the requesting command. For instance, the vttablet command will register flags for all users as defined in the dbconfigs.All variable.
Types ¶
type Connector ¶
type Connector struct {
// contains filtered or unexported fields
}
Connector contains Connection Parameters for mysql connection
func New ¶
func New(mcp *mysql.ConnParams) Connector
New initializes a ConnParams from mysql connection parameters
func (Connector) MysqlParams ¶
func (c Connector) MysqlParams() (*mysql.ConnParams, error)
MysqlParams returns the connections params
type CredentialsServer ¶
type CredentialsServer interface { // GetUserAndPassword returns the user / password to use for a given // user. May return ErrUnknownUser. The user might be altered // to support versioned users. // Note this call needs to be thread safe, as we may call this from // multiple go routines. GetUserAndPassword(user string) (string, string, error) }
CredentialsServer is the interface for a credential server
func GetCredentialsServer ¶
func GetCredentialsServer() CredentialsServer
GetCredentialsServer returns the current CredentialsServer. Only valid after flag.Init was called.
type DBConfigs ¶
type DBConfigs struct { Socket string `json:"socket,omitempty"` Host string `json:"host,omitempty"` Port int `json:"port,omitempty"` Charset string `json:"charset,omitempty"` Flags uint64 `json:"flags,omitempty"` Flavor string `json:"flavor,omitempty"` SslMode vttls.SslMode `json:"sslMode,omitempty"` SslCa string `json:"sslCa,omitempty"` SslCaPath string `json:"sslCaPath,omitempty"` SslCert string `json:"sslCert,omitempty"` SslKey string `json:"sslKey,omitempty"` TLSMinVersion string `json:"tlsMinVersion,omitempty"` ServerName string `json:"serverName,omitempty"` ConnectTimeoutMilliseconds int `json:"connectTimeoutMilliseconds,omitempty"` DBName string `json:"dbName,omitempty"` EnableQueryInfo bool `json:"enableQueryInfo,omitempty"` App UserConfig `json:"app,omitempty"` Dba UserConfig `json:"dba,omitempty"` Filtered UserConfig `json:"filtered,omitempty"` Repl UserConfig `json:"repl,omitempty"` Appdebug UserConfig `json:"appdebug,omitempty"` Allprivs UserConfig `json:"allprivs,omitempty"` // contains filtered or unexported fields }
DBConfigs stores all the data needed to build various connection parameters for the db. It stores credentials for app, appdebug, allprivs, dba, filtered and repl users. It contains other connection parameters like socket, charset, etc. It also stores the default db name, which it can combine with the rest of the data to build db-sepcific connection parameters.
The legacy way of initializing is as follows: App must call RegisterFlags to request the types of connections it wants support for. This must be done before invoking flags.Parse. After flag parsing, app invokes the Init function, which will return a DBConfigs object. The app must store the DBConfigs object internally, and use it to build connection parameters as needed.
func NewTestDBConfigs ¶
func NewTestDBConfigs(genParams, appDebugParams mysql.ConnParams, dbname string) *DBConfigs
NewTestDBConfigs returns a DBConfigs meant for testing.
func (*DBConfigs) AllPrivsConnector ¶
AllPrivsConnector returns connection parameters for allprivs with no dbname set.
func (*DBConfigs) AllPrivsWithDB ¶
AllPrivsWithDB returns connection parameters for allprivs with dbname set.
func (*DBConfigs) AppDebugWithDB ¶
AppDebugWithDB returns connection parameters for appdebug with dbname set.
func (*DBConfigs) DbaConnector ¶
DbaConnector returns connection parameters for dba with no dbname set.
func (*DBConfigs) ExternalRepl ¶
ExternalRepl returns connection parameters for repl with no dbname set.
func (*DBConfigs) ExternalReplWithDB ¶
ExternalReplWithDB returns connection parameters for repl with dbname set.
func (*DBConfigs) FilteredWithDB ¶
FilteredWithDB returns connection parameters for filtered with dbname set.
func (*DBConfigs) HasGlobalSettings ¶
HasGlobalSettings returns true if DBConfigs contains values for global configs.
func (*DBConfigs) InitWithSocket ¶
func (dbcfgs *DBConfigs) InitWithSocket(defaultSocketFile string, collationEnv *collations.Environment)
InitWithSocket will initialize all the necessary connection parameters. Precedence is as follows: if UserConfig settings are set, they supersede all other settings. The next priority is with per-user connection parameters. This is only for legacy support. If no per-user parameters are supplied, then the defaultSocketFile is used to initialize the per-user conn params.
func (*DBConfigs) MarshalJSON ¶
MarshalJSON marshals after redacting passwords.
func (*DBConfigs) ReplConnector ¶
ReplConnector returns connection parameters for repl with no dbname set.
func (*DBConfigs) SetDbParams ¶
func (dbcfgs *DBConfigs) SetDbParams(dbaParams, appParams, filteredParams mysql.ConnParams)
SetDbParams sets the dba and app params
type FileCredentialsServer ¶
type FileCredentialsServer struct {
// contains filtered or unexported fields
}
FileCredentialsServer is a simple implementation of CredentialsServer using a json file. Protected by mu.
func (*FileCredentialsServer) GetUserAndPassword ¶
func (fcs *FileCredentialsServer) GetUserAndPassword(user string) (string, string, error)
GetUserAndPassword is part of the CredentialsServer interface
type UserConfig ¶
type UserConfig struct { User string `json:"user,omitempty"` Password string `json:"password,omitempty"` UseSSL bool `json:"useSsl,omitempty"` UseTCP bool `json:"useTcp,omitempty"` }
UserConfig contains user-specific configs.
type VaultCredentialsServer ¶
type VaultCredentialsServer struct {
// contains filtered or unexported fields
}
VaultCredentialsServer implements CredentialsServer using a Vault backend from HashiCorp.
func (*VaultCredentialsServer) GetUserAndPassword ¶
func (vcs *VaultCredentialsServer) GetUserAndPassword(user string) (string, string, error)
GetUserAndPassword for Vault implementation