Documentation
¶
Index ¶
- func TestConnection(host, username, password string) error
- type Manager
- func (dm *Manager) BeginTx(ctx context.Context) error
- func (dm *Manager) CheckUserExists(username string) (bool, string, error)
- func (dm *Manager) CommitTx() error
- func (dm *Manager) CreateRole(role string) error
- func (dm *Manager) CreateUser(username, password string) (string, error)
- func (dm *Manager) GetMySQLVersion() (int, error)
- func (dm *Manager) GetUserHost(username string) (string, error)
- func (dm *Manager) GrantPrivileges(role, dbName, grants string) error
- func (dm *Manager) GrantPrivilegesToUser(username, dbName, grants string) error
- func (dm *Manager) GrantRoles(username, role string, isGCP bool) error
- func (dm *Manager) RollbackTx() error
- func (dm *Manager) SetDefaultRole(username, role string) error
- func (dm *Manager) ShowRoleGrants(role string) error
- func (dm *Manager) ShowUserGrants(username string) error
- type SQLFileExecutor
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TestConnection ¶
TestConnection attempts to connect to a MySQL server using the provided credentials
Types ¶
type Manager ¶
type Manager struct { DB *sql.DB Tx *sql.Tx Logger *log.Logger PasswordPolicy auth.PasswordPolicy AuthPlugin string // Optional override for authentication plugin Host string // Add Host field for connection details Username string // Add Username field for connection details Password string // Add Password field for connection details }
Manager handles database operations
func NewManager ¶
NewManager creates a new database manager
func (*Manager) CheckUserExists ¶
CheckUserExists checks if a MySQL user exists and returns their host
func (*Manager) CreateRole ¶
CreateRole creates a new MySQL role
func (*Manager) CreateUser ¶
CreateUser creates a new MySQL user
func (*Manager) GetMySQLVersion ¶
GetMySQLVersion returns MySQL version (57 for 5.7, 80 for 8.0+)
func (*Manager) GetUserHost ¶
GetUserHost returns the host for a given user
func (*Manager) GrantPrivileges ¶
GrantPrivileges grants privileges to a role
func (*Manager) GrantPrivilegesToUser ¶
GrantPrivilegesToUser grants privileges to a user
func (*Manager) GrantRoles ¶
GrantRoles grants roles to a user
func (*Manager) RollbackTx ¶
RollbackTx rolls back the current transaction
func (*Manager) SetDefaultRole ¶
SetDefaultRole sets the default role for a user
func (*Manager) ShowRoleGrants ¶
ShowRoleGrants displays grants for a role
func (*Manager) ShowUserGrants ¶
ShowUserGrants displays grants for a user
type SQLFileExecutor ¶
SQLFileExecutor handles creating and executing SQL files to avoid shell escaping issues
func NewSQLFileExecutor ¶
func NewSQLFileExecutor(host, user, password string, logger *log.Logger) *SQLFileExecutor
NewSQLFileExecutor creates a new executor
func (*SQLFileExecutor) ExecuteUserCreation ¶
func (e *SQLFileExecutor) ExecuteUserCreation(username, password, authPlugin string, roles []string, dbName, grants string) error
ExecuteUserCreation creates a SQL file with the user creation commands and executes it