Skip to content

Commit

Permalink
[FAB-6662] Make enroll attrs required by default
Browse files Browse the repository at this point in the history
Currently, the AttributeRequest struct has "Require" attribute.
It is set to false if the user does not specify the attribute.
But the fabric-ca-client command line considers the enrollment
attributes as required if the attributes are not qualified
with ":opt".

This change set makes the API and command line client consistent.
The "Require" attribute of AttributeRequest struct has been changed
to "Optional", whose value is false by default. This makes the
specified enrollment attributes required by default.

Change-Id: I4710174a3e1d7a5a2026c7a482d77219d337e6a2
Signed-off-by: Anil Ambati <[email protected]>
  • Loading branch information
Anil Ambati committed Oct 17, 2017
1 parent b74248d commit 7b42a83
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions api/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ func (a *Attribute) GetValue() string {
// AttributeRequest is a request for an attribute.
// This implements the certmgr/AttributeRequest interface.
type AttributeRequest struct {
Name string `json:"name"`
Require bool `json:"require,omitempty"`
Name string `json:"name"`
Optional bool `json:"optional,omitempty"`
}

// GetName returns the name of an attribute being requested
Expand All @@ -206,5 +206,5 @@ func (ar *AttributeRequest) GetName() string {

// IsRequired returns true if the attribute being requested is required
func (ar *AttributeRequest) IsRequired() bool {
return ar.Require
return !ar.Optional
}
4 changes: 2 additions & 2 deletions cmd/fabric-ca-client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,12 @@ func processAttributeRequests(cfgAttrReqs []string, cfg *lib.ClientConfig) error
name := sreq[0]
switch len(sreq) {
case 1:
reqs[idx] = &api.AttributeRequest{Name: name, Require: true}
reqs[idx] = &api.AttributeRequest{Name: name}
case 2:
if sreq[1] != "opt" {
return errors.Errorf("Invalid option in attribute request specification at '%s'; the value after the colon must be 'opt'", req)
}
reqs[idx] = &api.AttributeRequest{Name: name, Require: false}
reqs[idx] = &api.AttributeRequest{Name: name, Optional: true}
default:
return errors.Errorf("Multiple ':' characters not allowed in attribute request specification; error at '%s'", req)
}
Expand Down
6 changes: 3 additions & 3 deletions lib/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func testRegister(c *Client, t *testing.T) {
Name: userName,
Secret: resp.Secret,
AttrReqs: []*api.AttributeRequest{
&api.AttributeRequest{Name: "attr1", Require: true},
&api.AttributeRequest{Name: "attr1"},
},
}
eresp, err = c.Enroll(req)
Expand All @@ -337,8 +337,8 @@ func testRegister(c *Client, t *testing.T) {
Name: userName,
Secret: resp.Secret,
AttrReqs: []*api.AttributeRequest{
&api.AttributeRequest{Name: "attr1"},
&api.AttributeRequest{Name: "attr3", Require: true},
&api.AttributeRequest{Name: "attr1", Optional: true},
&api.AttributeRequest{Name: "attr3"},
},
}
eresp, err = c.Enroll(req)
Expand Down
16 changes: 8 additions & 8 deletions swagger/swagger-fabric-ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,10 @@
"type": "string",
"description": "The name of the attribute being requested to put into the enrollment certificate."
},
"require": {
"optional": {
"type": "boolean",
"description": "Boolean indicating whether the attribute is required and thus return an error if not found; the default value is false."
},
"description": "Boolean indicating whether the attribute is optional. An error is returned if the attribute is required but not found. The default value is false."
}
},
"required": [
"name"
Expand Down Expand Up @@ -215,7 +215,7 @@
"cert": {
"type": "string",
"description": "The enrollment certificate in base 64 encoded format."
},
}
}
},
"Errors": {
Expand Down Expand Up @@ -329,10 +329,10 @@
"type": "string",
"description": "The name of the attribute being requested to put into the enrollment certificate."
},
"require": {
"optional": {
"type": "boolean",
"description": "Boolean indicating whether the attribute is required and thus return an error if not found; the default value is false."
},
"description": "Boolean indicating whether the attribute is optional. An error is returned if the attribute is required but not found. The default value is false."
}
},
"required": [
"name"
Expand Down Expand Up @@ -362,7 +362,7 @@
"cert": {
"type": "string",
"description": "The enrollment certificate in base 64 encoded format."
},
}
}
},
"Errors": {
Expand Down

0 comments on commit 7b42a83

Please sign in to comment.