Skip to content

Commit

Permalink
[FAB-3107] Use 'identity' instead of 'user'
Browse files Browse the repository at this point in the history
Currently, user and identity are being used interchangeably,
which causes confusion. This change set contains changes
to use 'identity' in all the messages.

Change-Id: Ie6afd502d8e3cff087f318084f4861ff8569c1b9
Signed-off-by: Anil Ambati <[email protected]>
  • Loading branch information
Anil Ambati committed Apr 21, 2017
1 parent 7382805 commit a13fc7c
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 73 deletions.
11 changes: 5 additions & 6 deletions cmd/fabric-ca-client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ const (
URL: <<<URL>>>
# Membership Service Provider (MSP) directory
# This is useful when the client is used to enroll a peer or orderer, so
# that the enrollment artifacts are stored in the format expected by MSP.
# When the client is used to enroll a peer or an orderer, this field must be
# set to the MSP directory of the peer/orderer
MSPDir:
#############################################################################
Expand Down Expand Up @@ -117,18 +117,18 @@ csr:
expiry:
#############################################################################
# Registration section used to register a new user with fabric-ca server
# Registration section used to register a new identity with fabric-ca server
#############################################################################
id:
name:
type:
affiliation:
attributes:
attrs:
- name:
value:
#############################################################################
# Enrollment section used to enroll a user with fabric-ca server
# Enrollment section used to enroll an identity with fabric-ca server
#############################################################################
enrollment:
hosts:
Expand All @@ -146,7 +146,6 @@ var (
)

func configInit(command string) error {

var err error

if cfgFileName != "" {
Expand Down
7 changes: 3 additions & 4 deletions cmd/fabric-ca-client/enroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ var (
// initCmd represents the init command
var enrollCmd = &cobra.Command{
Use: "enroll -u http://user:userpw@serverAddr:serverPort",
Short: "Enroll user",
Long: "Enroll user with fabric-ca server",
Short: "Enroll an identity",
Long: "Enroll identity with fabric-ca server",
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
cmd.Help()
Expand All @@ -57,8 +57,7 @@ func init() {

// The client enroll main logic
func runEnroll(cmd *cobra.Command) error {
log.Debug("Entered Enroll")

log.Debug("Entered runEnroll")
_, _, err := util.GetUser()
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions cmd/fabric-ca-client/reenroll.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import (
// initCmd represents the init command
var reenrollCmd = &cobra.Command{
Use: "reenroll",
Short: "Reenroll user",
Long: "Reenroll user with fabric-ca server",
Short: "Reenroll an identity",
Long: "Reenroll an identity with fabric-ca server",
PreRunE: func(cmd *cobra.Command, args []string) error {
err := configInit(cmd.Name())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fabric-ca-client/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import (
// initCmd represents the init command
var registerCmd = &cobra.Command{
Use: "register",
Short: "Register user",
Long: "Register user with fabric-ca server",
Short: "Register an identity",
Long: "Register an identity with fabric-ca server",
PreRunE: func(cmd *cobra.Command, args []string) error {
err := configInit(cmd.Name())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fabric-ca-client/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ var errInput = errors.New("Invalid usage; either --eid or both --serial and --ak
// initCmd represents the init command
var revokeCmd = &cobra.Command{
Use: "revoke",
Short: "Revoke user",
Long: "Revoke user with fabric-ca server",
Short: "Revoke an identity",
Long: "Revoke an identity with fabric-ca server",
PreRunE: func(cmd *cobra.Command, args []string) error {
err := configInit(cmd.Name())
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/fabric-ca-server/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ registry:
# (default: 0, which means there is no limit)
maxEnrollments: 0
# Contains user information which is used when LDAP is disabled
# Contains identity information which is used when LDAP is disabled
identities:
- name: <<<ADMIN>>>
pass: <<<ADMINPW>>>
Expand Down Expand Up @@ -330,7 +330,7 @@ func createDefaultConfigFile() error {
user := ups[0]
pass := ups[1]
if len(user) >= 1024 {
return fmt.Errorf("The user name must be less than 1024 characters: '%s'", user)
return fmt.Errorf("The identity name must be less than 1024 characters: '%s'", user)
}
if len(pass) == 0 {
return errors.New("An empty password in the '-b user:pass' option is not permitted")
Expand Down
56 changes: 31 additions & 25 deletions lib/dbaccessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (d *Accessor) SetDB(db *sqlx.DB) {

// InsertUser inserts user into database
func (d *Accessor) InsertUser(user spi.UserInfo) error {
log.Debugf("DB: Insert User (%s) to database", user.Name)
log.Debugf("DB: Add identity %s", user.Name)

err := d.checkDB()
if err != nil {
Expand All @@ -125,7 +125,7 @@ func (d *Accessor) InsertUser(user spi.UserInfo) error {
})

if err != nil {
log.Error("Error during inserting of user, error: ", err)
log.Errorf("Error adding identity %s to the database: %s", user.Name, err)
return err
}

Expand All @@ -135,22 +135,22 @@ func (d *Accessor) InsertUser(user spi.UserInfo) error {
}

if numRowsAffected == 0 {
return fmt.Errorf("Failed to insert the user record")
return fmt.Errorf("Failed to add identity %s to the database", user.Name)
}

if numRowsAffected != 1 {
return fmt.Errorf("Expected one user record to be inserted, but %d records were inserted", numRowsAffected)
return fmt.Errorf("Expected to add one record to the database, but %d records were added", numRowsAffected)
}

log.Debugf("User %s inserted into database successfully", user.Name)
log.Debugf("Successfully added Identity %s to the database", user.Name)

return nil

}

// DeleteUser deletes user from database
func (d *Accessor) DeleteUser(id string) error {
log.Debugf("DB: Delete User (%s)", id)
log.Debugf("DB: Delete identity %s", id)
err := d.checkDB()
if err != nil {
return err
Expand All @@ -166,7 +166,7 @@ func (d *Accessor) DeleteUser(id string) error {

// UpdateUser updates user in database
func (d *Accessor) UpdateUser(user spi.UserInfo) error {
log.Debugf("DB: Update User (%s) in database", user.Name)
log.Debugf("DB: Update identity %s", user.Name)
err := d.checkDB()
if err != nil {
return err
Expand All @@ -188,18 +188,18 @@ func (d *Accessor) UpdateUser(user spi.UserInfo) error {
})

if err != nil {
log.Errorf("Failed to update user record [error: %s]", err)
log.Errorf("Failed to update identity record [error: %s]", err)
return err
}

numRowsAffected, err := res.RowsAffected()

if numRowsAffected == 0 {
return fmt.Errorf("Failed to update the user record")
return fmt.Errorf("Failed to update the identity record")
}

if numRowsAffected != 1 {
return fmt.Errorf("Expected one user record to be updated, but %d records were updated", numRowsAffected)
return fmt.Errorf("Expected one identity record to be updated, but %d records were updated", numRowsAffected)
}

return err
Expand All @@ -208,7 +208,7 @@ func (d *Accessor) UpdateUser(user spi.UserInfo) error {

// GetUser gets user from database
func (d *Accessor) GetUser(id string, attrs []string) (spi.User, error) {
log.Debugf("Getting user %s from the database", id)
log.Debugf("DB: Getting identity %s", id)

err := d.checkDB()
if err != nil {
Expand All @@ -226,7 +226,7 @@ func (d *Accessor) GetUser(id string, attrs []string) (spi.User, error) {

// GetUserInfo gets user information from database
func (d *Accessor) GetUserInfo(id string) (spi.UserInfo, error) {
log.Debugf("Getting user %s information from the database", id)
log.Debugf("DB: Getting information for identity %s", id)

var userInfo spi.UserInfo

Expand Down Expand Up @@ -257,7 +257,7 @@ func (d *Accessor) GetUserInfo(id string) (spi.UserInfo, error) {

// InsertAffiliation inserts affiliation into database
func (d *Accessor) InsertAffiliation(name string, prekey string) error {
log.Debugf("DB: Insert Affiliation (%s)", name)
log.Debugf("DB: Add affiliation %s", name)
err := d.checkDB()
if err != nil {
return err
Expand All @@ -272,7 +272,7 @@ func (d *Accessor) InsertAffiliation(name string, prekey string) error {

// DeleteAffiliation deletes affiliation from database
func (d *Accessor) DeleteAffiliation(name string) error {
log.Debugf("DB: Delete Affiliation (%s)", name)
log.Debugf("DB: Delete affiliation %s", name)
err := d.checkDB()
if err != nil {
return err
Expand All @@ -288,7 +288,7 @@ func (d *Accessor) DeleteAffiliation(name string) error {

// GetAffiliation gets affiliation from database
func (d *Accessor) GetAffiliation(name string) (spi.Affiliation, error) {
log.Debugf("DB: Get Affiliation (%s)", name)
log.Debugf("DB: Get affiliation %s", name)
err := d.checkDB()
if err != nil {
return nil, err
Expand Down Expand Up @@ -341,29 +341,32 @@ func (u *DBUser) GetName() string {

// Login the user with a password
func (u *DBUser) Login(pass string) error {
log.Debugf("DB: Login user %s with max enrollments of %d and state of %d", u.Name, u.MaxEnrollments, u.State)
log.Debugf("DB: Login identity %s with max enrollments of %d and state of %d",
u.Name, u.MaxEnrollments, u.State)

// Check the password
if u.Pass != pass {
return errors.New("Incorrect password")
}

// If the maxEnrollments is set (i.e. >= 0), make sure we haven't exceeded this number of logins.
// The state variable keeps track of the number of previously successful logins.
// If the maxEnrollments is set (i.e. >= 0), make sure we haven't exceeded
// this number of logins. The state variable keeps track of the number of
// previously successful logins.
if u.MaxEnrollments >= 0 {

// If maxEnrollments is set to 0, user has unlimited enrollment
if u.MaxEnrollments != 0 {
if u.State >= u.MaxEnrollments {
return fmt.Errorf("No more enrollments left. The maximum number of enrollments is %d", u.MaxEnrollments)
return fmt.Errorf("No more enrollments left. The maximum number of enrollments is %d",
u.MaxEnrollments)
}
}

// Not exceeded, so attempt to increment the count
state := u.State + 1
res, err := u.db.Exec(u.db.Rebind("UPDATE users SET state = ? WHERE (id = ?)"), state, u.Name)
if err != nil {
return fmt.Errorf("Failed to update state of user %s to %d: %s", u.Name, state, err)
return fmt.Errorf("Failed to update state of identity %s to %d: %s",
u.Name, state, err)
}

numRowsAffected, err := res.RowsAffected()
Expand All @@ -373,17 +376,20 @@ func (u *DBUser) Login(pass string) error {
}

if numRowsAffected == 0 {
return fmt.Errorf("no rows were affected when updating the state of user %s", u.Name)
return fmt.Errorf("no rows were affected when updating the state of identity %s",
u.Name)
}

if numRowsAffected != 1 {
return fmt.Errorf("%d rows were affected when updating the state of user %s", numRowsAffected, u.Name)
return fmt.Errorf("%d rows were affected when updating the state of identity %s",
numRowsAffected, u.Name)
}

log.Debugf("Successfully incremented state for user %s to %d", u.Name, state)
log.Debugf("DB: Successfully incremented state for identity %s to %d",
u.Name, state)
}

log.Debugf("DB: user %s successfully logged in", u.Name)
log.Debugf("DB: identity %s successfully logged in", u.Name)

return nil

Expand Down
Loading

0 comments on commit a13fc7c

Please sign in to comment.