-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Create/Get Profile Endpoint and store the profile data
closes #2 Signed-off-by: talwinder.kaur <talwinder.kaur@securekey.com>
- Loading branch information
1 parent
4ec9046
commit 6e04d74
Showing
14 changed files
with
746 additions
and
47 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
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
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,137 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package storage | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"sync" | ||
|
||
"github.com/trustbloc/edv/pkg/storage" | ||
) | ||
|
||
// MockStoreProvider mock store provider. | ||
type MockStoreProvider struct { | ||
Store *MockStore | ||
ErrOpenStoreHandle error | ||
FailNameSpace string | ||
} | ||
|
||
// NewMockStoreProvider new store provider instance. | ||
func NewMockStoreProvider() *MockStoreProvider { | ||
return &MockStoreProvider{Store: &MockStore{ | ||
Store: make(map[string][]byte), | ||
}} | ||
} | ||
|
||
// OpenStore opens and returns a store for given name space. | ||
func (s *MockStoreProvider) OpenStore(name string) (storage.Store, error) { | ||
if name == s.FailNameSpace { | ||
return nil, fmt.Errorf("failed to open store for name space %s", name) | ||
} | ||
|
||
return s.Store, s.ErrOpenStoreHandle | ||
} | ||
|
||
// Close closes all stores created under this store provider | ||
func (s *MockStoreProvider) Close() error { | ||
return nil | ||
} | ||
|
||
// CloseStore closes store for given name space | ||
func (s *MockStoreProvider) CloseStore(name string) error { | ||
return nil | ||
} | ||
|
||
// MockStore mock store. | ||
type MockStore struct { | ||
Store map[string][]byte | ||
lock sync.RWMutex | ||
ErrPut error | ||
ErrGet error | ||
ErrItr error | ||
} | ||
|
||
// Put stores the key and the record | ||
func (s *MockStore) Put(k string, v []byte) error { | ||
if k == "" { | ||
return errors.New("key is mandatory") | ||
} | ||
|
||
s.lock.Lock() | ||
s.Store[k] = v | ||
s.lock.Unlock() | ||
|
||
return s.ErrPut | ||
} | ||
|
||
// Get fetches the record based on key | ||
func (s *MockStore) Get(k string) ([]byte, error) { | ||
s.lock.RLock() | ||
defer s.lock.RUnlock() | ||
|
||
val, ok := s.Store[k] | ||
if !ok { | ||
return nil, storage.ErrValueNotFound | ||
} | ||
|
||
return val, s.ErrGet | ||
} | ||
|
||
// MockIterator is the mock implementation of storage iterator | ||
type MockIterator struct { | ||
currentIndex int | ||
currentItem []string | ||
items [][]string | ||
err error | ||
} | ||
|
||
func (s *MockIterator) isExhausted() bool { | ||
return len(s.items) == 0 || len(s.items) == s.currentIndex | ||
} | ||
|
||
// Next moves pointer to next value of iterator. | ||
// It returns false if the iterator is exhausted. | ||
func (s *MockIterator) Next() bool { | ||
if s.isExhausted() { | ||
return false | ||
} | ||
|
||
s.currentItem = s.items[s.currentIndex] | ||
s.currentIndex++ | ||
|
||
return true | ||
} | ||
|
||
// Release releases associated resources. | ||
func (s *MockIterator) Release() { | ||
s.currentIndex = 0 | ||
s.items = make([][]string, 0) | ||
s.currentItem = make([]string, 0) | ||
} | ||
|
||
// Error returns error in iterator. | ||
func (s *MockIterator) Error() error { | ||
return s.err | ||
} | ||
|
||
// Key returns the key of the current key/value pair. | ||
func (s *MockIterator) Key() []byte { | ||
if len(s.items) == 0 || len(s.currentItem) == 0 { | ||
return nil | ||
} | ||
|
||
return []byte(s.currentItem[0]) | ||
} | ||
|
||
// Value returns the value of the current key/value pair. | ||
func (s *MockIterator) Value() []byte { | ||
if len(s.items) == 0 || len(s.currentItem) < 1 { | ||
return nil | ||
} | ||
|
||
return []byte(s.currentItem[1]) | ||
} |
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,40 @@ | ||
/* | ||
Copyright SecureKey Technologies Inc. All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package vc | ||
|
||
import ( | ||
"github.com/trustbloc/edv/pkg/storage" | ||
|
||
mockstore "github.com/trustbloc/edge-service/pkg/internal/mock/storage" | ||
) | ||
|
||
// MockVC mock vc service | ||
type MockVC struct { | ||
ProtocolName string | ||
} | ||
|
||
// Name return service name | ||
func (m *MockVC) Name() string { | ||
if m.ProtocolName != "" { | ||
return m.ProtocolName | ||
} | ||
|
||
return "credential" | ||
} | ||
|
||
// MockProvider is provider for vc service | ||
type MockProvider struct { | ||
StoreProvider *mockstore.MockStoreProvider | ||
} | ||
|
||
// StorageProvider is mock storage provider for vc service | ||
func (p *MockProvider) StorageProvider() storage.Provider { | ||
if p.StoreProvider != nil { | ||
return p.StoreProvider | ||
} | ||
|
||
return mockstore.NewMockStoreProvider() | ||
} |
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.