MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / buildAuthFromFileData

Method buildAuthFromFileData

internal/pluginhost/auth_callbacks.go:305–356  ·  view source on GitHub ↗
(path string, data []byte)

Source from the content-addressed store, hash-verified

303}
304
305func (h *Host) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) {
306 if strings.TrimSpace(path) == "" {
307 return nil, fmt.Errorf("auth path is empty")
308 }
309 if data == nil {
310 var errRead error
311 data, errRead = os.ReadFile(path)
312 if errRead != nil {
313 return nil, fmt.Errorf("failed to read auth file: %w", errRead)
314 }
315 }
316 metadata := make(map[string]any)
317 if errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {
318 return nil, fmt.Errorf("invalid auth file: %w", errUnmarshal)
319 }
320 provider, _ := metadata["type"].(string)
321 if strings.TrimSpace(provider) == "" {
322 provider = "unknown"
323 }
324 label := provider
325 if email, ok := metadata["email"].(string); ok && strings.TrimSpace(email) != "" {
326 label = strings.TrimSpace(email)
327 }
328 authID := h.authIDForPath(path)
329 if authID == "" {
330 authID = path
331 }
332 auth := &coreauth.Auth{
333 ID: authID,
334 Provider: provider,
335 FileName: filepath.Base(path),
336 Label: label,
337 Status: coreauth.StatusActive,
338 Attributes: map[string]string{
339 "path": path,
340 "source": path,
341 },
342 Metadata: metadata,
343 CreatedAt: time.Now().UTC(),
344 UpdatedAt: time.Now().UTC(),
345 }
346 if manager := h.currentAuthManager(); manager != nil {
347 if existing, ok := manager.GetByID(authID); ok {
348 auth.CreatedAt = existing.CreatedAt
349 auth.LastRefreshedAt = existing.LastRefreshedAt
350 auth.NextRetryAfter = existing.NextRetryAfter
351 auth.Runtime = existing.Runtime
352 }
353 }
354 coreauth.ApplyCustomHeadersFromMetadata(auth)
355 return auth, nil
356}
357
358func (h *Host) upsertAuthRecord(ctx context.Context, auth *coreauth.Auth) error {
359 manager := h.currentAuthManager()

Callers 1

saveAuthFileMethod · 0.95

Calls 3

authIDForPathMethod · 0.95
currentAuthManagerMethod · 0.95
GetByIDMethod · 0.80

Tested by

no test coverage detected