Files
fgueryandGitHub 599477b709 fix(EN-549): remove config and connector dependencies (#622)
* chore: rename RunNextTasks workflow

* feat: added a trimmed down type for connector only containing the id

* feat: make runNextTask use connectorIdOnly

* feat: added isScheduledForDeletion to plugin interface

* feat: add scheduledForDeletion at plugin level

* feat: refactor manager.Load to take a connector instead of parts of it

* feat: saves the connector's scheduledFOrDeletion into the plugin

* feat: use plugin.IsScheduledForDeletion instead of loading connector

* fix: make e2e tests less flaky

* fix: remove config from most request types

* feat: (WIP) remove config from runNextTask

* fix: remove unneeded method definitions in each plugin

* fix: simplify RunNextFlow as anyway we need to change the parameters

* fix: add a workflow compatible with previous version for runNextTasks

* fix(EN-577): added back RunSendEvents as a deprecated workflow

* fix(EN-577): added back RunUpdatePaymentInitiationFromPayment as a deprecated workflow

* fix: fix linting directives

* fix: replace old usage with refactored one

* fix: added back missing deprecated activities

* fix: ensure fetch_next_balance works with v3.0 code

* fix: simplify a bit the versionning etc

* fix: quick refactor before applying solution elsewhere

* fix: add back RunSendEvents and RunNextTask child workflows where necessary for backward compatibility

* fix: add back missing activity, seems like it's mandatory?

* fix: run payment initiation update as child workflow when necessary

* fix: missing activy call in test, refine some todos

* fix: lint

* fix: ensure we always reload plugins into the manager -- so exposing isScheduledForDeletion

* fix: ensure we stop storing clear config in temporal

* fix: make store config support plain text config

* fix: some comments

* fix: change runSendEvent workflow to be match what we had in 3.0

* feat: enable worker versionning to avoid workflow from new version to get executed on old code

* fix: lint

* fix: revert worker versionning

* fix: minor code review comments

* fix: add context to Encrypt & Decrypt methods

* fix: improve lint, add couple tests

* fix: use atomic to handle isScheduledForDeletion

* fix: make create_events work on migration

* fix: avoid returning channel; just send what is needed in runSendEventAsChildWorkflow and runNextTaskAsChildWorkflow

* fix: remove extra call to installWorkflow on start plugin

* fix: typo in error log line

* fix: simplify errChan initialization

* fix: clarify feature flag names
2026-01-05 11:09:45 +00:00

50 lines
2.0 KiB
Go

package storage
import (
"context"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
)
// EncryptRaw encrypts a JSON payload using Postgres pgcrypto and the storage encryption key.
// It mirrors the encryption performed in other storage methods (e.g., connectors install).
func (s *store) EncryptRaw(ctx context.Context, message json.RawMessage) (json.RawMessage, error) {
// Use a simple SELECT to leverage pgp_sym_encrypt with consistent options
// We encrypt the JSON as TEXT to match existing patterns
var cipher []byte
// bun.NewRaw with positional args; we cast to text in the SQL expression
if err := s.db.NewRaw("SELECT pgp_sym_encrypt(?::TEXT, ?::TEXT, ?::TEXT)", string(message), s.configEncryptionKey, encryptionOptions).Scan(ctx, &cipher); err != nil {
return nil, err
}
// Base64-encode the binary ciphertext so it can be safely marshaled as JSON
b64 := base64.StdEncoding.EncodeToString(cipher)
return []byte(fmt.Sprintf("%q", b64)), nil
}
// ErrNotEncrypted indicates that the provided payload is not an encrypted blob
// produced by EncryptRaw, but rather plain JSON. Callers may treat this as a
// no-op and pass the original payload through unchanged.
var ErrNotEncrypted = errors.New("storage: not encrypted")
// DecryptRaw decrypts a JSON payload previously encrypted with EncryptRaw.
func (s *store) DecryptRaw(ctx context.Context, message json.RawMessage) (json.RawMessage, error) {
// Expect a JSON string containing base64-encoded ciphertext.
// If it's not a JSON string (e.g., it's an object/array), treat as plain text.
var b64 string
if err := json.Unmarshal(message, &b64); err != nil {
return nil, ErrNotEncrypted
}
cipher, err := base64.StdEncoding.DecodeString(b64)
if err != nil {
return nil, ErrNotEncrypted
}
var plain string
if err := s.db.NewRaw("SELECT pgp_sym_decrypt(?::BYTEA, ?::TEXT, ?::TEXT)", cipher, s.configEncryptionKey, encryptionOptions).Scan(ctx, &plain); err != nil {
return nil, err
}
return json.RawMessage(plain), nil
}