diff --git a/registry/remote/credentials/internal/config/config.go b/registry/remote/credentials/internal/config/config.go index 5bb66a0e..20ee0743 100644 --- a/registry/remote/credentials/internal/config/config.go +++ b/registry/remote/credentials/internal/config/config.go @@ -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() diff --git a/registry/remote/credentials/internal/config/config_test.go b/registry/remote/credentials/internal/config/config_test.go index 6622108b..a18eccac 100644 --- a/registry/remote/credentials/internal/config/config_test.go +++ b/registry/remote/credentials/internal/config/config_test.go @@ -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) + } +} diff --git a/registry/remote/credentials/store.go b/registry/remote/credentials/store.go index 467ace66..ae8ce5be 100644 --- a/registry/remote/credentials/store.go +++ b/registry/remote/credentials/store.go @@ -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 @@ -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 @@ -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 diff --git a/registry/remote/credentials/store_test.go b/registry/remote/credentials/store_test.go index 159b9b14..919f8757 100644 --- a/registry/remote/credentials/store_test.go +++ b/registry/remote/credentials/store_test.go @@ -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