internaldb

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2017 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBInit

func DBInit(dbConfig *config.DBConfig, logger lager.Logger) (*gorm.DB, error)

Supported DB types: * postgres * sqlite3

func RotateKey

func RotateKey(db *gorm.DB, old_key, new_key []byte, logger lager.Logger, failFast bool) error

Types

type DBBinding

type DBBinding struct {
	ID        uint64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
	BindingID string
	DBUser    DBUser // gorm belongs to relationship
	DBUserID  uint64
}

type DBInstance

type DBInstance struct {
	// Managed by gorm
	ID        uint64 `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
	// Managed by us
	InstanceID string `gorm:"unique_index"`
	DBName     string
	ServiceID  string
	PlanID     string
	Users      []DBUser
}

func FindInstance

func FindInstance(db *gorm.DB, instanceID string) *DBInstance

Use this wrapper so we always preload the users

func NewInstance

func NewInstance(serviceID, planID, instanceID, dbPrefix string, key []byte) (*DBInstance, error)

Remember to DB.Save() from the caller

func (*DBInstance) Bind

func (i *DBInstance) Bind(db *gorm.DB, bindingID, username string, userType DBUserType, key []byte) (user DBUser, new bool, err error)

func (*DBInstance) BindingUser

func (i *DBInstance) BindingUser(bindingID string) (*DBUser, *DBBinding)

func (*DBInstance) Delete

func (i *DBInstance) Delete(db *gorm.DB) error

func (*DBInstance) MasterUser

func (i *DBInstance) MasterUser() *DBUser

We currently preload all users from the database and do the search in go code. We could also load the ones we need on demand using appropriate database queries. Given the number of users is expected to be small (usually just one Master and one Standard) the preload way seems fine for now.

func (*DBInstance) NewUser

func (i *DBInstance) NewUser(userType DBUserType, key []byte) (DBUser, error)

func (*DBInstance) Unbind

func (i *DBInstance) Unbind(db *gorm.DB, bindingID string) (user DBUser, delete bool, err error)

func (*DBInstance) UnderscoreID

func (i *DBInstance) UnderscoreID() string

func (*DBInstance) User

func (i *DBInstance) User(username string) *DBUser

type DBUser

type DBUser struct {
	ID                uint64 `gorm:"primary_key"`
	CreatedAt         time.Time
	UpdatedAt         time.Time
	DBInstance        DBInstance // gorm belongs to relationship
	DBInstanceID      uint64
	Username          string
	EncryptedPassword []byte
	IV                []byte
	Type              DBUserType
	Bindings          []DBBinding
}

func NewUser

func NewUser(userType DBUserType, key []byte) (DBUser, error)

func (*DBUser) Delete

func (u *DBUser) Delete(db *gorm.DB) error

func (*DBUser) Password

func (u *DBUser) Password(key []byte) (string, error)

func (*DBUser) SetPassword

func (u *DBUser) SetPassword(password string, key []byte) error

func (*DBUser) SetRandomPassword

func (u *DBUser) SetRandomPassword(key []byte) error

type DBUserType

type DBUserType string
const (
	Master    DBUserType = "master"
	SuperUser DBUserType = "superuser"
	Standard  DBUserType = "standard"
)

func (*DBUserType) Scan

func (u *DBUserType) Scan(value interface{}) error

Ensure custom string type works with gorm/sql https://github.com/jinzhu/gorm/issues/302

func (DBUserType) Value

func (u DBUserType) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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