-
Notifications
You must be signed in to change notification settings - Fork 507
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User interface has been moved to pkg/core. Also, both User interface and implementation are cleaned up: - Setters and non-utilized methods are removed from the interface - Implementation is hidden behind IdentityManager. Only IdentityManager can create a user instance. A simple usage pattern of a User is: - Register - Enroll - Obtain a user by calling IdentityManager.GetUser(username) Change-Id: Ib50ff33df039310f9c2b314ba862e085fb427b97 Signed-off-by: Aleksandar Likic <aleksandar.likic@securekey.com>
- Loading branch information
Aleksandar Likic
committed
Mar 2, 2018
1 parent
4845e91
commit 77daffe
Showing
37 changed files
with
477 additions
and
1,116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package identitymgr | ||
|
||
import ( | ||
"github.com/hyperledger/fabric-sdk-go/pkg/fab/keyvaluestore" | ||
|
||
"github.com/hyperledger/fabric-sdk-go/pkg/context/api" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// CertFileUserStore stores each user in a separate file. | ||
// Only user's enrollment cert is stored, in pem format. | ||
// File naming is <user>@<org>-cert.pem | ||
type CertFileUserStore struct { | ||
store api.KVStore | ||
} | ||
|
||
func userIdentifierFromUser(user UserData) UserIdentifier { | ||
return UserIdentifier{ | ||
MspID: user.MspID, | ||
Name: user.Name, | ||
} | ||
} | ||
|
||
func storeKeyFromUserIdentifier(key UserIdentifier) string { | ||
return key.Name + "@" + key.MspID + "-cert.pem" | ||
} | ||
|
||
// NewCertFileUserStore1 creates a new instance of CertFileUserStore | ||
func NewCertFileUserStore1(store api.KVStore) (*CertFileUserStore, error) { | ||
return &CertFileUserStore{ | ||
store: store, | ||
}, nil | ||
} | ||
|
||
// NewCertFileUserStore creates a new instance of CertFileUserStore | ||
func NewCertFileUserStore(path string) (*CertFileUserStore, error) { | ||
if path == "" { | ||
return nil, errors.New("path is empty") | ||
} | ||
store, err := keyvaluestore.New(&keyvaluestore.FileKeyValueStoreOptions{ | ||
Path: path, | ||
}) | ||
if err != nil { | ||
return nil, errors.WithMessage(err, "user store creation failed") | ||
} | ||
return NewCertFileUserStore1(store) | ||
} | ||
|
||
// Load returns the User stored in the store for a key. | ||
func (s *CertFileUserStore) Load(key UserIdentifier) (UserData, error) { | ||
var userData UserData | ||
cert, err := s.store.Load(storeKeyFromUserIdentifier(key)) | ||
if err != nil { | ||
if err == api.ErrNotFound { | ||
return userData, api.ErrUserNotFound | ||
} | ||
return userData, err | ||
} | ||
certBytes, ok := cert.([]byte) | ||
if !ok { | ||
return userData, errors.New("user is not of proper type") | ||
} | ||
userData = UserData{ | ||
MspID: key.MspID, | ||
Name: key.Name, | ||
EnrollmentCertificate: certBytes, | ||
} | ||
return userData, nil | ||
} | ||
|
||
// Store stores a User into store | ||
func (s *CertFileUserStore) Store(user UserData) error { | ||
key := storeKeyFromUserIdentifier(UserIdentifier{MspID: user.MspID, Name: user.Name}) | ||
return s.store.Store(key, user.EnrollmentCertificate) | ||
} | ||
|
||
// Delete deletes a User from store | ||
func (s *CertFileUserStore) Delete(key UserIdentifier) error { | ||
return s.store.Delete(storeKeyFromUserIdentifier(key)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.