mysql

package
v2.0.0-...-a7294fb Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 9 Imported by: 0

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 ConnectToDB

func ConnectToDB(ctx context.Context, serverAddress string, database string, port int, user string, password string) (*sql.DB, error)

func ConnectToDBAAD

func ConnectToDBAAD(ctx context.Context, serverAddress string, database string, port int, user string, token string) (*sql.DB, error)

ConnectToDBAAD connects to the MySQL database using the specified user. user must be an AAD user of the form:

  • "user@tenant.onmicrosoft.com" (for AAD users)
  • "my-mi" (for Managed Identities)
  • "mygroup" (for AAD groups)

func CreateOrUpdateAADUser

func CreateOrUpdateAADUser(ctx context.Context, db *sql.DB, username string, alias string) error

CreateOrUpdateAADUser creates or updates an AAD user. See https://learn.microsoft.com/en-us/azure/mysql/flexible-server/how-to-azure-ad for details on how to create AAD users. username can be either the actual AAD username (for real AAD users), the group name for groups, or the managed identity name for managed identities.

func CreateOrUpdateUser

func CreateOrUpdateUser(ctx context.Context, db *sql.DB, username string, hostname string, password string) error

func DoesUserExist

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

DoesUserExist checks if db contains user

func DropUser

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

DropUser drops a user from db

func GetUserDatabasePrivileges

func GetUserDatabasePrivileges(ctx context.Context, db *sql.DB, user string, hostname string) (map[string]set.Set[string], error)

GetUserDatabasePrivileges gets the per-database privileges 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 GetUserServerPrivileges

func GetUserServerPrivileges(ctx context.Context, db *sql.DB, user string, hostname string) (set.Set[string], error)

GetUserServerPrivileges gets the server-level privileges the user has as a set.

func HostnameOrDefault

func HostnameOrDefault(hostname string) string

func IsSQLAll

func IsSQLAll(privilege string) bool

IsSQLAll returns whether the string matches the special privilege value ALL.

func ReconcileUserDatabasePrivileges

func ReconcileUserDatabasePrivileges(ctx context.Context, conn *sql.DB, user string, hostname string, dbPrivs map[string][]string) error

ReconcileUserDatabasePrivileges revokes and grants database privileges 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 ReconcileUserServerPrivileges

func ReconcileUserServerPrivileges(ctx context.Context, db *sql.DB, user string, hostname string, privileges []string) error

ReconcileUserServerPrivileges revokes and grants server-level privileges as needed so the privileges for the user match those passed in.

Types

type SQLPrivilegeDelta

type SQLPrivilegeDelta struct {
	AddedPrivileges   set.Set[string]
	DeletedPrivileges set.Set[string]
}

func DiffCurrentAndExpectedSQLPrivileges

func DiffCurrentAndExpectedSQLPrivileges(currentPrivileges set.Set[string], expectedPrivileges set.Set[string]) SQLPrivilegeDelta

Jump to

Keyboard shortcuts

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