mysql

package
v0.0.0-...-4354d50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2024 License: MIT Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const DriverName = "mysql"

DriverName is driver name for psqldb connection

View Source
const ServerPort = 3306

ServerPort is the default server port for sql server

View Source
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 DropUser

func DropUser(ctx context.Context, db *sql.DB, user string) error

DropUser drops a user from db

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

func EnsureUserServerRoles(ctx context.Context, db *sql.DB, user string, roles []string) error

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 GetFullSQLServerName(serverName string) string

func GetFullyQualifiedUserName

func GetFullyQualifiedUserName(userName string, serverName string) string

func IgnoreDatabaseBusy

func IgnoreDatabaseBusy(err error) error

func IgnoreResourceNotFound

func IgnoreResourceNotFound(err error) error

func IsErrorDatabaseBusy

func IsErrorDatabaseBusy(err error) bool

func IsErrorResourceNotFound

func IsErrorResourceNotFound(err error) bool

TODO: This is probably more generic than MySQL

func UserExists

func UserExists(ctx context.Context, db *sql.DB, username string) (bool, error)

UserExists checks if db contains user

Types

type StringSet

type StringSet map[string]struct{}

func ExtractUserServerRoles

func ExtractUserServerRoles(ctx context.Context, db *sql.DB, user string) (StringSet, error)

ExtractUserServerRoles extracts the server-level privileges the user has as a set.

func SliceToSet

func SliceToSet(values []string) StringSet

func (StringSet) Add

func (s StringSet) Add(value string)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL