Skip to content

Commit

Permalink
fix: Add custom error
Browse files Browse the repository at this point in the history
  • Loading branch information
jachym-tousek-keboola committed Dec 17, 2024
1 parent e307174 commit 37438f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/level/local/diskreader"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/model"
"github.com/keboola/keboola-as-code/internal/pkg/service/stream/storage/statistics"
"github.com/keboola/keboola-as-code/internal/pkg/utils/errors"
)

func (b *Bridge) uploadSlice(ctx context.Context, volume *diskreader.Volume, slice plugin.Slice, stats statistics.Value) error {
Expand Down Expand Up @@ -75,6 +76,10 @@ func (b *Bridge) uploadSlice(ctx context.Context, volume *diskreader.Volume, sli
// Decrypt file upload credentials
var credentials keboola.FileUploadCredentials
if keboolaFile.EncryptedCredentials != nil {
if b.credentialsEncryptor == nil {
return errors.New("missing credentials encryptor")
}

fileMetadata := cloudencrypt.Metadata{"file": slice.FileKey.String()}
credentials, err = b.credentialsEncryptor.Decrypt(ctx, keboolaFile.EncryptedCredentials, fileMetadata)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/keboola/go-cloud-encrypt/pkg/cloudencrypt"

"github.com/keboola/keboola-as-code/internal/pkg/service/stream/definition/key"
"github.com/keboola/keboola-as-code/internal/pkg/utils/errors"
)

// Token is a Storage API Token used to create staging files and import files to the target table.
Expand All @@ -27,6 +28,10 @@ func (token Token) ID() string {

func (token Token) DecryptToken(ctx context.Context, encryptor *cloudencrypt.GenericEncryptor[keboola.Token], metadata cloudencrypt.Metadata) (keboola.Token, error) {
if token.EncryptedToken != nil {
if encryptor == nil {
return keboola.Token{}, errors.New("missing token encryptor")
}

return encryptor.Decrypt(ctx, token.EncryptedToken, metadata)
}

Expand Down

0 comments on commit 37438f7

Please sign in to comment.