(path, baseDir string)
| 563 | } |
| 564 | |
| 565 | func (s *ObjectTokenStore) readAuthFile(path, baseDir string) (*cliproxyauth.Auth, error) { |
| 566 | data, err := os.ReadFile(path) |
| 567 | if err != nil { |
| 568 | return nil, fmt.Errorf("read file: %w", err) |
| 569 | } |
| 570 | if len(data) == 0 { |
| 571 | return nil, nil |
| 572 | } |
| 573 | metadata := make(map[string]any) |
| 574 | if err = json.Unmarshal(data, &metadata); err != nil { |
| 575 | return nil, fmt.Errorf("unmarshal auth json: %w", err) |
| 576 | } |
| 577 | provider := strings.TrimSpace(valueAsString(metadata["type"])) |
| 578 | if provider == "" { |
| 579 | provider = "unknown" |
| 580 | } |
| 581 | info, err := os.Stat(path) |
| 582 | if err != nil { |
| 583 | return nil, fmt.Errorf("stat auth file: %w", err) |
| 584 | } |
| 585 | rel, errRel := filepath.Rel(baseDir, path) |
| 586 | if errRel != nil { |
| 587 | rel = filepath.Base(path) |
| 588 | } |
| 589 | rel = normalizeAuthID(rel) |
| 590 | attr := map[string]string{ |
| 591 | cliproxyauth.AttributePath: path, |
| 592 | cliproxyauth.AttributeSourceBackend: cliproxyauth.AuthSourceObjectStore, |
| 593 | } |
| 594 | if email := strings.TrimSpace(valueAsString(metadata["email"])); email != "" { |
| 595 | attr["email"] = email |
| 596 | } |
| 597 | auth := &cliproxyauth.Auth{ |
| 598 | ID: rel, |
| 599 | Provider: provider, |
| 600 | FileName: rel, |
| 601 | Label: labelFor(metadata), |
| 602 | Status: cliproxyauth.StatusActive, |
| 603 | Attributes: attr, |
| 604 | Metadata: metadata, |
| 605 | CreatedAt: info.ModTime(), |
| 606 | UpdatedAt: info.ModTime(), |
| 607 | LastRefreshedAt: time.Time{}, |
| 608 | NextRefreshAfter: time.Time{}, |
| 609 | } |
| 610 | cliproxyauth.ApplyCustomHeadersFromMetadata(auth) |
| 611 | if disabled, ok := metadata["disabled"].(bool); ok && disabled { |
| 612 | auth.Disabled = true |
| 613 | auth.Status = cliproxyauth.StatusDisabled |
| 614 | } |
| 615 | return auth, nil |
| 616 | } |
| 617 | |
| 618 | func normalizeLineEndingsBytes(data []byte) []byte { |
| 619 | replaced := bytes.ReplaceAll(data, []byte{'\r', '\n'}, []byte{'\n'}) |
no test coverage detected