dbutil

package
v1.4.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2018 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCADataSource added in v1.1.0

func GetCADataSource(dbtype, datasource string, cacount int) string

GetCADataSource returns a datasource with a unqiue database name

func GetNewAttributes added in v1.4.0

func GetNewAttributes(modifyAttrs, newAttrs []api.Attribute) []api.Attribute

GetNewAttributes updates existing attribute, or add attribute if it does not already exist

func MaskDBCred added in v1.0.5

func MaskDBCred(str string) string

MaskDBCred hides DB credentials in connection string

func Migrate added in v1.4.0

func Migrate(db *DB, srvLevels *Levels) error

Migrate updates the database tables to use the latest schema and does data migration if needed

Types

type DB added in v1.2.0

type DB struct {
	*sqlx.DB
	// Indicates if database was successfully initialized
	IsDBInitialized bool
}

DB is an adapter for sqlx.DB and implements FabricCADB interface

func NewUserRegistryMySQL

func NewUserRegistryMySQL(datasource string, clientTLSConfig *tls.ClientTLSConfig, csp bccsp.BCCSP) (*DB, error)

NewUserRegistryMySQL opens a connection to a postgres database

func NewUserRegistryPostgres

func NewUserRegistryPostgres(datasource string, clientTLSConfig *tls.ClientTLSConfig) (*DB, error)

NewUserRegistryPostgres opens a connection to a postgres database

func NewUserRegistrySQLLite3

func NewUserRegistrySQLLite3(datasource string) (*DB, error)

NewUserRegistrySQLLite3 returns a pointer to a sqlite database

func (*DB) BeginTx added in v1.2.0

func (db *DB) BeginTx() FabricCATx

BeginTx implements BeginTx method of FabricCADB interface

func (*DB) IsInitialized added in v1.2.0

func (db *DB) IsInitialized() bool

IsInitialized returns true if db is intialized, else false

type FabricCADB added in v1.2.0

type FabricCADB interface {
	IsInitialized() bool
	Select(dest interface{}, query string, args ...interface{}) error
	Exec(query string, args ...interface{}) (sql.Result, error)
	NamedExec(query string, arg interface{}) (sql.Result, error)
	Rebind(query string) string
	MustBegin() *sqlx.Tx
	// BeginTx has same behavior as MustBegin except it returns FabricCATx
	// instead of *sqlx.Tx
	BeginTx() FabricCATx
}

FabricCADB is the interface with functions implemented by sqlx.DB object that are used by Fabric CA server

type FabricCATx added in v1.2.0

type FabricCATx interface {
	Queryx(query string, args ...interface{}) (*sqlx.Rows, error)
	Select(dest interface{}, query string, args ...interface{}) error
	Rebind(query string) string
	Exec(query string, args ...interface{}) (sql.Result, error)
	Commit() error
	Rollback() error
}

FabricCATx is the interface with functions implemented by sqlx.Tx object that are used by Fabric CA server

type Levels added in v1.1.0

type Levels struct {
	Identity    int
	Affiliation int
	Certificate int
	Credential  int
	RAInfo      int
	Nonce       int
}

Levels contains the levels of identities, affiliations, and certificates

func CurrentDBLevels added in v1.4.0

func CurrentDBLevels(db *DB) (*Levels, error)

CurrentDBLevels returns current levels from the database

type User added in v1.4.0

type User struct {
	spi.UserInfo
	// contains filtered or unexported fields
}

User is the databases representation of a user

func NewDBUser added in v1.4.0

func NewDBUser(userRec *UserRecord, db *DB) *User

NewDBUser creates a DBUser object from the DB user record

func (*User) GetAffiliationPath added in v1.4.0

func (u *User) GetAffiliationPath() []string

GetAffiliationPath returns the complete path for the user's affiliation.

func (*User) GetAttribute added in v1.4.0

func (u *User) GetAttribute(name string) (*api.Attribute, error)

GetAttribute returns the value for an attribute name

func (*User) GetAttributes added in v1.4.0

func (u *User) GetAttributes(attrNames []string) ([]api.Attribute, error)

GetAttributes returns the requested attributes. Return all the user's attributes if nil is passed in

func (*User) GetFailedLoginAttempts added in v1.4.0

func (u *User) GetFailedLoginAttempts() int

GetFailedLoginAttempts returns the number of times the user has entered an incorrect password

func (*User) GetLevel added in v1.4.0

func (u *User) GetLevel() int

GetLevel returns the level of the user

func (*User) GetMaxEnrollments added in v1.4.0

func (u *User) GetMaxEnrollments() int

GetMaxEnrollments returns the max enrollments of the user

func (*User) GetName added in v1.4.0

func (u *User) GetName() string

GetName returns the enrollment ID of the user

func (*User) GetPass added in v1.4.0

func (u *User) GetPass() []byte

GetPass returns the hashed password of the user

func (*User) GetType added in v1.4.0

func (u *User) GetType() string

GetType returns the type of the user

func (*User) IncrementIncorrectPasswordAttempts added in v1.4.0

func (u *User) IncrementIncorrectPasswordAttempts() error

IncrementIncorrectPasswordAttempts updates the incorrect password count of user

func (*User) IsRevoked added in v1.4.0

func (u *User) IsRevoked() bool

IsRevoked returns back true if user is revoked

func (*User) Login added in v1.4.0

func (u *User) Login(pass string, caMaxEnrollments int) error

Login the user with a password

func (*User) LoginComplete added in v1.4.0

func (u *User) LoginComplete() error

LoginComplete completes the login process by incrementing the state of the user

func (*User) ModifyAttributes added in v1.4.0

func (u *User) ModifyAttributes(newAttrs []api.Attribute) error

ModifyAttributes adds a new attribute, modifies existing attribute, or delete attribute

func (*User) ModifyAttributesTx added in v1.4.0

func (u *User) ModifyAttributesTx(tx FabricCATx, newAttrs []api.Attribute) error

ModifyAttributesTx adds a new attribute, modifies existing attribute, or delete attribute

func (*User) Revoke added in v1.4.0

func (u *User) Revoke() error

Revoke will revoke the user, setting the state of the user to be -1

func (*User) SetLevel added in v1.4.0

func (u *User) SetLevel(level int) error

SetLevel sets the level of the user

func (*User) SetLevelTx added in v1.4.0

func (u *User) SetLevelTx(tx FabricCATx, level int) error

SetLevelTx sets the level of the user

type UserRecord added in v1.4.0

type UserRecord struct {
	Name                      string `db:"id"`
	Pass                      []byte `db:"token"`
	Type                      string `db:"type"`
	Affiliation               string `db:"affiliation"`
	Attributes                string `db:"attributes"`
	State                     int    `db:"state"`
	MaxEnrollments            int    `db:"max_enrollments"`
	Level                     int    `db:"level"`
	IncorrectPasswordAttempts int    `db:"incorrect_password_attempts"`
}

UserRecord defines the properties of a user

Directories

Path Synopsis
Code generated by mockery v1.0.0.
Code generated by mockery v1.0.0.

Jump to

Keyboard shortcuts

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