@@ -96,12 +96,12 @@ func New(fn string) *ConfigFile {
9696
9797// LoadFromReader reads the configuration data given and sets up the auth config
9898// information with given directory and populates the receiver object
99- func (configFile * ConfigFile ) LoadFromReader (configData io.Reader ) error {
100- if err := json .NewDecoder (configData ).Decode (configFile ); err != nil && ! errors .Is (err , io .EOF ) {
99+ func (c * ConfigFile ) LoadFromReader (configData io.Reader ) error {
100+ if err := json .NewDecoder (configData ).Decode (c ); err != nil && ! errors .Is (err , io .EOF ) {
101101 return err
102102 }
103103 var err error
104- for addr , ac := range configFile .AuthConfigs {
104+ for addr , ac := range c .AuthConfigs {
105105 if ac .Auth != "" {
106106 ac .Username , ac .Password , err = decodeAuth (ac .Auth )
107107 if err != nil {
@@ -110,33 +110,33 @@ func (configFile *ConfigFile) LoadFromReader(configData io.Reader) error {
110110 }
111111 ac .Auth = ""
112112 ac .ServerAddress = addr
113- configFile .AuthConfigs [addr ] = ac
113+ c .AuthConfigs [addr ] = ac
114114 }
115115 return nil
116116}
117117
118118// ContainsAuth returns whether there is authentication configured
119119// in this file or not.
120- func (configFile * ConfigFile ) ContainsAuth () bool {
121- return configFile .CredentialsStore != "" ||
122- len (configFile .CredentialHelpers ) > 0 ||
123- len (configFile .AuthConfigs ) > 0
120+ func (c * ConfigFile ) ContainsAuth () bool {
121+ return c .CredentialsStore != "" ||
122+ len (c .CredentialHelpers ) > 0 ||
123+ len (c .AuthConfigs ) > 0
124124}
125125
126126// GetAuthConfigs returns the mapping of repo to auth configuration
127- func (configFile * ConfigFile ) GetAuthConfigs () map [string ]types.AuthConfig {
128- if configFile .AuthConfigs == nil {
129- configFile .AuthConfigs = make (map [string ]types.AuthConfig )
127+ func (c * ConfigFile ) GetAuthConfigs () map [string ]types.AuthConfig {
128+ if c .AuthConfigs == nil {
129+ c .AuthConfigs = make (map [string ]types.AuthConfig )
130130 }
131- return configFile .AuthConfigs
131+ return c .AuthConfigs
132132}
133133
134134// SaveToWriter encodes and writes out all the authorization information to
135135// the given writer
136- func (configFile * ConfigFile ) SaveToWriter (writer io.Writer ) error {
136+ func (c * ConfigFile ) SaveToWriter (writer io.Writer ) error {
137137 // Encode sensitive data into a new/temp struct
138- tmpAuthConfigs := make (map [string ]types.AuthConfig , len (configFile .AuthConfigs ))
139- for k , authConfig := range configFile .AuthConfigs {
138+ tmpAuthConfigs := make (map [string ]types.AuthConfig , len (c .AuthConfigs ))
139+ for k , authConfig := range c .AuthConfigs {
140140 authCopy := authConfig
141141 // encode and save the authstring, while blanking out the original fields
142142 authCopy .Auth = encodeAuth (& authCopy )
@@ -146,18 +146,18 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
146146 tmpAuthConfigs [k ] = authCopy
147147 }
148148
149- saveAuthConfigs := configFile .AuthConfigs
150- configFile .AuthConfigs = tmpAuthConfigs
151- defer func () { configFile .AuthConfigs = saveAuthConfigs }()
149+ saveAuthConfigs := c .AuthConfigs
150+ c .AuthConfigs = tmpAuthConfigs
151+ defer func () { c .AuthConfigs = saveAuthConfigs }()
152152
153153 // User-Agent header is automatically set, and should not be stored in the configuration
154- for v := range configFile .HTTPHeaders {
154+ for v := range c .HTTPHeaders {
155155 if strings .EqualFold (v , "User-Agent" ) {
156- delete (configFile .HTTPHeaders , v )
156+ delete (c .HTTPHeaders , v )
157157 }
158158 }
159159
160- data , err := json .MarshalIndent (configFile , "" , "\t " )
160+ data , err := json .MarshalIndent (c , "" , "\t " )
161161 if err != nil {
162162 return err
163163 }
@@ -166,16 +166,16 @@ func (configFile *ConfigFile) SaveToWriter(writer io.Writer) error {
166166}
167167
168168// Save encodes and writes out all the authorization information
169- func (configFile * ConfigFile ) Save () (retErr error ) {
170- if configFile .Filename == "" {
169+ func (c * ConfigFile ) Save () (retErr error ) {
170+ if c .Filename == "" {
171171 return errors .New ("can't save config with empty filename" )
172172 }
173173
174- dir := filepath .Dir (configFile .Filename )
174+ dir := filepath .Dir (c .Filename )
175175 if err := os .MkdirAll (dir , 0o700 ); err != nil {
176176 return err
177177 }
178- temp , err := os .CreateTemp (dir , filepath .Base (configFile .Filename ))
178+ temp , err := os .CreateTemp (dir , filepath .Base (c .Filename ))
179179 if err != nil {
180180 return err
181181 }
@@ -189,7 +189,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
189189 }
190190 }()
191191
192- err = configFile .SaveToWriter (temp )
192+ err = c .SaveToWriter (temp )
193193 if err != nil {
194194 return err
195195 }
@@ -199,7 +199,7 @@ func (configFile *ConfigFile) Save() (retErr error) {
199199 }
200200
201201 // Handle situation where the configfile is a symlink, and allow for dangling symlinks
202- cfgFile := configFile .Filename
202+ cfgFile := c .Filename
203203 if f , err := filepath .EvalSymlinks (cfgFile ); err == nil {
204204 cfgFile = f
205205 } else if os .IsNotExist (err ) {
@@ -217,16 +217,16 @@ func (configFile *ConfigFile) Save() (retErr error) {
217217
218218// ParseProxyConfig computes proxy configuration by retrieving the config for the provided host and
219219// then checking this against any environment variables provided to the container
220- func (configFile * ConfigFile ) ParseProxyConfig (host string , runOpts map [string ]* string ) map [string ]* string {
220+ func (c * ConfigFile ) ParseProxyConfig (host string , runOpts map [string ]* string ) map [string ]* string {
221221 var cfgKey string
222222
223- if _ , ok := configFile .Proxies [host ]; ! ok {
223+ if _ , ok := c .Proxies [host ]; ! ok {
224224 cfgKey = "default"
225225 } else {
226226 cfgKey = host
227227 }
228228
229- config := configFile .Proxies [cfgKey ]
229+ config := c .Proxies [cfgKey ]
230230 permitted := map [string ]* string {
231231 "HTTP_PROXY" : & config .HTTPProxy ,
232232 "HTTPS_PROXY" : & config .HTTPSProxy ,
@@ -290,12 +290,12 @@ func decodeAuth(authStr string) (string, string, error) {
290290
291291// GetCredentialsStore returns a new credentials store from the settings in the
292292// configuration file
293- func (configFile * ConfigFile ) GetCredentialsStore (registryHostname string ) credentials.Store {
293+ func (c * ConfigFile ) GetCredentialsStore (registryHostname string ) credentials.Store {
294294 var store credentials.Store
295- if helper , ok := configFile .CredentialHelpers [registryHostname ]; ok && helper != "" {
296- store = newNativeStore (configFile , helper )
295+ if helper , ok := c .CredentialHelpers [registryHostname ]; ok && helper != "" {
296+ store = newNativeStore (c , helper )
297297 } else {
298- store = credentials .NewFileStore (configFile )
298+ store = credentials .NewFileStore (c )
299299 }
300300
301301 envConfig := os .Getenv (DockerEnvConfigKey )
@@ -358,28 +358,28 @@ var newNativeStore = func(configFile *ConfigFile, helperSuffix string) credentia
358358}
359359
360360// GetAuthConfig for a repository from the credential store
361- func (configFile * ConfigFile ) GetAuthConfig (registryHostname string ) (types.AuthConfig , error ) {
362- return configFile .GetCredentialsStore (registryHostname ).Get (registryHostname )
361+ func (c * ConfigFile ) GetAuthConfig (registryHostname string ) (types.AuthConfig , error ) {
362+ return c .GetCredentialsStore (registryHostname ).Get (registryHostname )
363363}
364364
365365// GetAllCredentials returns all of the credentials stored in all of the
366366// configured credential stores.
367- func (configFile * ConfigFile ) GetAllCredentials () (map [string ]types.AuthConfig , error ) {
367+ func (c * ConfigFile ) GetAllCredentials () (map [string ]types.AuthConfig , error ) {
368368 auths := make (map [string ]types.AuthConfig )
369369 addAll := func (from map [string ]types.AuthConfig ) {
370370 maps .Copy (auths , from )
371371 }
372372
373- defaultStore := configFile .GetCredentialsStore ("" )
373+ defaultStore := c .GetCredentialsStore ("" )
374374 newAuths , err := defaultStore .GetAll ()
375375 if err != nil {
376376 return nil , err
377377 }
378378 addAll (newAuths )
379379
380380 // Auth configs from a registry-specific helper should override those from the default store.
381- for registryHostname := range configFile .CredentialHelpers {
382- newAuth , err := configFile .GetAuthConfig (registryHostname )
381+ for registryHostname := range c .CredentialHelpers {
382+ newAuth , err := c .GetAuthConfig (registryHostname )
383383 if err != nil {
384384 // TODO(thaJeztah): use context-logger, so that this output can be suppressed (in tests).
385385 logrus .WithError (err ).Warnf ("Failed to get credentials for registry: %s" , registryHostname )
@@ -391,16 +391,16 @@ func (configFile *ConfigFile) GetAllCredentials() (map[string]types.AuthConfig,
391391}
392392
393393// GetFilename returns the file name that this config file is based on.
394- func (configFile * ConfigFile ) GetFilename () string {
395- return configFile .Filename
394+ func (c * ConfigFile ) GetFilename () string {
395+ return c .Filename
396396}
397397
398398// PluginConfig retrieves the requested option for the given plugin.
399- func (configFile * ConfigFile ) PluginConfig (pluginname , option string ) (string , bool ) {
400- if configFile .Plugins == nil {
399+ func (c * ConfigFile ) PluginConfig (pluginname , option string ) (string , bool ) {
400+ if c .Plugins == nil {
401401 return "" , false
402402 }
403- pluginConfig , ok := configFile .Plugins [pluginname ]
403+ pluginConfig , ok := c .Plugins [pluginname ]
404404 if ! ok {
405405 return "" , false
406406 }
@@ -412,21 +412,21 @@ func (configFile *ConfigFile) PluginConfig(pluginname, option string) (string, b
412412// plugin. Passing a value of "" will remove the option. If removing
413413// the final config item for a given plugin then also cleans up the
414414// overall plugin entry.
415- func (configFile * ConfigFile ) SetPluginConfig (pluginname , option , value string ) {
416- if configFile .Plugins == nil {
417- configFile .Plugins = make (map [string ]map [string ]string )
415+ func (c * ConfigFile ) SetPluginConfig (pluginname , option , value string ) {
416+ if c .Plugins == nil {
417+ c .Plugins = make (map [string ]map [string ]string )
418418 }
419- pluginConfig , ok := configFile .Plugins [pluginname ]
419+ pluginConfig , ok := c .Plugins [pluginname ]
420420 if ! ok {
421421 pluginConfig = make (map [string ]string )
422- configFile .Plugins [pluginname ] = pluginConfig
422+ c .Plugins [pluginname ] = pluginConfig
423423 }
424424 if value != "" {
425425 pluginConfig [option ] = value
426426 } else {
427427 delete (pluginConfig , option )
428428 }
429429 if len (pluginConfig ) == 0 {
430- delete (configFile .Plugins , pluginname )
430+ delete (c .Plugins , pluginname )
431431 }
432432}
0 commit comments