Skip to content

Commit

Permalink
interface change
Browse files Browse the repository at this point in the history
Signed-off-by: Jakub Warczarek <[email protected]>
  • Loading branch information
programmer04 committed Jan 9, 2025
1 parent 7c43959 commit e7582ea
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion registry/remote/credentials/file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ func TestFileStore_Get_invalidConfig(t *testing.T) {
}
}

func TestReadOnlyFileStore_Get_emptyConfig(t *testing.T) {
func TestFileStore_Get_emptyConfig(t *testing.T) {
ctx := context.Background()
fs, err := NewFileStore("testdata/empty_config.json")
if err != nil {
Expand Down
10 changes: 0 additions & 10 deletions registry/remote/credentials/readonly_file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,3 @@ func NewReadOnlyFileStore(reader io.Reader) (*ReadOnlyFileStore, error) {
func (fs *ReadOnlyFileStore) Get(_ context.Context, serverAddress string) (auth.Credential, error) {
return fs.cfg.GetCredential(serverAddress)
}

// Get always returns ErrReadOnlyStore. It's present to satisfy the Store interface.
func (fs *ReadOnlyFileStore) Put(_ context.Context, _ string, _ auth.Credential) error {
return ErrReadOnlyStore
}

// Delete always returns ErrReadOnlyStore. It's present to satisfy the Store interface.
func (fs *ReadOnlyFileStore) Delete(_ context.Context, _ string) error {
return ErrReadOnlyStore
}
2 changes: 1 addition & 1 deletion registry/remote/credentials/readonly_file_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestReadOnlyFileStore_Create_fromInvalidConfig(t *testing.T) {
}
}

func TestFileStore_Get_emptyConfig(t *testing.T) {
func TestReadOnlyFileStore_Get_emptyConfig(t *testing.T) {
ctx := context.Background()
const emptyValidJson = "{}"
rofs, err := NewReadOnlyFileStore(strings.NewReader(emptyValidJson))
Expand Down
2 changes: 1 addition & 1 deletion registry/remote/credentials/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func Logout(ctx context.Context, store Store, registryName string) error {
}

// Credential returns a Credential() function that can be used by auth.Client.
func Credential(store Store) auth.CredentialFunc {
func Credential(store ReadOnlyStore) auth.CredentialFunc {
return func(ctx context.Context, hostport string) (auth.Credential, error) {
hostport = ServerAddressFromHostname(hostport)
if hostport == "" {
Expand Down
9 changes: 7 additions & 2 deletions registry/remote/credentials/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,15 @@ const (
dockerConfigFileName = "config.json"
)

// Store is the interface that any credentials store must implement.
type Store interface {
// ReadOnlyStore is a read-only interface for credentials store.
type ReadOnlyStore interface {
// Get retrieves credentials from the store for the given server address.
Get(ctx context.Context, serverAddress string) (auth.Credential, error)
}

// Store is the interface that any credentials store must implement.
type Store interface {
ReadOnlyStore
// Put saves credentials into the store for the given server address.
Put(ctx context.Context, serverAddress string, cred auth.Credential) error
// Delete removes credentials from the store for the given server address.
Expand Down

0 comments on commit e7582ea

Please sign in to comment.