Add encryption support to provider account models (#815)

* Enable encryption for raw payloads in account models.

* Add backfill support for Snaptrade, Coinbase, Coinstats, and Mercury accounts.
This commit is contained in:
LPW
2026-02-04 17:40:01 -05:00
committed by GitHub
parent b08285a10f
commit ee6afb48fd
5 changed files with 34 additions and 4 deletions

View File

@@ -1,5 +1,11 @@
class CoinbaseAccount < ApplicationRecord
include CurrencyNormalizable
include CurrencyNormalizable, Encryptable
# Encrypt raw payloads if ActiveRecord encryption is configured
if encryption_ready?
encrypts :raw_payload
encrypts :raw_transactions_payload
end
belongs_to :coinbase_item

View File

@@ -1,7 +1,13 @@
# Represents a single crypto token/coin within a CoinStats wallet.
# Each wallet address may have multiple CoinstatsAccounts (one per token).
class CoinstatsAccount < ApplicationRecord
include CurrencyNormalizable
include CurrencyNormalizable, Encryptable
# Encrypt raw payloads if ActiveRecord encryption is configured
if encryption_ready?
encrypts :raw_payload
encrypts :raw_transactions_payload
end
belongs_to :coinstats_item

View File

@@ -1,5 +1,11 @@
class MercuryAccount < ApplicationRecord
include CurrencyNormalizable
include CurrencyNormalizable, Encryptable
# Encrypt raw payloads if ActiveRecord encryption is configured
if encryption_ready?
encrypts :raw_payload
encrypts :raw_transactions_payload
end
belongs_to :mercury_item

View File

@@ -1,7 +1,15 @@
class SnaptradeAccount < ApplicationRecord
include CurrencyNormalizable
include CurrencyNormalizable, Encryptable
include SnaptradeAccount::DataHelpers
# Encrypt raw payloads if ActiveRecord encryption is configured
if encryption_ready?
encrypts :raw_payload
encrypts :raw_transactions_payload
encrypts :raw_holdings_payload
encrypts :raw_activities_payload
end
belongs_to :snaptrade_item
# Association through account_providers for linking to Sure accounts

View File

@@ -56,6 +56,10 @@ namespace :security do
results[:simplefin_accounts] = backfill_model(SimplefinAccount, %i[raw_payload raw_transactions_payload raw_holdings_payload], batch_size, dry_run)
results[:lunchflow_accounts] = backfill_model(LunchflowAccount, %i[raw_payload raw_transactions_payload], batch_size, dry_run)
results[:enable_banking_accounts] = backfill_model(EnableBankingAccount, %i[raw_payload raw_transactions_payload], batch_size, dry_run)
results[:snaptrade_accounts] = backfill_model(SnaptradeAccount, %i[raw_payload raw_transactions_payload raw_holdings_payload raw_activities_payload], batch_size, dry_run)
results[:coinbase_accounts] = backfill_model(CoinbaseAccount, %i[raw_payload raw_transactions_payload], batch_size, dry_run)
results[:coinstats_accounts] = backfill_model(CoinstatsAccount, %i[raw_payload raw_transactions_payload], batch_size, dry_run)
results[:mercury_accounts] = backfill_model(MercuryAccount, %i[raw_payload raw_transactions_payload], batch_size, dry_run)
puts({
ok: true,