Add bridge backend for sync

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-02-01 21:22:31 +01:00
parent bc5bbdae81
commit 3d4b215b8f
19 changed files with 1038 additions and 145 deletions

View File

@@ -507,6 +507,60 @@ ORDER BY
return nil
}
func (c *Connector) Update(
ctx context.Context,
conn pg.Conn,
scope Scoper,
encryptionKey cipher.EncryptionKey,
) error {
q := `
UPDATE connectors
SET
settings = @settings,
encrypted_connection = @encrypted_connection,
updated_at = @updated_at
WHERE
%s
AND id = @id
`
q = fmt.Sprintf(q, scope.SQLFragment())
if c.Connection == nil {
return fmt.Errorf("connection is nil")
}
c.extractSlackSettings()
connection, err := json.Marshal(c.Connection)
if err != nil {
return fmt.Errorf("cannot marshal connection: %w", err)
}
encryptedConnection, err := cipher.Encrypt(connection, encryptionKey)
if err != nil {
return fmt.Errorf("cannot encrypt connection: %w", err)
}
args := pgx.StrictNamedArgs{
"id": c.ID,
"settings": c.Settings,
"encrypted_connection": encryptedConnection,
"updated_at": c.UpdatedAt,
}
maps.Copy(args, scope.SQLArguments())
_, err = conn.Exec(ctx, q, args)
if err != nil {
return fmt.Errorf("cannot update connector: %w", err)
}
c.EncryptedConnection = encryptedConnection
c.populateSlackSettings()
return nil
}
func (c *Connectors) decryptConnections(encryptionKey cipher.EncryptionKey) error {
for _, cnnctr := range *c {
if len(cnnctr.EncryptedConnection) == 0 {