Skip to content

Commit c15db56

Browse files
authored
added possibility to name the user keys (#7)
#### Type of change - New feature #### Description This PR gives `cryptogen` to capability to create named certificates for users within a peer organization, as it is currently done with the `peers`. Before this fix, it was impossible to specify the name of a user, leading to the production of user crypto material that looked like: ```text users/ [email protected]/ [email protected]/ ``` With this additional functionality, if the user specifies a user with a Name: ```yaml Users: Count: 1 Specs: - Name: testuser ``` it will generate: ```text users/ [email protected]/ [email protected]/ [email protected]/ ``` The possibility of giving names to the user credentials is crucial to successfully handle the current deployment when using `cryptogen`, since the Ansible scripts use the hostname to identify the path where to locate the crypto material. Signed-off-by: pco <[email protected]>
1 parent c100e50 commit c15db56

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

cmd/cryptogen/main.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,15 @@ type NodeSpec struct {
6565
PublicKeyAlgorithm string `yaml:"PublicKeyAlgorithm"`
6666
}
6767

68+
// UserSpec Contains User specifications needed to customize the crypto material generation.
69+
type UserSpec struct {
70+
Name string `yaml:"Name"`
71+
}
72+
6873
type UsersSpec struct {
69-
Count int `yaml:"Count"`
70-
PublicKeyAlgorithm string `yaml:"PublicKeyAlgorithm"`
74+
Count int `yaml:"Count"`
75+
PublicKeyAlgorithm string `yaml:"PublicKeyAlgorithm"`
76+
Specs []UserSpec `yaml:"Specs"`
7177
}
7278

7379
type OrgSpec struct {
@@ -209,6 +215,8 @@ PeerOrgs:
209215
Count: 1
210216
Users:
211217
Count: 1
218+
Specs:
219+
- Name: testuser
212220
`
213221

214222
// command line flags
@@ -561,16 +569,20 @@ func generatePeerOrg(baseDir string, orgSpec OrgSpec) {
561569
generateNodes(peersDir, orgSpec.Specs, signCA, tlsCA, msp.PEER, orgSpec.EnableNodeOUs)
562570

563571
publicKeyAlg := getPublicKeyAlg(orgSpec.Users.PublicKeyAlgorithm)
564-
// TODO: add ability to specify usernames
565-
users := []NodeSpec{}
566-
for j := 1; j <= orgSpec.Users.Count; j++ {
567-
user := NodeSpec{
568-
CommonName: fmt.Sprintf("%s%d@%s", userBaseName, j, orgName),
572+
users := make([]NodeSpec, 0, len(orgSpec.Users.Specs)+orgSpec.Users.Count)
573+
for _, s := range orgSpec.Users.Specs {
574+
users = append(users, NodeSpec{
575+
CommonName: fmt.Sprintf("%s@%s", s.Name, orgName),
569576
PublicKeyAlgorithm: publicKeyAlg,
570-
}
571-
572-
users = append(users, user)
577+
})
573578
}
579+
for j := range orgSpec.Users.Count {
580+
users = append(users, NodeSpec{
581+
CommonName: fmt.Sprintf("%s%d@%s", userBaseName, j+1, orgName),
582+
PublicKeyAlgorithm: publicKeyAlg,
583+
})
584+
}
585+
574586
// add an admin user
575587
adminUser := NodeSpec{
576588
isAdmin: true,

0 commit comments

Comments
 (0)