Skip to content

Commit

Permalink
[FAB-5697] Make identity type optional to register
Browse files Browse the repository at this point in the history
Currently identity type is required to register an
identity. With this change identity type is not longer
required. If identity type is not specified, it is set
to default value 'user'

Change-Id: I0379c76cc10731c076547a144b6e74ae9e6bf4fc
Signed-off-by: Anil Ambati <[email protected]>
  • Loading branch information
Anil Ambati committed Aug 27, 2017
1 parent f0e1701 commit 446f9cf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 1 addition & 1 deletion api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type RegistrationRequest struct {
// Name is the unique name of the identity
Name string `json:"id" help:"Unique name of the identity"`
// Type of identity being registered (e.g. "peer, app, user")
Type string `json:"type" help:"Type of identity being registered (e.g. 'peer, app, user')"`
Type string `json:"type" def:"user" help:"Type of identity being registered (e.g. 'peer, app, user')"`
// Secret is an optional password. If not specified,
// a random secret is generated. In both cases, the secret
// is returned in the RegistrationResponse.
Expand Down
10 changes: 10 additions & 0 deletions cmd/fabric-ca-client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,16 @@ func testRegisterCommandLine(t *testing.T, srv *lib.Server) {
t.Errorf("client register failed: %s", err)
}

// Register an identity without identity type parameter (--id.type). It should succeed.
// The identity type is set to default type "user"
userName := "testRegister5"
err = RunMain([]string{cmdName, "register", "-d", "--id.name", userName,
"--id.affiliation", "company2"})
assert.NoError(t, err, "Failed to register identity "+userName)
user, err = db.GetUserInfo(userName)
assert.NoError(t, err)
assert.Equal(t, "user", user.Type, "Identity type for '%s' should have been 'user'", userName)

os.Remove(defYaml) // Delete default config file

err = RunMain([]string{cmdName, "register", "-u", "http://localhost:7091"})
Expand Down
10 changes: 5 additions & 5 deletions docs/source/users-guide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ The following shows the Fabric CA client usage message:
--id.maxenrollments int The maximum number of times the secret can be reused to enroll.
--id.name string Unique name of the identity
--id.secret string The enrollment secret for the identity being registered
--id.type string Type of identity being registered (e.g. 'peer, app, user')
--id.type string Type of identity being registered (e.g. 'peer, app, user') (default "user")
-M, --mspdir string Membership Service Provider directory (default "msp")
-m, --myhost string Hostname to include in the certificate signing request during enrollment (default "saads-mbp.raleigh.ibm.com")
-a, --revoke.aki string AKI (Authority Key Identifier) of the certificate to be revoked
Expand Down Expand Up @@ -1461,14 +1461,14 @@ during registration as follows:
of "a.b.c" but may not register an identity with an affiliation of "a.c".
The following command uses the **admin** identity's credentials to register a new
identity with an enrollment id of "admin2", a type of "user", an affiliation of
user with an enrollment id of "admin2", an affiliation of
"org1.department1", an attribute named "hf.Revoker" with a value of "true", and
an attribute named "foo" with a value of "bar".
.. code:: bash
export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
fabric-ca-client register --id.name admin2 --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar'
fabric-ca-client register --id.name admin2 --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar'
The password, also known as the enrollment secret, is printed.
This password is required to enroll the identity.
Expand All @@ -1481,13 +1481,13 @@ the attribute must be encapsulated in double quotes. See example below.
.. code:: bash
fabric-ca-client register -d --id.name admin2 --id.type user --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,user",hf.Revoker=true'
fabric-ca-client register -d --id.name admin2 --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,user",hf.Revoker=true'
or
.. code:: bash
fabric-ca-client register -d --id.name admin2 --id.type user --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,user"' --id.attrs hf.Revoker=true
fabric-ca-client register -d --id.name admin2 --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,user"' --id.attrs hf.Revoker=true
You may set default values for any of the fields used in the register command
by editing the client's configuration file. For example, suppose the configuration
Expand Down
16 changes: 7 additions & 9 deletions lib/serverregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func registerUser(req *api.RegistrationRequestNet, registrar string, ca *CA) (st

if registrar != "" {
// Check the permissions of member named 'registrar' to perform this registration
err = canRegister(registrar, req.Type, ca)
err = canRegister(registrar, req, ca)
if err != nil {
log.Debugf("Registration of '%s' failed: %s", req.Name, err)
return "", err
Expand Down Expand Up @@ -168,7 +168,7 @@ func requireAffiliation(idType string) bool {
return true
}

func canRegister(registrar string, userType string, ca *CA) error {
func canRegister(registrar string, req *api.RegistrationRequestNet, ca *CA) error {
log.Debugf("canRegister - Check to see if user %s can register", registrar)

user, err := ca.registry.GetUser(registrar, nil)
Expand All @@ -183,13 +183,11 @@ func canRegister(registrar string, userType string, ca *CA) error {
} else {
roles = make([]string, 0)
}
if userType != "" {
if !util.StrContained(userType, roles) {
return errors.Errorf("Identity '%s' may not register type '%s'", registrar, userType)
}
} else {
return errors.New("No identity type provided. Please provide identity type")
if req.Type == "" {
req.Type = "user"
}
if !util.StrContained(req.Type, roles) {
return fmt.Errorf("Identity '%s' may not register type '%s'", registrar, req.Type)
}

return nil
}
1 change: 0 additions & 1 deletion swagger/swagger-fabric-ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@
},
"required": [
"id",
"type",
"affiliation_path",
"attrs"
]
Expand Down

0 comments on commit 446f9cf

Please sign in to comment.