Documentation ¶
Index ¶
- func DBInit(dbConfig *config.DBConfig, logger lager.Logger) (*gorm.DB, error)
- func RotateKey(db *gorm.DB, old_key, new_key []byte, logger lager.Logger, failFast bool) error
- type DBBinding
- type DBInstance
- func (i *DBInstance) Bind(db *gorm.DB, bindingID, username string, userType DBUserType, key []byte) (user DBUser, new bool, err error)
- func (i *DBInstance) BindingUser(bindingID string) (*DBUser, *DBBinding)
- func (i *DBInstance) Delete(db *gorm.DB) error
- func (i *DBInstance) MasterUser() *DBUser
- func (i *DBInstance) NewUser(userType DBUserType, key []byte) (DBUser, error)
- func (i *DBInstance) Unbind(db *gorm.DB, bindingID string) (user DBUser, delete bool, err error)
- func (i *DBInstance) UnderscoreID() string
- func (i *DBInstance) User(username string) *DBUser
- type DBUser
- type DBUserType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
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) 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) 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 (*DBUser) SetRandomPassword ¶
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
Click to show internal directories.
Click to hide internal directories.