vitess: Index | Files

package dbconfigs

import ""

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.


Package Files

credentials.go dbconfigs.go


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


var All = []string{App, AppDebug, AllPrivs, Dba, Filtered, Repl, ExternalRepl}

All can be used to register all flags: RegisterFlags(All...)

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

func HasConnectionParams Uses

func HasConnectionParams() bool

HasConnectionParams returns true if connection parameters were specified in the command-line. This will allow the caller to search for alternate ways to connect, like looking in the my.cnf file.

func RegisterFlags Uses

func RegisterFlags(userKeys ...string)

RegisterFlags registers the flags for the given DBConfigFlag. For instance, vttablet will register client, dba and repl. Returns all registered flags.

type Connector Uses

type Connector struct {
    // contains filtered or unexported fields

Connector contains Connection Parameters for mysql connection

func New Uses

func New(mcp *mysql.ConnParams) Connector

New initializes a ConnParams from mysql connection parameters

func (Connector) Connect Uses

func (c Connector) Connect(ctx context.Context) (*mysql.Conn, error)

Connect will invoke the mysql.connect method and return a connection

func (Connector) DBName Uses

func (c Connector) DBName() string

DBName gets the dbname from mysql.ConnParams

func (Connector) Host Uses

func (c Connector) Host() string

Host gets the host from mysql.ConnParams

func (Connector) MysqlParams Uses

func (c Connector) MysqlParams() (*mysql.ConnParams, error)

MysqlParams returns the connections params

type CredentialsServer Uses

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 Uses

func GetCredentialsServer() CredentialsServer

GetCredentialsServer returns the current CredentialsServer. Only valid after flag.Init was called.

type DBConfigs Uses

type DBConfigs struct {
    DBName        sync2.AtomicString
    SidecarDBName sync2.AtomicString
    // 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. It also supplies the SidecarDBName. This is currently hardcoded to "_vt", but will soon become customizable. The life-cycle of this package is as follows: App must call RegisterFlags to request the types of connections it wants support for. This must be done before involing 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. The DBName is initially empty and may later be set or changed by the app.

func Init Uses

func Init(defaultSocketFile string) (*DBConfigs, error)

Init will initialize all the necessary connection parameters. Precedence is as follows: if baseConfig command line options are set, they supersede all other settings. If baseConfig is not set, 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 NewTestDBConfigs Uses

func NewTestDBConfigs(genParams, appDebugParams mysql.ConnParams, dbName string) *DBConfigs

NewTestDBConfigs returns a DBConfigs meant for testing.

func (*DBConfigs) AllPrivsWithDB Uses

func (dbcfgs *DBConfigs) AllPrivsWithDB() Connector

AllPrivsWithDB returns connection parameters for appdebug with dbname set.

func (*DBConfigs) AppDebugWithDB Uses

func (dbcfgs *DBConfigs) AppDebugWithDB() Connector

AppDebugWithDB returns connection parameters for appdebug with dbname set.

func (*DBConfigs) AppWithDB Uses

func (dbcfgs *DBConfigs) AppWithDB() Connector

AppWithDB returns connection parameters for app with dbname set.

func (*DBConfigs) Copy Uses

func (dbcfgs *DBConfigs) Copy() *DBConfigs

Copy returns a copy of the DBConfig.

func (*DBConfigs) Dba Uses

func (dbcfgs *DBConfigs) Dba() Connector

Dba returns connection parameters for dba with no dbname set.

func (*DBConfigs) DbaWithDB Uses

func (dbcfgs *DBConfigs) DbaWithDB() Connector

DbaWithDB returns connection parameters for appdebug with dbname set.

func (*DBConfigs) ExternalRepl Uses

func (dbcfgs *DBConfigs) ExternalRepl() Connector

ExternalRepl returns connection parameters for repl with no dbname set.

func (*DBConfigs) ExternalReplWithDB Uses

func (dbcfgs *DBConfigs) ExternalReplWithDB() Connector

ExternalReplWithDB returns connection parameters for repl with dbname set.

func (*DBConfigs) FilteredWithDB Uses

func (dbcfgs *DBConfigs) FilteredWithDB() Connector

FilteredWithDB returns connection parameters for filtered with dbname set.

func (*DBConfigs) IsZero Uses

func (dbcfgs *DBConfigs) IsZero() bool

IsZero returns true if DBConfigs was uninitialized.

func (*DBConfigs) Repl Uses

func (dbcfgs *DBConfigs) Repl() Connector

Repl returns connection parameters for repl with no dbname set.

func (*DBConfigs) String Uses

func (dbcfgs *DBConfigs) String() string

type FileCredentialsServer Uses

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 Uses

func (fcs *FileCredentialsServer) GetUserAndPassword(user string) (string, string, error)

GetUserAndPassword is part of the CredentialsServer interface

Package dbconfigs imports 13 packages (graph) and is imported by 74 packages. Updated 2020-04-07. Refresh now. Tools for package owners.