feat(tfstated): implement HTTP basic auth

This commit is contained in:
Julien Dessaux 2024-11-14 01:34:29 +01:00
parent 4020344eda
commit 3d8812fbd0
Signed by: adyxax
GPG key ID: F92E51B86E07177E
18 changed files with 245 additions and 58 deletions

View file

@ -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 {