ResolveAuthDir normalizes the auth directory path for consistent reuse throughout the app. It expands a leading tilde (~) to the user's home directory and returns a cleaned path. If authDir is empty, it defaults to ~/.cli-proxy-api.
(authDir string)
| 75 | // It expands a leading tilde (~) to the user's home directory and returns a cleaned path. |
| 76 | // If authDir is empty, it defaults to ~/.cli-proxy-api. |
| 77 | func ResolveAuthDir(authDir string) (string, error) { |
| 78 | if authDir == "" { |
| 79 | authDir = config.DefaultAuthDir |
| 80 | } |
| 81 | if strings.HasPrefix(authDir, "~") { |
| 82 | home, err := os.UserHomeDir() |
| 83 | if err != nil { |
| 84 | return "", fmt.Errorf("resolve auth dir: %w", err) |
| 85 | } |
| 86 | remainder := strings.TrimPrefix(authDir, "~") |
| 87 | remainder = strings.TrimLeft(remainder, "/\\") |
| 88 | if remainder == "" { |
| 89 | return filepath.Clean(home), nil |
| 90 | } |
| 91 | normalized := strings.ReplaceAll(remainder, "\\", "/") |
| 92 | return filepath.Clean(filepath.Join(home, filepath.FromSlash(normalized))), nil |
| 93 | } |
| 94 | return filepath.Clean(authDir), nil |
| 95 | } |
| 96 | |
| 97 | // CountAuthFiles returns the number of auth records available through the provided Store. |
| 98 | // For filesystem-backed stores, this reflects the number of JSON auth files under the configured directory. |
no outgoing calls
no test coverage detected