Documentation ¶
Index ¶
- Constants
- func ConnectToSQLDBAsCurrentUser(ctx context.Context, driverName string, fullServer string, database string, ...) (*sql.DB, error)
- func ConnectToSqlDB(ctx context.Context, driverName string, fullServer string, database string, ...) (*sql.DB, error)
- func DropUser(ctx context.Context, db *sql.DB, user string) error
- func EnsureUserDatabaseRoles(ctx context.Context, conn *sql.DB, user string, dbRoles map[string][]string) error
- func EnsureUserServerRoles(ctx context.Context, db *sql.DB, user string, roles []string) error
- func ExtractUserDatabaseRoles(ctx context.Context, db *sql.DB, user string) (map[string]StringSet, error)
- func GetFullSQLServerName(serverName string) string
- func GetFullyQualifiedUserName(userName string, serverName string) string
- func IgnoreDatabaseBusy(err error) error
- func IgnoreResourceNotFound(err error) error
- func IsErrorDatabaseBusy(err error) bool
- func IsErrorResourceNotFound(err error) bool
- func UserExists(ctx context.Context, db *sql.DB, username string) (bool, error)
- type StringSet
Constants ¶
const DriverName = "mysql"
DriverName is driver name for psqldb connection
const ServerPort = 3306
ServerPort is the default server port for sql server
const SystemDatabase = "mysql"
SystemDatabase is the name of the system database in a MySQL server where users and privileges are stored (and which we can always assume will exist).
Variables ¶
This section is empty.
Functions ¶
func ConnectToSQLDBAsCurrentUser ¶
func ConnectToSQLDBAsCurrentUser( ctx context.Context, driverName string, fullServer string, database string, port int, user string, clientID string) (*sql.DB, error)
ConnectToSQLDBAsCurrentUser connects to the SQL DB using the specified MSI ClientID
func ConnectToSqlDB ¶
func ConnectToSqlDB(ctx context.Context, driverName string, fullServer string, database string, port int, user string, password string) (*sql.DB, error)
ConnectToSqlDb connects to the SQL db using the given credentials
func EnsureUserDatabaseRoles ¶
func EnsureUserDatabaseRoles(ctx context.Context, conn *sql.DB, user string, dbRoles map[string][]string) error
EnsureUserDatabaseRoles revokes and grants database roles as needed so they match the ones passed in. If there's an error applying privileges for one database it will still continue to apply privileges for subsequent databases (before reporting all errors).
func EnsureUserServerRoles ¶
EnsureUserServerRoles revokes and grants server-level roles as needed so the roles for the user match those passed in.
func ExtractUserDatabaseRoles ¶
func ExtractUserDatabaseRoles(ctx context.Context, db *sql.DB, user string) (map[string]StringSet, error)
ExtractUserDatabaseRoles extracts the per-database roles that the user has. The user can have different permissions to each database. The details of access are returned in the map, keyed by database name.
func GetFullSQLServerName ¶
func IgnoreDatabaseBusy ¶
func IgnoreResourceNotFound ¶
func IsErrorDatabaseBusy ¶
func IsErrorResourceNotFound ¶
TODO: This is probably more generic than MySQL
Types ¶
type StringSet ¶
type StringSet map[string]struct{}
func ExtractUserServerRoles ¶
ExtractUserServerRoles extracts the server-level privileges the user has as a set.