Skip to content

Commit

Permalink
refactor: make credentials.NewMemoryStore return an interface
Browse files Browse the repository at this point in the history
Signed-off-by: Lixia (Sylvia) Lei <[email protected]>
  • Loading branch information
Wwwsylvia committed Sep 22, 2023
1 parent 9f83e67 commit 0a6db83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions registry/remote/credentials/memory_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import (
"oras.land/oras-go/v2/registry/remote/auth"
)

// MemoryStore is a store that keeps credentials in memory.
type MemoryStore struct {
// memoryStore is a store that keeps credentials in memory.
type memoryStore struct {
store sync.Map
}

// NewMemoryStore creates a new in-memory credentials store.
func NewMemoryStore() *MemoryStore {
return &MemoryStore{}
func NewMemoryStore() Store {
return &memoryStore{}
}

// Get retrieves credentials from the store for the given server address.
func (ms *MemoryStore) Get(_ context.Context, serverAddress string) (auth.Credential, error) {
func (ms *memoryStore) Get(_ context.Context, serverAddress string) (auth.Credential, error) {
cred, found := ms.store.Load(serverAddress)
if !found {
return auth.EmptyCredential, nil
Expand All @@ -42,13 +42,13 @@ func (ms *MemoryStore) Get(_ context.Context, serverAddress string) (auth.Creden
}

// Put saves credentials into the store for the given server address.
func (ms *MemoryStore) Put(_ context.Context, serverAddress string, cred auth.Credential) error {
func (ms *memoryStore) Put(_ context.Context, serverAddress string, cred auth.Credential) error {
ms.store.Store(serverAddress, cred)
return nil
}

// Delete removes credentials from the store for the given server address.
func (ms *MemoryStore) Delete(_ context.Context, serverAddress string) error {
func (ms *memoryStore) Delete(_ context.Context, serverAddress string) error {
ms.store.Delete(serverAddress)
return nil
}
2 changes: 1 addition & 1 deletion registry/remote/credentials/memory_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func TestMemoryStore_Get_notExistRecord(t *testing.T) {

func TestMemoryStore_Get_validRecord(t *testing.T) {
ctx := context.Background()
ms := NewMemoryStore()
ms := NewMemoryStore().(*memoryStore)

serverAddress := "registry.example.com"
want := auth.Credential{
Expand Down

0 comments on commit 0a6db83

Please sign in to comment.