| 461 | } |
| 462 | |
| 463 | func (s *GitTokenStore) readAuthFile(path, baseDir string) (*cliproxyauth.Auth, error) { |
| 464 | data, err := os.ReadFile(path) |
| 465 | if err != nil { |
| 466 | return nil, fmt.Errorf("read file: %w", err) |
| 467 | } |
| 468 | if len(data) == 0 { |
| 469 | return nil, nil |
| 470 | } |
| 471 | metadata := make(map[string]any) |
| 472 | if err = json.Unmarshal(data, &metadata); err != nil { |
| 473 | return nil, fmt.Errorf("unmarshal auth json: %w", err) |
| 474 | } |
| 475 | provider, _ := metadata["type"].(string) |
| 476 | if provider == "" { |
| 477 | provider = "unknown" |
| 478 | } |
| 479 | info, err := os.Stat(path) |
| 480 | if err != nil { |
| 481 | return nil, fmt.Errorf("stat file: %w", err) |
| 482 | } |
| 483 | id := s.idFor(path, baseDir) |
| 484 | auth := &cliproxyauth.Auth{ |
| 485 | ID: id, |
| 486 | Provider: provider, |
| 487 | FileName: id, |
| 488 | Label: s.labelFor(metadata), |
| 489 | Status: cliproxyauth.StatusActive, |
| 490 | Attributes: map[string]string{ |
| 491 | cliproxyauth.AttributePath: path, |
| 492 | cliproxyauth.AttributeSourceBackend: cliproxyauth.AuthSourceGit, |
| 493 | }, |
| 494 | Metadata: metadata, |
| 495 | CreatedAt: info.ModTime(), |
| 496 | UpdatedAt: info.ModTime(), |
| 497 | LastRefreshedAt: time.Time{}, |
| 498 | NextRefreshAfter: time.Time{}, |
| 499 | } |
| 500 | if email, ok := metadata["email"].(string); ok && email != "" { |
| 501 | auth.Attributes["email"] = email |
| 502 | } |
| 503 | cliproxyauth.ApplyCustomHeadersFromMetadata(auth) |
| 504 | if disabled, ok := metadata["disabled"].(bool); ok && disabled { |
| 505 | auth.Disabled = true |
| 506 | auth.Status = cliproxyauth.StatusDisabled |
| 507 | } |
| 508 | return auth, nil |
| 509 | } |
| 510 | |
| 511 | func (s *GitTokenStore) idFor(path, baseDir string) string { |
| 512 | if baseDir == "" { |