Skip to content

Commit

Permalink
refactor: rename "logs" key to "events"
Browse files Browse the repository at this point in the history
The events table contains more than just logs, so this is just to make
things a bit clearer.
  • Loading branch information
alecthomas committed Aug 14, 2024
1 parent 2ab778b commit 91d7ad6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
8 changes: 4 additions & 4 deletions backend/controller/dal/dal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down Expand Up @@ -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,
})
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions backend/controller/dal/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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]
Expand All @@ -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{
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions internal/encryption/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
type SubKey string

const (
LogsSubKey SubKey = "logs"
AsyncSubKey SubKey = "async"
EventsSubKey SubKey = "events"
AsyncSubKey SubKey = "async"
)

type DataEncryptor interface {
Expand Down
8 changes: 4 additions & 4 deletions internal/encryption/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions internal/encryption/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down

0 comments on commit 91d7ad6

Please sign in to comment.