From 91d7ad67a13626404b508be7517a7f558251341e Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Wed, 14 Aug 2024 15:55:58 +1000 Subject: [PATCH] refactor: rename "logs" key to "events" The events table contains more than just logs, so this is just to make things a bit clearer. --- backend/controller/dal/dal.go | 8 ++++---- backend/controller/dal/events.go | 8 ++++---- internal/encryption/encryption.go | 4 ++-- internal/encryption/encryption_test.go | 8 ++++---- internal/encryption/integration_test.go | 4 ++-- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index 9e1f7b4ac1..f0c9968e51 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -709,7 +709,7 @@ func (d *DAL) SetDeploymentReplicas(ctx context.Context, key model.DeploymentKey return dalerrs.TranslatePGError(err) } } - payload, err := d.encryptJSON(encryption.LogsSubKey, map[string]interface{}{ + payload, err := d.encryptJSON(encryption.EventsSubKey, map[string]interface{}{ "prev_min_replicas": deployment.MinReplicas, "min_replicas": minReplicas, }) @@ -782,7 +782,7 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentKey model.Depl } } - payload, err := d.encryptJSON(encryption.LogsSubKey, map[string]any{ + payload, err := d.encryptJSON(encryption.EventsSubKey, map[string]any{ "min_replicas": int32(minReplicas), "replaced": replacedDeploymentKey, }) @@ -1057,7 +1057,7 @@ func (d *DAL) InsertLogEvent(ctx context.Context, log *LogEvent) error { "error": log.Error, "stack": log.Stack, } - encryptedPayload, err := d.encryptJSON(encryption.LogsSubKey, payload) + encryptedPayload, err := d.encryptJSON(encryption.EventsSubKey, payload) if err != nil { return fmt.Errorf("failed to encrypt log payload: %w", err) } @@ -1137,7 +1137,7 @@ func (d *DAL) InsertCallEvent(ctx context.Context, call *CallEvent) error { if pr, ok := call.ParentRequestKey.Get(); ok { parentRequestKey = optional.Some(pr.String()) } - payload, err := d.encryptJSON(encryption.LogsSubKey, map[string]any{ + payload, err := d.encryptJSON(encryption.EventsSubKey, map[string]any{ "duration_ms": call.Duration.Milliseconds(), "request": call.Request, "response": call.Response, diff --git a/backend/controller/dal/events.go b/backend/controller/dal/events.go index 75babd7fe4..69a42519c0 100644 --- a/backend/controller/dal/events.go +++ b/backend/controller/dal/events.go @@ -349,7 +349,7 @@ func (d *DAL) transformRowsToEvents(deploymentKeys map[int64]model.DeploymentKey switch row.Type { case sql.EventTypeLog: var jsonPayload eventLogJSON - if err := d.decryptJSON(encryption.LogsSubKey, row.Payload, &jsonPayload); err != nil { + if err := d.decryptJSON(encryption.EventsSubKey, row.Payload, &jsonPayload); err != nil { return nil, fmt.Errorf("failed to decrypt log event: %w", err) } @@ -371,7 +371,7 @@ func (d *DAL) transformRowsToEvents(deploymentKeys map[int64]model.DeploymentKey case sql.EventTypeCall: var jsonPayload eventCallJSON - if err := d.decryptJSON(encryption.LogsSubKey, row.Payload, &jsonPayload); err != nil { + if err := d.decryptJSON(encryption.EventsSubKey, row.Payload, &jsonPayload); err != nil { return nil, fmt.Errorf("failed to decrypt call event: %w", err) } var sourceVerb optional.Option[schema.Ref] @@ -396,7 +396,7 @@ func (d *DAL) transformRowsToEvents(deploymentKeys map[int64]model.DeploymentKey case sql.EventTypeDeploymentCreated: var jsonPayload eventDeploymentCreatedJSON - if err := d.decryptJSON(encryption.LogsSubKey, row.Payload, &jsonPayload); err != nil { + if err := d.decryptJSON(encryption.EventsSubKey, row.Payload, &jsonPayload); err != nil { return nil, fmt.Errorf("failed to decrypt call event: %w", err) } out = append(out, &DeploymentCreatedEvent{ @@ -411,7 +411,7 @@ func (d *DAL) transformRowsToEvents(deploymentKeys map[int64]model.DeploymentKey case sql.EventTypeDeploymentUpdated: var jsonPayload eventDeploymentUpdatedJSON - if err := d.decryptJSON(encryption.LogsSubKey, row.Payload, &jsonPayload); err != nil { + if err := d.decryptJSON(encryption.EventsSubKey, row.Payload, &jsonPayload); err != nil { return nil, fmt.Errorf("failed to decrypt call event: %w", err) } out = append(out, &DeploymentUpdatedEvent{ diff --git a/internal/encryption/encryption.go b/internal/encryption/encryption.go index b6816e5986..c563f640ca 100644 --- a/internal/encryption/encryption.go +++ b/internal/encryption/encryption.go @@ -19,8 +19,8 @@ import ( type SubKey string const ( - LogsSubKey SubKey = "logs" - AsyncSubKey SubKey = "async" + EventsSubKey SubKey = "events" + AsyncSubKey SubKey = "async" ) type DataEncryptor interface { diff --git a/internal/encryption/encryption_test.go b/internal/encryption/encryption_test.go index f13e4358d5..724469bad6 100644 --- a/internal/encryption/encryption_test.go +++ b/internal/encryption/encryption_test.go @@ -9,10 +9,10 @@ import ( func TestNoOpEncryptor(t *testing.T) { encryptor := NoOpEncryptorNext{} - encrypted, err := encryptor.Encrypt(LogsSubKey, []byte("hunter2")) + encrypted, err := encryptor.Encrypt(EventsSubKey, []byte("hunter2")) assert.NoError(t, err) - decrypted, err := encryptor.Decrypt(LogsSubKey, encrypted) + decrypted, err := encryptor.Decrypt(EventsSubKey, encrypted) assert.NoError(t, err) assert.Equal(t, "hunter2", string(decrypted)) @@ -25,10 +25,10 @@ func TestKMSEncryptorFakeKMS(t *testing.T) { encryptor, err := NewKMSEncryptorGenerateKey(uri, nil) assert.NoError(t, err) - encrypted, err := encryptor.Encrypt(LogsSubKey, []byte("hunter2")) + encrypted, err := encryptor.Encrypt(EventsSubKey, []byte("hunter2")) assert.NoError(t, err) - decrypted, err := encryptor.Decrypt(LogsSubKey, encrypted) + decrypted, err := encryptor.Decrypt(EventsSubKey, encrypted) assert.NoError(t, err) assert.Equal(t, "hunter2", string(decrypted)) diff --git a/internal/encryption/integration_test.go b/internal/encryption/integration_test.go index 92cca64ad0..e895a31142 100644 --- a/internal/encryption/integration_test.go +++ b/internal/encryption/integration_test.go @@ -130,10 +130,10 @@ func TestKMSEncryptorLocalstack(t *testing.T) { encryptor, err := NewKMSEncryptorGenerateKey(uri, v1client) assert.NoError(t, err) - encrypted, err := encryptor.Encrypt(LogsSubKey, []byte("hunter2")) + encrypted, err := encryptor.Encrypt(EventsSubKey, []byte("hunter2")) assert.NoError(t, err) - decrypted, err := encryptor.Decrypt(LogsSubKey, encrypted) + decrypted, err := encryptor.Decrypt(EventsSubKey, encrypted) assert.NoError(t, err) assert.Equal(t, "hunter2", string(decrypted))