From 8940f9fce960d0613400177468a71261f07f4b6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1chym=20Tou=C5=A1ek?= Date: Thu, 5 Dec 2024 10:06:28 +0100 Subject: [PATCH] refactor: Simplify metadata --- .../stream/sink/type/tablesink/keboola/bridge/file.go | 3 +-- .../stream/sink/type/tablesink/keboola/bridge/job.go | 3 +-- .../stream/sink/type/tablesink/keboola/bridge/slice.go | 3 +-- .../stream/sink/type/tablesink/keboola/bridge/token.go | 6 ++---- .../stream/sink/type/tablesink/keboola/bridge/token_test.go | 6 ++---- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/file.go b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/file.go index 0bfe9e4efb..279a3ddbc2 100644 --- a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/file.go +++ b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/file.go @@ -154,8 +154,7 @@ func (b *Bridge) importFile(ctx context.Context, file plugin.File, stats statist ) // Prepare encryption metadata - metadata := cloudencrypt.Metadata{} - metadata["sink"] = file.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": file.SinkKey.String()} // Decrypt token var token keboola.Token diff --git a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/job.go b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/job.go index f62ef59ac8..ca685270fb 100644 --- a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/job.go +++ b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/job.go @@ -81,8 +81,7 @@ func (b *Bridge) CleanJob(ctx context.Context, job model.Job) (err error, delete } // Prepare encryption metadata - metadata := cloudencrypt.Metadata{} - metadata["sink"] = job.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": job.SinkKey.String()} // Decrypt token var token keboola.Token diff --git a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/slice.go b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/slice.go index 44b4d7d0b3..abb3e106ad 100644 --- a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/slice.go +++ b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/slice.go @@ -37,8 +37,7 @@ func (b *Bridge) uploadSlice(ctx context.Context, volume *diskreader.Volume, sli } // Prepare encryption metadata - metadata := cloudencrypt.Metadata{} - metadata["sink"] = slice.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": slice.SinkKey.String()} // Decrypt token var token keboola.Token diff --git a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token.go b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token.go index 82b0a076f5..510602c1d6 100644 --- a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token.go +++ b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token.go @@ -78,8 +78,7 @@ func (b *Bridge) tokenForSink(ctx context.Context, now time.Time, sink definitio } // Prepare encryption metadata - metadata := cloudencrypt.Metadata{} - metadata["sink"] = sink.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": sink.SinkKey.String()} // Use token from the database, if the operation is not called from the API, // so no modification of the sink target bucket is expected and the token should work. @@ -230,8 +229,7 @@ func (b *Bridge) encryptRawTokens(ctx context.Context, tokens []keboolasink.Toke } func (b *Bridge) encryptToken(ctx context.Context, token keboolasink.Token) *op.TxnOp[keboolasink.Token] { - metadata := cloudencrypt.Metadata{} - metadata["sink"] = token.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": token.SinkKey.String()} ciphertext, err := b.encryptor.Encrypt(ctx, *token.Token, metadata) if err != nil { return op.ErrorTxn[keboolasink.Token](err) diff --git a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token_test.go b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token_test.go index 2f49edc910..5d552771c2 100644 --- a/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token_test.go +++ b/internal/pkg/service/stream/sink/type/tablesink/keboola/bridge/token_test.go @@ -212,8 +212,7 @@ func TestBridge_MigrateTokens(t *testing.T) { assert.Equal(t, "1", token1.TokenID) assert.NotNil(t, token1.EncryptedToken) - metadata := cloudencrypt.Metadata{} - metadata["sink"] = token1.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": token1.SinkKey.String()} keboolaToken, err := encryptor.Decrypt(ctx, token1.EncryptedToken, metadata) require.NoError(t, err) assert.Equal(t, "token1", keboolaToken.Token) @@ -226,8 +225,7 @@ func TestBridge_MigrateTokens(t *testing.T) { assert.Equal(t, "2", token2.TokenID) assert.NotNil(t, token2.EncryptedToken) - metadata := cloudencrypt.Metadata{} - metadata["sink"] = token2.SinkKey.String() + metadata := cloudencrypt.Metadata{"sink": token2.SinkKey.String()} keboolaToken, err := encryptor.Decrypt(ctx, token2.EncryptedToken, metadata) require.NoError(t, err) assert.Equal(t, "token2", keboolaToken.Token)