@@ -95,12 +95,12 @@ func New(fn string) *ConfigFile {
9595
9696// LoadFromReader reads the configuration data given and sets up the auth config
9797// information with given directory and populates the receiver object
98- func (configFile * ConfigFile ) LoadFromReader (configData io.Reader ) error {
99- if err := json .NewDecoder (configData ).Decode (configFile ); err != nil && ! errors .Is (err , io .EOF ) {
98+ func (c * ConfigFile ) LoadFromReader (configData io.Reader ) error {
99+ if err := json .NewDecoder (configData ).Decode (c ); err != nil && ! errors .Is (err , io .EOF ) {
100100 return err
101101 }
102102 var err error
103- for addr , ac := range configFile .AuthConfigs {
103+ for addr , ac := range c .AuthConfigs {
104104 if ac .Auth != "" {
105105 ac .Username , ac .Password , err = decodeAuth (ac .Auth )
106106 if err != nil {
@@ -109,33 +109,33 @@ func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error {
109109 }
110110 ac .Auth = ""
111111 ac .ServerAddress = addr
112- configFile .AuthConfigs [addr ] = ac
112+ c .AuthConfigs [addr ] = ac
113113 }
114114 return nil
115115}
116116
117117// ContainsAuth returns whether there is authentication configured
118118// in this file or not.
119- func (configFile * ConfigFile ) ContainsAuth () bool {
120- return configFile .CredentialsStore != "" ||
121- len (configFile .CredentialHelpers ) > 0 ||
122- len (configFile .AuthConfigs ) > 0
119+ func (c * ConfigFile ) ContainsAuth () bool {
120+ return c .CredentialsStore != "" ||
121+ len (c .CredentialHelpers ) > 0 ||
122+ len (c .AuthConfigs ) > 0
123123}
124124
125125// GetAuthConfigs returns the mapping of repo to auth configuration
126- func (configFile * ConfigFile ) GetAuthConfigs () map [string ]types.AuthConfig {
127- if configFile .AuthConfigs == nil {
128- configFile .AuthConfigs = make (map [string ]types.AuthConfig )
126+ func (c * ConfigFile ) GetAuthConfigs () map [string ]types.AuthConfig {
127+ if c .AuthConfigs == nil {
128+ c .AuthConfigs = make (map [string ]types.AuthConfig )
129129 }
130- return configFile .AuthConfigs
130+ return c .AuthConfigs
131131}
132132
133133// SaveToWriter encodes and writes out all the authorization information to
134134// the given writer
135- func (configFile * ConfigFile ) SaveToWriter (writer io.Writer ) error {
135+ func (c * ConfigFile ) SaveToWriter (writer io.Writer ) error {
136136 // Encode sensitive data into a new/temp struct
137- tmpAuthConfigs := make (map [string ]types.AuthConfig , len (configFile .AuthConfigs ))
138- for k , authConfig := range configFile .AuthConfigs {
137+ tmpAuthConfigs := make (map [string ]types.AuthConfig , len (c .AuthConfigs ))
138+ for k , authConfig := range c .AuthConfigs {
139139 authCopy := authConfig
140140 // encode and save the authstring, while blanking out the original fields
141141 authCopy .Auth = encodeAuth (& authCopy )
@@ -145,18 +145,18 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
145145 tmpAuthConfigs [k ] = authCopy
146146 }
147147
148- saveAuthConfigs := configFile .AuthConfigs
149- configFile .AuthConfigs = tmpAuthConfigs
150- defer func () { configFile .AuthConfigs = saveAuthConfigs }()
148+ saveAuthConfigs := c .AuthConfigs
149+ c .AuthConfigs = tmpAuthConfigs
150+ defer func () { c .AuthConfigs = saveAuthConfigs }()
151151
152152 // User-Agent header is automatically set, and should not be stored in the configuration
153- for v := range configFile .HTTPHeaders {
153+ for v := range c .HTTPHeaders {
154154 if strings .EqualFold (v , "User-Agent" ) {
155- delete (configFile .HTTPHeaders , v )
155+ delete (c .HTTPHeaders , v )
156156 }
157157 }
158158
159- data , err := json .MarshalIndent (configFile , "" , "\t " )
159+ data , err := json .MarshalIndent (c , "" , "\t " )
160160 if err != nil {
161161 return err
162162 }
@@ -165,16 +165,16 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
165165}
166166
167167// Save encodes and writes out all the authorization information
168- func (configFile * ConfigFile ) Save () (retErr error ) {
169- if configFile .Filename == "" {
168+ func (c * ConfigFile ) Save () (retErr error ) {
169+ if c .Filename == "" {
170170 return errors .New ("can't save config with empty filename" )
171171 }
172172
173- dir := filepath .Dir (configFile .Filename )
173+ dir := filepath .Dir (c .Filename )
174174 if err := os .MkdirAll (dir , 0o700 ); err != nil {
175175 return err
176176 }
177- temp , err := os .CreateTemp (dir , filepath .Base (configFile .Filename ))
177+ temp , err := os .CreateTemp (dir , filepath .Base (c .Filename ))
178178 if err != nil {
179179 return err
180180 }
@@ -188,7 +188,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
188188 }
189189 }()
190190
191- err = configFile .SaveToWriter (temp )
191+ err = c .SaveToWriter (temp )
192192 if err != nil {
193193 return err
194194 }
@@ -198,7 +198,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
198198 }
199199
200200 // Handle situation where the configfile is a symlink, and allow for dangling symlinks
201- cfgFile := configFile .Filename
201+ cfgFile := c .Filename
202202 if f , err := filepath .EvalSymlinks (cfgFile ); err == nil {
203203 cfgFile = f
204204 } else if os .IsNotExist (err ) {
@@ -216,16 +216,16 @@ func (configFile *ConfigFile) Save() (retErr error) {
216216
217217// ParseProxyConfig computes proxy configuration by retrieving the config for the provided host and
218218// then checking this against any environment variables provided to the container
219- func (configFile * ConfigFile ) ParseProxyConfig (host string , runOpts map [string ]* string ) map [string ]* string {
219+ func (c * ConfigFile ) ParseProxyConfig (host string , runOpts map [string ]* string ) map [string ]* string {
220220 var cfgKey string
221221
222- if _ , ok := configFile .Proxies [host ]; ! ok {
222+ if _ , ok := c .Proxies [host ]; ! ok {
223223 cfgKey = "default"
224224 } else {
225225 cfgKey = host
226226 }
227227
228- config := configFile .Proxies [cfgKey ]
228+ config := c .Proxies [cfgKey ]
229229 permitted := map [string ]* string {
230230 "HTTP_PROXY" : & config .HTTPProxy ,
231231 "HTTPS_PROXY" : & config .HTTPSProxy ,
@@ -289,12 +289,12 @@ func decodeAuth(authStr string) (string, string, error) {
289289
290290// GetCredentialsStore returns a new credentials store from the settings in the
291291// configuration file
292- func (configFile * ConfigFile ) GetCredentialsStore (registryHostname string ) credentials.Store {
292+ func (c * ConfigFile ) GetCredentialsStore (registryHostname string ) credentials.Store {
293293 var store credentials.Store
294- if helper := configFile .CredentialHelpers [registryHostname ]; helper != "" {
295- store = newNativeStore (configFile , helper )
294+ if helper := c .CredentialHelpers [registryHostname ]; helper != "" {
295+ store = newNativeStore (c , helper )
296296 } else {
297- store = credentials .NewFileStore (configFile )
297+ store = credentials .NewFileStore (c )
298298 }
299299
300300 envConfig := os .Getenv (DockerEnvConfigKey )
@@ -357,30 +357,30 @@ var newNativeStore = func(configFile *ConfigFile, helperSuffix string) credentia
357357}
358358
359359// GetAuthConfig for a repository from the credential store
360- func (configFile * ConfigFile ) GetAuthConfig (registryHostname string ) (types.AuthConfig , error ) {
361- return configFile .GetCredentialsStore (registryHostname ).Get (registryHostname )
360+ func (c * ConfigFile ) GetAuthConfig (registryHostname string ) (types.AuthConfig , error ) {
361+ return c .GetCredentialsStore (registryHostname ).Get (registryHostname )
362362}
363363
364364// GetAllCredentials returns all of the credentials stored in all of the
365365// configured credential stores.
366- func (configFile * ConfigFile ) GetAllCredentials () (map [string ]types.AuthConfig , error ) {
366+ func (c * ConfigFile ) GetAllCredentials () (map [string ]types.AuthConfig , error ) {
367367 auths := make (map [string ]types.AuthConfig )
368368 addAll := func (from map [string ]types.AuthConfig ) {
369369 for reg , ac := range from {
370370 auths [reg ] = ac
371371 }
372372 }
373373
374- defaultStore := configFile .GetCredentialsStore ("" )
374+ defaultStore := c .GetCredentialsStore ("" )
375375 newAuths , err := defaultStore .GetAll ()
376376 if err != nil {
377377 return nil , err
378378 }
379379 addAll (newAuths )
380380
381381 // Auth configs from a registry-specific helper should override those from the default store.
382- for registryHostname := range configFile .CredentialHelpers {
383- newAuth , err := configFile .GetAuthConfig (registryHostname )
382+ for registryHostname := range c .CredentialHelpers {
383+ newAuth , err := c .GetAuthConfig (registryHostname )
384384 if err != nil {
385385 // TODO(thaJeztah): use context-logger, so that this output can be suppressed (in tests).
386386 logrus .WithError (err ).Warnf ("Failed to get credentials for registry: %s" , registryHostname )
@@ -392,16 +392,16 @@ func (configFile *ConfigFile) GetAllCredentials() (map[string]types.AuthConfig,
392392}
393393
394394// GetFilename returns the file name that this config file is based on.
395- func (configFile * ConfigFile ) GetFilename () string {
396- return configFile .Filename
395+ func (c * ConfigFile ) GetFilename () string {
396+ return c .Filename
397397}
398398
399399// PluginConfig retrieves the requested option for the given plugin.
400- func (configFile * ConfigFile ) PluginConfig (pluginname , option string ) (string , bool ) {
401- if configFile .Plugins == nil {
400+ func (c * ConfigFile ) PluginConfig (pluginname , option string ) (string , bool ) {
401+ if c .Plugins == nil {
402402 return "" , false
403403 }
404- pluginConfig , ok := configFile .Plugins [pluginname ]
404+ pluginConfig , ok := c .Plugins [pluginname ]
405405 if ! ok {
406406 return "" , false
407407 }
@@ -413,21 +413,21 @@ func (configFile *ConfigFile) PluginConfig(pluginname, option string) (string, b
413413// plugin. Passing a value of "" will remove the option. If removing
414414// the final config item for a given plugin then also cleans up the
415415// overall plugin entry.
416- func (configFile * ConfigFile ) SetPluginConfig (pluginname , option , value string ) {
417- if configFile .Plugins == nil {
418- configFile .Plugins = make (map [string ]map [string ]string )
416+ func (c * ConfigFile ) SetPluginConfig (pluginname , option , value string ) {
417+ if c .Plugins == nil {
418+ c .Plugins = make (map [string ]map [string ]string )
419419 }
420- pluginConfig , ok := configFile .Plugins [pluginname ]
420+ pluginConfig , ok := c .Plugins [pluginname ]
421421 if ! ok {
422422 pluginConfig = make (map [string ]string )
423- configFile .Plugins [pluginname ] = pluginConfig
423+ c .Plugins [pluginname ] = pluginConfig
424424 }
425425 if value != "" {
426426 pluginConfig [option ] = value
427427 } else {
428428 delete (pluginConfig , option )
429429 }
430430 if len (pluginConfig ) == 0 {
431- delete (configFile .Plugins , pluginname )
431+ delete (c .Plugins , pluginname )
432432 }
433433}
0 commit comments