lib/uplink: better diagnostics with invalid encryption access

Fixes #3841

Change-Id: I965b8fbb8fd221c740c2fc1421d66721c046f038
This commit is contained in:
Jeff Wendling 2020-04-30 16:42:29 -06:00 committed by Ivan Fraixedes
parent 324fd410a0
commit 13baacc479
2 changed files with 15 additions and 0 deletions

View File

@ -42,6 +42,17 @@ func NewEncryptionAccessWithDefaultKey(defaultKey storj.Key) *EncryptionAccess {
return ec
}
// validate returns an error if the EncryptionAccess is not valid to be used.
func (s *EncryptionAccess) validate() error {
if s == nil {
return errs.New("invalid nil encryption access")
}
if s.store == nil {
return errs.New("invalid encryption access: no store")
}
return nil
}
// Store returns the underlying encryption store for the access context.
func (s *EncryptionAccess) Store() *encryption.Store {
return s.store

View File

@ -158,6 +158,10 @@ func (p *Project) GetBucketInfo(ctx context.Context, bucket string) (b storj.Buc
func (p *Project) OpenBucket(ctx context.Context, bucketName string, access *EncryptionAccess) (b *Bucket, err error) {
defer mon.Task()(&ctx)(&err)
if err := access.validate(); err != nil {
return nil, err
}
bucketInfo, cfg, err := p.GetBucketInfo(ctx, bucketName)
if err != nil {
return nil, err