MCPcopy Create free account
hub / github.com/PostHog/duckgres / LoadStatements

Method LoadStatements

controlplane/user_secrets.go:82–101  ·  view source on GitHub ↗

LoadStatements returns the user's decrypted secret statements for replay at session creation. Rows that fail to decrypt (e.g. written under a rotated key) are skipped with a loud log instead of failing the whole session.

(_ context.Context, orgID, username string)

Source from the content-addressed store, hash-verified

80// session creation. Rows that fail to decrypt (e.g. written under a rotated
81// key) are skipped with a loud log instead of failing the whole session.
82func (m *CPUserSecretManager) LoadStatements(_ context.Context, orgID, username string) ([]string, error) {
83 if m.cipher == nil {
84 return nil, nil
85 }
86 rows, err := m.store.ListOrgUserSecrets(orgID, username)
87 if err != nil {
88 return nil, fmt.Errorf("list user secrets: %w", err)
89 }
90 statements := make([]string, 0, len(rows))
91 for _, row := range rows {
92 stmt, err := m.cipher.Open(row.OrgID, row.Username, row.SecretName, row.Ciphertext)
93 if err != nil {
94 slog.Error("User persistent secret cannot be decrypted; skipping replay (was the encryption key rotated?).",
95 "org", row.OrgID, "user", row.Username, "secret", row.SecretName, "error", err)
96 continue
97 }
98 statements = append(statements, stmt)
99 }
100 return statements, nil
101}
102
103// SessionSecretLoader binds an org onto LoadStatements in the shape
104// SessionManager.SetUserSecretLoader expects.

Callers 1

SessionSecretLoaderMethod · 0.95

Calls 3

ListOrgUserSecretsMethod · 0.65
OpenMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected