database

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Sqlserver               = "sqlserver"
	Postgres                = "postgres"
	Mysql                   = "mysql"
	Mariadb                 = "mariadb"
	CreateMapKey            = "create"
	DeleteMapKey            = "delete"
	RotateMapKey            = "rotate"
	OperationsConfigKey     = "operations"
	ErrorOnMissingKeyOption = "missingkey=error"
	DbmsConfigKey           = "dbms"
)

Variables

This section is empty.

Functions

func GetMysqlOpQuery added in v0.2.0

func GetMysqlOpQuery(operation Operation) (string, error)

GetMysqlOpQuery constructs a CALL query from the specified operation. Keys of operation.Inputs must be integers, they are converted from string to int and then used to sort the parameters in the stored procedure call. If keys are not specified as integers, an error is returned.

func RenderGoTemplate added in v0.2.0

func RenderGoTemplate(text string, values interface{}, options ...string) (string, error)

RenderGoTemplate takes the text to be parsed as a Go template and values to be rendered. For options see template.Option.

Types

type Dbms

type Dbms struct {
	DatabaseClassName string     `json:"databaseClassName"`
	Endpoints         []Endpoint `json:"endpoints"`
}

+kubebuilder:object:generate=true Dbms is the instance associated with a Dbms resource. It contains the Driver responsible for the Operations executed on Endpoints.

func (*Dbms) DeepCopy added in v0.2.0

func (in *Dbms) DeepCopy() *Dbms

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Dbms.

func (*Dbms) DeepCopyInto added in v0.2.0

func (in *Dbms) DeepCopyInto(out *Dbms)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

type DbmsConn

type DbmsConn struct {
	Driver
}

DbmsConn represents the DBMS connection. See Driver.

func New

func New(driver string, dsn Dsn) (*DbmsConn, error)

New initializes a Dbms instance based on a map of Operation. It expects a dsn like that: driver://username:password@host/instance?param1=value&param2=value

See the individual Driver implementations.

type DbmsList added in v0.2.0

type DbmsList []Dbms

+kubebuilder:object:generate=true DbmsList is a slice containing Dbms structs.

func (DbmsList) DeepCopy added in v0.2.0

func (in DbmsList) DeepCopy() DbmsList

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DbmsList.

func (DbmsList) DeepCopyInto added in v0.2.0

func (in DbmsList) DeepCopyInto(out *DbmsList)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (DbmsList) GetDatabaseClassNameByEndpointName added in v0.2.0

func (c DbmsList) GetDatabaseClassNameByEndpointName(endpointName string) string

GetDatabaseClassNameByEndpointName performs a linear search on the receiver in search of endpointName. If an entry is found, it is returned.

type Driver

type Driver interface {
	CreateDb(operation Operation) OpOutput
	DeleteDb(operation Operation) OpOutput
	Rotate(operation Operation) OpOutput
	Ping() error
}

