dbutil

package
v0.0.0-...-a0081c5 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetCADataSource

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

GetCADataSource returns a datasource with a unqiue database name

func GetNewAttributes

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

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

func MaskDBCred

func MaskDBCred(str string) string

MaskDBCred hides DB credentials in connection string

func Migrate

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

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

func (db *DB) BeginTx() FabricCATx

BeginTx implements BeginTx method of FabricCADB interface

func (*DB) IsInitialized

func (db *DB) IsInitialized() bool

IsInitialized returns true if db is intialized, else false

type FabricCADB

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

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

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

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

CurrentDBLevels returns current levels from the database

type User

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

User is the databases representation of a user

func NewDBUser

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

NewDBUser creates a DBUser object from the DB user record

func (*User) GetAffiliationPath

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

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

func (*User) GetAttribute

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

GetAttribute returns the value for an attribute name

func (*User) GetAttributes

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

func (u *User) GetFailedLoginAttempts() int

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

func (*User) GetLevel

func (u *User) GetLevel() int

GetLevel returns the level of the user

func (*User) GetMaxEnrollments

func (u *User) GetMaxEnrollments() int

GetMaxEnrollments returns the max enrollments of the user

func (*User) GetName

func (u *User) GetName() string

GetName returns the enrollment ID of the user

func (*User) GetPass

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

GetPass returns the hashed password of the user

func (*User) GetType

func (u *User) GetType() string

GetType returns the type of the user

func (*User) IncrementIncorrectPasswordAttempts

func (u *User) IncrementIncorrectPasswordAttempts() error

IncrementIncorrectPasswordAttempts updates the incorrect password count of user

func (*User) IsRevoked

func (u *User) IsRevoked() bool

IsRevoked returns back true if user is revoked

func (*User) Login

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

Login the user with a password

func (*User) LoginComplete

func (u *User) LoginComplete() error

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

func (*User) ModifyAttributes

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

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

func (*User) ModifyAttributesTx

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

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

func (*User) Revoke

func (u *User) Revoke() error

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

func (*User) SetLevel

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

SetLevel sets the level of the user

func (*User) SetLevelTx

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

SetLevelTx sets the level of the user

type UserRecord

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