From 3d8812fbd0091d2ef636949628c52bf9f48617a6 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 14 Nov 2024 01:34:29 +0100 Subject: feat(tfstated): implement HTTP basic auth --- pkg/database/states.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'pkg/database/states.go') diff --git a/pkg/database/states.go b/pkg/database/states.go index d1e9c7d..4f0ce58 100644 --- a/pkg/database/states.go +++ b/pkg/database/states.go @@ -43,7 +43,7 @@ func (db *DB) GetState(path string) ([]byte, error) { } // returns true in case of id mismatch -func (db *DB) SetState(path string, data []byte, lockID string) (bool, error) { +func (db *DB) SetState(path string, accountID int, data []byte, lockID string) (bool, error) { encryptedData, err := db.dataEncryptionKey.EncryptAES256(data) if err != nil { return false, err @@ -82,10 +82,11 @@ func (db *DB) SetState(path string, data []byte, lockID string) (bool, error) { return true, err } _, err = tx.ExecContext(db.ctx, - `INSERT INTO versions(state_id, data, lock) - SELECT :stateID, :data, lock + `INSERT INTO versions(account_id, state_id, data, lock) + SELECT :accountID, :stateID, :data, lock FROM states WHERE states.id = :stateID;`, + sql.Named("accountID", accountID), sql.Named("stateID", stateID), sql.Named("data", encryptedData)) if err != nil { -- cgit v1.2.3