Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make credentials.NewMemoryStore return an interface #605

Merged
merged 1 commit into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading