Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Billy Zha <[email protected]>
  • Loading branch information
qweeah committed Jan 16, 2024
1 parent b178cc7 commit 704e303
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions registry/remote/credentials/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ func (cfg *Config) CredentialsStore() string {
return cfg.credentialsStore
}

// Path returns the path to the config file.
func (cfg *Config) Path() string {
return cfg.path
}

// SetCredentialsStore puts the configured credentials store.
func (cfg *Config) SetCredentialsStore(credsStore string) error {
cfg.rwLock.Lock()
Expand Down
10 changes: 10 additions & 0 deletions registry/remote/credentials/internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1450,3 +1450,13 @@ func Test_toHostname(t *testing.T) {
})
}
}

func TestConfig_Path(t *testing.T) {
mockedPath := "/path/to/config.json"
config := Config{
path: mockedPath,
}
if got := config.Path(); got != mockedPath {
t.Errorf("Config.Path() = %v, want %v", got, mockedPath)
}
}
8 changes: 3 additions & 5 deletions registry/remote/credentials/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type Store interface {
// in the config file.
type DynamicStore struct {
config *config.Config
configPath string
options StoreOptions
detectedCredsStore string
setCredsStoreOnce sync.Once
Expand Down Expand Up @@ -101,9 +100,8 @@ func NewStore(configPath string, opts StoreOptions) (*DynamicStore, error) {
return nil, err
}
ds := &DynamicStore{
config: cfg,
configPath: configPath,
options: opts,
config: cfg,
options: opts,
}
if opts.DetectDefaultNativeStore && !cfg.IsAuthConfigured() {
// no authentication configured, detect the default credentials store
Expand Down Expand Up @@ -171,7 +169,7 @@ func (ds *DynamicStore) IsAuthConfigured() bool {

// ConfigPath returns the path to the config file.
func (ds *DynamicStore) ConfigPath() string {
return ds.configPath
return ds.config.Path()
}

// getHelperSuffix returns the credential helper suffix for the given server
Expand Down
1 change: 1 addition & 0 deletions registry/remote/credentials/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ func Test_DynamicStore_getHelperSuffix(t *testing.T) {
})
}
}

func Test_DynamicStore_ConfigPath(t *testing.T) {
path := "../../testdata/credsStore_config.json"
var err error
Expand Down

0 comments on commit 704e303

Please sign in to comment.