Skip to content

Commit

Permalink
Allow GCP buckets in other regions (#1570)
Browse files Browse the repository at this point in the history
* Allow GCP buckets in other regions

* go mod tidy -compat=1.17

* go mod tidy
  • Loading branch information
KastenMike committed Jul 27, 2022
1 parent 2fd28db commit c3a90d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

replace (
github.com/googleapis/gnostic => github.com/googleapis/gnostic v0.4.1
github.com/graymeta/stow => github.com/kastenhq/stow v0.2.6-kasten.1.0.20220719172801-c11a0e5f2e09
github.com/graymeta/stow => github.com/kastenhq/stow v0.2.6-kasten.1.0.20220726203146-8a90401257d4
github.com/rook/operator-kit => github.com/kastenhq/operator-kit v0.0.0-20180316185208-859e831cc18d
gopkg.in/check.v1 => github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734 h1:qulsCaCv+O2y9/sQ9nd5KChnAgFOWakTHQ9ZADjs6DQ=
github.com/kastenhq/check v0.0.0-20180626002341-0264cfcea734/go.mod h1:rdqSnvOJuKCPFW/h2rVLuXOAkRnHHdp9PZcKx4HCoDM=
github.com/kastenhq/stow v0.2.6-kasten.1.0.20220719172801-c11a0e5f2e09 h1:E5PMnpRjRwhBdLiVkVKNxYmLg4RemY5IJEZVBO+jrgc=
github.com/kastenhq/stow v0.2.6-kasten.1.0.20220719172801-c11a0e5f2e09/go.mod h1:6+N3Bn9Whpb+bnRFQ2A2kAyAUiYvYM0+N5bArNd4K8s=
github.com/kastenhq/stow v0.2.6-kasten.1.0.20220726203146-8a90401257d4 h1:MuAfIUYqmW0bIxyltt4EIAgKSV3GxvEwZzlqBqGLQko=
github.com/kastenhq/stow v0.2.6-kasten.1.0.20220726203146-8a90401257d4/go.mod h1:6+N3Bn9Whpb+bnRFQ2A2kAyAUiYvYM0+N5bArNd4K8s=
github.com/kelseyhightower/envconfig v1.4.0 h1:Im6hONhd3pLkfDFsbRgu68RDNkGF1r3dvMUtDTo2cv8=
github.com/kelseyhightower/envconfig v1.4.0/go.mod h1:cccZRl6mQpaq41TPp5QxidR+Sa3axMbJDNb//FQX6Gg=
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
Expand Down
1 change: 1 addition & 0 deletions pkg/objectstore/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package objectstore

const googleGCSHost = "https://storage.googleapis.com"
const REGIONAL = "REGIONAL"

// ProviderType enum for different providers
type ProviderType string
Expand Down
18 changes: 11 additions & 7 deletions pkg/objectstore/objectstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@ func s3Config(ctx context.Context, config ProviderConfig, secret *Secret) (stowK
return stows3.Kind, cm, nil
}

func gcsConfig(ctx context.Context, secret *Secret) (stowKind string, stowConfig stow.Config, err error) {
func gcsConfig(ctx context.Context, config ProviderConfig, secret *Secret) (stowKind string, stowConfig stow.Config, err error) {
var configJSON string
var projectID string
cm := stow.ConfigMap{}
if secret != nil {
if secret.Type != SecretTypeGcpServiceAccountKey {
return "", nil, errors.Errorf("invalid secret type %s", secret.Type)
}
configJSON = secret.Gcp.ServiceKey
projectID = secret.Gcp.ProjectID
if config.Region != "" {
cm[stowgcs.ConfigLocation] = config.Region
cm[stowgcs.ConfigStorageClass] = REGIONAL
}
} else {
creds, err := google.FindDefaultCredentials(ctx, compute.ComputeScope)
if err != nil {
Expand All @@ -162,11 +167,10 @@ func gcsConfig(ctx context.Context, secret *Secret) (stowKind string, stowConfig
configJSON = string(creds.JSON)
projectID = creds.ProjectID
}
return stowgcs.Kind, stow.ConfigMap{
stowgcs.ConfigJSON: configJSON,
stowgcs.ConfigProjectId: projectID,
stowgcs.ConfigScopes: "",
}, nil
cm[stowgcs.ConfigJSON] = configJSON
cm[stowgcs.ConfigProjectId] = projectID
cm[stowgcs.ConfigScopes] = ""
return stowgcs.Kind, cm, nil
}

func azureConfig(ctx context.Context, secret *Secret) (stowKind string, stowConfig stow.Config, err error) {
Expand Down Expand Up @@ -203,7 +207,7 @@ func getConfig(ctx context.Context, config ProviderConfig, secret *Secret) (stow
case ProviderTypeS3:
return s3Config(ctx, config, secret)
case ProviderTypeGCS:
return gcsConfig(ctx, secret)
return gcsConfig(ctx, config, secret)
case ProviderTypeAzure:
return azureConfig(ctx, secret)
default:
Expand Down

0 comments on commit c3a90d5

Please sign in to comment.