List enumerates all auth JSON files under the configured directory.
(ctx context.Context)
| 164 | |
| 165 | // List enumerates all auth JSON files under the configured directory. |
| 166 | func (s *FileTokenStore) List(ctx context.Context) ([]*cliproxyauth.Auth, error) { |
| 167 | dir := s.baseDirSnapshot() |
| 168 | if dir == "" { |
| 169 | return nil, fmt.Errorf("auth filestore: directory not configured") |
| 170 | } |
| 171 | entries := make([]*cliproxyauth.Auth, 0) |
| 172 | err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, walkErr error) error { |
| 173 | if walkErr != nil { |
| 174 | return walkErr |
| 175 | } |
| 176 | if d.IsDir() { |
| 177 | return nil |
| 178 | } |
| 179 | if !strings.HasSuffix(strings.ToLower(d.Name()), ".json") { |
| 180 | return nil |
| 181 | } |
| 182 | auths, errReadAuths := s.readAuthFiles(path, dir) |
| 183 | if errReadAuths != nil { |
| 184 | return nil |
| 185 | } |
| 186 | if len(auths) > 0 { |
| 187 | entries = append(entries, auths...) |
| 188 | } |
| 189 | return nil |
| 190 | }) |
| 191 | if err != nil { |
| 192 | return nil, err |
| 193 | } |
| 194 | return entries, nil |
| 195 | } |
| 196 | |
| 197 | // Delete removes the auth file. |
| 198 | func (s *FileTokenStore) Delete(ctx context.Context, id string) error { |