database

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ACCESS_TYPE_READONLY  = "readOnly"
	ACCESS_TYPE_READWRITE = "readWrite"
	ACCESS_TYPE_MAINUSER  = "main"
)

Variables

This section is empty.

Functions

func CreateDatabase added in v1.13.0

func CreateDatabase(db Database, admin AdminCredentials) error

CreateDatabase executes queries to create database

func CreateOrUpdateUser added in v1.13.0

func CreateOrUpdateUser(db Database, dbuser *DatabaseUser, admin AdminCredentials) error

CreateOrUpdateUser executes queries to create or update user

func CreateUser added in v1.13.0

func CreateUser(db Database, dbuser *DatabaseUser, admin AdminCredentials) error

CreateUser executes queries to a create user

func DeleteDatabase added in v1.13.0

func DeleteDatabase(db Database, admin AdminCredentials) error

DeleteDatabase executes queries to delete database and user

func DeleteUser added in v1.13.0

func DeleteUser(db Database, dbuser *DatabaseUser, admin AdminCredentials) error

func UpdateUser added in v1.13.0

func UpdateUser(db Database, dbuser *DatabaseUser, admin AdminCredentials) error

Types

type AdminCredentials

type AdminCredentials struct {
	Username string `yaml:"user"`
	Password string `yaml:"password"`
}

AdminCredentials contains admin username and password of database server

type Credentials

type Credentials struct {
	Name             string
	Username         string
	Password         string
	TemplatedSecrets map[string]string
}

Credentials contains credentials to connect database

type Database

type Database interface {
	CheckStatus(user *DatabaseUser) error
	GetCredentials(user *DatabaseUser) Credentials
	ParseAdminCredentials(data map[string][]byte) (AdminCredentials, error)
	GetDatabaseAddress() DatabaseAddress
	// contains filtered or unexported methods
}

Database is interface for CRUD operate of different types of databases

func New

func New(engine string) Database

New returns database interface according to engine type

type DatabaseAddress

type DatabaseAddress struct {
	Host string
	Port uint16
}

DatabaseAddress contains host and port of a database instance

type DatabaseUser added in v1.13.0

type DatabaseUser struct {
	Username   string
	Password   string
	AccessType string
}

type Mysql

type Mysql struct {
	Backend      string
	Host         string
	Port         uint16
	Database     string
	SSLEnabled   bool
	SkipCAVerify bool
}

Mysql is a database interface, abstraced object represents a database on mysql instance can be used to execute query to mysql database

func (Mysql) CheckStatus

func (m Mysql) CheckStatus(user *DatabaseUser) error

CheckStatus checks status of mysql database if the connection to database works

func (Mysql) GetCredentials

func (m Mysql) GetCredentials(user *DatabaseUser) Credentials

GetCredentials returns credentials of the mysql database

func (Mysql) GetDatabaseAddress

func (m Mysql) GetDatabaseAddress() DatabaseAddress

func (Mysql) ParseAdminCredentials

func (m Mysql) ParseAdminCredentials(data map[string][]byte) (AdminCredentials, error)

ParseAdminCredentials parse admin username and password of mysql database from secret data If "user" key is not defined, take "root" as admin user by default

type Postgres

type Postgres struct {
	Backend          string
	Host             string
	Port             uint16
	Database         string
	Monitoring       bool
	Extensions       []string
	SSLEnabled       bool
	SkipCAVerify     bool
	DropPublicSchema bool
	Schemas          []string
	Template         string
	// A user that is created with the Database
	//  it's required to set default priveleges
	//  for read only users
	MainUser string
}

Postgres is a database interface, abstraced object represents a database on postgres instance can be used to execute query to postgres database

func (Postgres) CheckStatus

func (p Postgres) CheckStatus(user *DatabaseUser) error

CheckStatus checks status of postgres database if the connection to database works

func (Postgres) GetCredentials

func (p Postgres) GetCredentials(user *DatabaseUser) Credentials

GetCredentials returns credentials of the postgres database

func (Postgres) GetDatabaseAddress

func (p Postgres) GetDatabaseAddress() DatabaseAddress

func (Postgres) ParseAdminCredentials

func (p Postgres) ParseAdminCredentials(data map[string][]byte) (AdminCredentials, error)

ParseAdminCredentials parse admin username and password of postgres database from secret data If "user" key is not defined, take "postgres" as admin user by default

Jump to

Keyboard shortcuts

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