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

Method syncAuthFromDatabase

internal/store/postgresstore.go:454–493  ·  view source on GitHub ↗

syncAuthFromDatabase populates the local auth directory from PostgreSQL data.

(ctx context.Context)

Source from the content-addressed store, hash-verified

452
453// syncAuthFromDatabase populates the local auth directory from PostgreSQL data.
454func (s *PostgresStore) syncAuthFromDatabase(ctx context.Context) error {
455 query := fmt.Sprintf("SELECT id, content FROM %s", s.fullTableName(s.cfg.AuthTable))
456 rows, err := s.db.QueryContext(ctx, query)
457 if err != nil {
458 return fmt.Errorf("postgres store: load auth from database: %w", err)
459 }
460 defer rows.Close()
461
462 if err = os.RemoveAll(s.authDir); err != nil {
463 return fmt.Errorf("postgres store: reset auth directory: %w", err)
464 }
465 if err = os.MkdirAll(s.authDir, 0o700); err != nil {
466 return fmt.Errorf("postgres store: recreate auth directory: %w", err)
467 }
468
469 for rows.Next() {
470 var (
471 id string
472 payload string
473 )
474 if err = rows.Scan(&id, &payload); err != nil {
475 return fmt.Errorf("postgres store: scan auth row: %w", err)
476 }
477 path, errPath := s.absoluteAuthPath(id)
478 if errPath != nil {
479 log.WithError(errPath).Warnf("postgres store: skipping auth %s outside spool", id)
480 continue
481 }
482 if err = os.MkdirAll(filepath.Dir(path), 0o700); err != nil {
483 return fmt.Errorf("postgres store: create auth subdir: %w", err)
484 }
485 if err = os.WriteFile(path, []byte(payload), 0o600); err != nil {
486 return fmt.Errorf("postgres store: write auth file: %w", err)
487 }
488 }
489 if err = rows.Err(); err != nil {
490 return fmt.Errorf("postgres store: iterate auth rows: %w", err)
491 }
492 return nil
493}
494
495func (s *PostgresStore) syncAuthFile(ctx context.Context, relID, path string) error {
496 data, err := os.ReadFile(path)

Callers 1

BootstrapMethod · 0.95

Calls 4

fullTableNameMethod · 0.95
absoluteAuthPathMethod · 0.95
NextMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected