SaveToWriter encodes and writes out all the authorization information to the given writer
(writer io.Writer)
| 162 | // SaveToWriter encodes and writes out all the authorization information to |
| 163 | // the given writer |
| 164 | func (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 |
| 197 | func (c *ConfigFile) Save() (retErr error) { |