MCPcopy Create free account
hub / github.com/docker/cli / SaveToWriter

Method SaveToWriter

cli/config/configfile/file.go:164–194  ·  view source on GitHub ↗

SaveToWriter encodes and writes out all the authorization information to the given writer

(writer io.Writer)

Source from the content-addressed store, hash-verified

162// SaveToWriter encodes and writes out all the authorization information to
163// the given writer
164func (c *ConfigFile) SaveToWriter(writer io.Writer) error {
165 // Encode sensitive data into a new/temp struct
166 tmpAuthConfigs := make(map[string]types.AuthConfig, len(c.AuthConfigs))
167 for k, authConfig := range c.AuthConfigs {
168 authCopy := authConfig
169 // encode and save the authstring, while blanking out the original fields
170 authCopy.Auth = encodeAuth(&authCopy)
171 authCopy.Username = ""
172 authCopy.Password = ""
173 authCopy.ServerAddress = ""
174 tmpAuthConfigs[k] = authCopy
175 }
176
177 saveAuthConfigs := c.AuthConfigs
178 c.AuthConfigs = tmpAuthConfigs
179 defer func() { c.AuthConfigs = saveAuthConfigs }()
180
181 // User-Agent header is automatically set, and should not be stored in the configuration
182 for v := range c.HTTPHeaders {
183 if strings.EqualFold(v, "User-Agent") {
184 delete(c.HTTPHeaders, v)
185 }
186 }
187
188 data, err := json.MarshalIndent(c, "", "\t")
189 if err != nil {
190 return err
191 }
192 _, err = writer.Write(data)
193 return err
194}
195
196// Save encodes and writes out all the authorization information
197func (c *ConfigFile) Save() (retErr error) {

Callers 3

SaveMethod · 0.95
TestJSONSaveWithNoFileFunction · 0.80

Calls 2

encodeAuthFunction · 0.85
WriteMethod · 0.45

Tested by 1

TestJSONSaveWithNoFileFunction · 0.64