Skip to content

Commit

Permalink
debug: Log metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Dec 18, 2024
1 parent 194e200 commit fc25599
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/pkg/service/stream/encryption/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ func NewLoggedEncryptor(ctx context.Context, encryptor cloudencrypt.Encryptor, l
}

func (encryptor *LoggedEncryptor) Encrypt(ctx context.Context, plaintext []byte, metadata cloudencrypt.Metadata) ([]byte, error) {
meta := ""
for k, v := range metadata {
meta += k + ": " + v + ", "
}

encryptor.logger.Infof(ctx, "encryption metadata: "+meta)

if len(plaintext) == 0 {
err := errors.New("text should not be empty")
encryptor.logger.Infof(ctx, "encryption error: %s", err.Error())
Expand All @@ -41,6 +48,13 @@ func (encryptor *LoggedEncryptor) Encrypt(ctx context.Context, plaintext []byte,
}

func (encryptor *LoggedEncryptor) Decrypt(ctx context.Context, ciphertext []byte, metadata cloudencrypt.Metadata) ([]byte, error) {
meta := ""
for k, v := range metadata {
meta += k + ": " + v + ", "
}

encryptor.logger.Infof(ctx, "decryption metadata: "+meta)

if len(ciphertext) == 0 {
err := errors.New("text should not be empty")
encryptor.logger.Infof(ctx, "decryption error: %s", err.Error())
Expand Down

0 comments on commit fc25599

Please sign in to comment.