| 293 | } |
| 294 | |
| 295 | func existingAuth(ctx context.Context) (*auth.ConfigData, error) { |
| 296 | authConfig := auth.NewConfigData() |
| 297 | content, err := os.ReadFile(C.AuthFile) |
| 298 | if err == nil { |
| 299 | // We don't care of the error |
| 300 | json.Unmarshal(content, &authConfig) |
| 301 | } else if os.IsNotExist(err) { |
| 302 | config := make(auth.ConfigPerHostV2) |
| 303 | buffer, err := json.Marshal(&config) |
| 304 | if err != nil { |
| 305 | return nil, errors.Wrapf(ctx, err, "encode non-existing authentication file") |
| 306 | } |
| 307 | authConfig.AuthConfigPerHost = json.RawMessage(buffer) |
| 308 | } else { |
| 309 | return nil, errors.Wrapf(ctx, err, "read existing authentication file") |
| 310 | } |
| 311 | return authConfig, nil |
| 312 | } |