Driver represents a struct responsible for executing CreateDb and DeleteDb operations on a system it supports. Drivers should provide a way to check their current status (i.e. whether it can accept CreateDb and DeleteDb operations at the moment of a Ping call

type Dsn

type Dsn string

func (Dsn) GenMysql added in v0.2.0

func (dsn Dsn) GenMysql() (string, error)

func (Dsn) GenPostgres added in v0.2.0

func (dsn Dsn) GenPostgres() (string, error)

func (Dsn) GenSqlserver added in v0.2.0

func (dsn Dsn) GenSqlserver() (string, error)

func (Dsn) String

func (dsn Dsn) String() string

String returns a string from a Dsn.

type Endpoint

type Endpoint struct {
	Name         string       `json:"name"`
	SecretKeyRef SecretKeyRef `json:"secretKeyRef,omitempty"`
	Dsn          Dsn          `json:"dsn,omitempty"`
}

+kubebuilder:object:generate=true +kubebuilder:kubebuilder:validation:MinItems=1 Endpoint represent the configuration of a DBMS endpoint identified by a name.

func (*Endpoint) DeepCopy added in v0.2.0

func (in *Endpoint) DeepCopy() *Endpoint

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Endpoint.

func (*Endpoint) DeepCopyInto added in v0.2.0

func (in *Endpoint) DeepCopyInto(out *Endpoint)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (Endpoint) IsDsnPresent

func (e Endpoint) IsDsnPresent() bool

IsDsnPresent return true if an endpoint dsn is not empty, else it returns false.

func (Endpoint) IsNamePresent

func (e Endpoint) IsNamePresent() bool

IsNamePresent return true if an endpoint name is not empty, else it returns false.

type MysqlConn added in v0.2.0

type MysqlConn struct {
	// contains filtered or unexported fields
}

MysqlConn represents a connection to a MySQL DBMS.

func NewMysqlConn added in v0.2.0

func NewMysqlConn(dsn string) (*MysqlConn, error)

NewMysqlConn opens a new SQL Server connection from a given dsn.

func (*MysqlConn) CreateDb added in v0.2.0

func (c *MysqlConn) CreateDb(operation Operation) OpOutput

CreateDb attempts to create a new database as specified in the operation parameter. It returns an OpOutput with the result of the call.

func (*MysqlConn) DeleteDb added in v0.2.0

func (c *MysqlConn) DeleteDb(operation Operation) OpOutput

DeleteDb attempts to delete a database instance as specified in the operation parameter. It returns an OpOutput with the result of the call if present.

func (*MysqlConn) Ping added in v0.2.0

func (c *MysqlConn) Ping() error

Ping returns an error if a connection cannot be established with the DBMS, else it returns nil.

func (*MysqlConn) Rotate added in v0.2.0

func (c *MysqlConn) Rotate(operation Operation) OpOutput

Rotate attempts to rotate the credentials of a connection.

type OpOutput

type OpOutput struct {
	Result map[string]string
	Err    error
}

OpOutput represents the return values of an operation. If the operation generates an error, it must be set in the Err field. If Err is nil, the operation is assumed to be successful.

type OpValues

type OpValues struct {
	Metadata   map[string]interface{}
	Parameters map[string]string
}

OpValues represent the input values of an operation.

type Operation

type Operation struct {
	Name   string            `json:"name,omitempty"`
	Inputs map[string]string `json:"inputs,omitempty"`
}

+kubebuilder:object:generate=true Operation represents an operation performed on a DBMS identified by name and containing a map of inputs and a map of outputs.

func (*Operation) DeepCopy added in v0.2.0

func (in *Operation) DeepCopy() *Operation

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Operation.

func (*Operation) DeepCopyInto added in v0.2.0

func (in *Operation) DeepCopyInto(out *Operation)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (Operation) RenderOperation added in v0.2.0

func (op Operation) RenderOperation(values OpValues) (Operation, error)

RenderOperation renders "actions" specified through the use of the Go text/template format. It renders Input of the receiver. Data to be inserted is taken directly from values. See OpValues. If the rendering is successful, the method returns ah na rendered Operation, if an error is generated, it is returned along with an empty Operation struct. Keys which are specified but not found generate an error (i.e. no unreferenced keys are allowed).

type PsqlConn

type PsqlConn struct {
	// contains filtered or unexported fields
}

PsqlConn represents a connection to a SQL Server DBMS.

func NewPsqlConn

func NewPsqlConn(dsn string) (*PsqlConn, error)

NewPsqlConn opens a new PostgreSQL connection from a given dsn.

func (*PsqlConn) CreateDb

func (c *PsqlConn) CreateDb(operation Operation) OpOutput

CreateDb attempts to create a new database as specified in the operation parameter. It returns an OpOutput with the result of the call.

func (*PsqlConn) DeleteDb

func (c *PsqlConn) DeleteDb(operation Operation) OpOutput

DeleteDb attempts to delete a database instance as specified in the operation parameter. It returns an OpOutput with the result of the call if present.

func (*PsqlConn) Ping

func (c *PsqlConn) Ping() error

Ping returns an error if a connection cannot be established with the DBMS, else it returns nil.

func (*PsqlConn) Rotate added in v0.2.0

func (c *PsqlConn) Rotate(operation Operation) OpOutput

Rotate attempts to rotate the credentials of a connection.

type RateLimitedDbmsConn added in v0.2.0

type RateLimitedDbmsConn struct {
	Driver
	// contains filtered or unexported fields
}

func NewRateLimitedDbmsConn added in v0.2.0

func NewRateLimitedDbmsConn(dbmsConn Driver, rps int) (*RateLimitedDbmsConn, error)

NewRateLimitedDbmsConn returns a new rate-limited dbms connection. Rps specifies the number of allowed requests per second for this dbms connection. If rps is equal to 0, it returns a connection that is not rate-limited. Rps cannot be a negative number.

func (*RateLimitedDbmsConn) CreateDb added in v0.2.0

func (conn *RateLimitedDbmsConn) CreateDb(operation Operation) OpOutput

func (*RateLimitedDbmsConn) DeleteDb added in v0.2.0

func (conn *RateLimitedDbmsConn) DeleteDb(operation Operation) OpOutput

func (*RateLimitedDbmsConn) Ping added in v0.2.0

func (conn *RateLimitedDbmsConn) Ping() error

type SecretFormat added in v0.2.0

type SecretFormat map[string]string

+kubebuilder:object:generate=true

func (SecretFormat) DeepCopy added in v0.2.0

func (in SecretFormat) DeepCopy() SecretFormat

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SecretFormat.

func (SecretFormat) DeepCopyInto added in v0.2.0

func (in SecretFormat) DeepCopyInto(out *SecretFormat)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (SecretFormat) RenderSecretFormat added in v0.2.0

func (s SecretFormat) RenderSecretFormat(createOpOutput OpOutput) (SecretFormat, error)

RenderSecretFormat renders a secret from OpOutput.Result create operation.

type SecretKeyRef added in v1.0.0

type SecretKeyRef struct {
	Name string `json:"name"`
	Key  string `json:"key"`
}

SecretKeyRef specifies a reference to a value contained in a Secret resource identified by name and key.

type SqlserverConn added in v0.2.0

type SqlserverConn struct {
	// contains filtered or unexported fields
}

SqlserverConn represents a connection to a SQL Server DBMS.

func NewSqlserverConn added in v0.2.0

func NewSqlserverConn(dsn string) (*SqlserverConn, error)

NewSqlserverConn opens a new SQL Server connection from a given dsn.

func (*SqlserverConn) CreateDb added in v0.2.0

func (c *SqlserverConn) CreateDb(operation Operation) OpOutput

CreateDb attempts to create a new database as specified in the operation parameter. It returns an OpOutput with the result of the call.

func (*SqlserverConn) DeleteDb added in v0.2.0

func (c *SqlserverConn) DeleteDb(operation Operation) OpOutput

DeleteDb attempts to delete a database instance as specified in the operation parameter. It returns an OpOutput with the result of the call.

func (*SqlserverConn) Ping added in v0.2.0

func (c *SqlserverConn) Ping() error

func (*SqlserverConn) Rotate added in v0.2.0

func (c *SqlserverConn) Rotate(operation Operation) OpOutput

Rotate attempts to rotate the credentials of a connection.

Jump to

Keyboard shortcuts

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