Skip to content

Commit

Permalink
Return error for multiple config options set
Browse files Browse the repository at this point in the history
An error is now returned when a more than one storage configuration has
been set. Previously, this would not return an error and simply use what
-ever the user had set that was first in the storage switch options.

Closes #853
  • Loading branch information
Diogenesoftoronto committed Feb 2, 2024
1 parent 627126d commit e2c2a6b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions internal/storage/types/location_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"fmt"
"net/url"
"reflect"

"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
Expand Down Expand Up @@ -53,14 +54,21 @@ func (c *LocationConfig) UnmarshalJSON(blob []byte) error {
return err
}

errMultipleConfig := errors.New("multiple config values have been assigned")
switch {
// TODO: return error if we have more than one config assigned (mutually exclusive)
case types.S3 != nil:
c.Value = types.S3
case types.SFTPConfig != nil:
if reflect.ValueOf(c.Value).IsValid() {
return errMultipleConfig
}
c.Value = types.SFTPConfig
case types.URLConfig != nil:
if reflect.ValueOf(c.Value).IsValid() {
return errMultipleConfig
}
c.Value = types.URLConfig

default:
return errors.New("undefined configuration document")
}
Expand Down Expand Up @@ -143,6 +151,5 @@ func (c URLConfig) OpenBucket(ctx context.Context) (*blob.Bucket, error) {
if err != nil {
return nil, fmt.Errorf("open bucket by URL: %v", err)
}

return b, nil
}

0 comments on commit e2c2a6b

Please sign in to comment.