Skip to content

Commit

Permalink
refactor: Simplify metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Dec 5, 2024
1 parent c1e9d0f commit 8940f9f
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 8940f9f

Please sign in to comment.