Skip to content

Commit b7a3ad4

Browse files
authored
PBM-1484 gcp sdk fix (#1099)
* add client email to config * add equal * remove non-mandatory projectId
1 parent fadb212 commit b7a3ad4

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

pbm/config/config.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ func (c *Config) String() string {
150150
if c.Storage.GCS.Credentials.PrivateKey != "" {
151151
c.Storage.GCS.Credentials.PrivateKey = "***"
152152
}
153+
if c.Storage.GCS.Credentials.ClientEmail != "" {
154+
c.Storage.GCS.Credentials.ClientEmail = "***"
155+
}
153156
}
154157

155158
b, err := yaml.Marshal(c)
@@ -254,6 +257,8 @@ func (s *StorageConf) Equal(other *StorageConf) bool {
254257
return s.S3.Equal(other.S3)
255258
case storage.Azure:
256259
return s.Azure.Equal(other.Azure)
260+
case storage.GCS:
261+
return s.GCS.Equal(other.GCS)
257262
case storage.Filesystem:
258263
return s.Filesystem.Equal(other.Filesystem)
259264
case storage.Blackhole:
@@ -286,6 +291,8 @@ func (s *StorageConf) Typ() string {
286291
return "S3"
287292
case storage.Azure:
288293
return "Azure"
294+
case storage.GCS:
295+
return "GCS"
289296
case storage.Filesystem:
290297
return "FS"
291298
case storage.Blackhole:
@@ -318,6 +325,11 @@ func (s *StorageConf) Path() string {
318325
if s.Azure.Prefix != "" {
319326
path += "/" + s.Azure.Prefix
320327
}
328+
case storage.GCS:
329+
path = "gs://" + s.GCS.Bucket
330+
if s.GCS.Prefix != "" {
331+
path += "/" + s.GCS.Prefix
332+
}
321333
case storage.Filesystem:
322334
path = s.Filesystem.Path
323335
}

pbm/storage/gcs/gcs.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"fmt"
77
"io"
88
"path"
9+
"reflect"
910
"strings"
1011
"time"
1112

@@ -32,8 +33,8 @@ type Config struct {
3233
}
3334

3435
type Credentials struct {
35-
ProjectID string `bson:"projectId" json:"projectId,omitempty" yaml:"projectId,omitempty"`
36-
PrivateKey string `bson:"privateKey" json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
36+
ClientEmail string `bson:"clientEmail" json:"clientEmail,omitempty" yaml:"clientEmail,omitempty"`
37+
PrivateKey string `bson:"privateKey" json:"privateKey,omitempty" yaml:"privateKey,omitempty"`
3738
}
3839

3940
type Retryer struct {
@@ -52,7 +53,6 @@ type Retryer struct {
5253

5354
type ServiceAccountCredentials struct {
5455
Type string `json:"type"`
55-
ProjectID string `json:"project_id"`
5656
PrivateKey string `json:"private_key"`
5757
ClientEmail string `json:"client_email"`
5858
AuthURI string `json:"auth_uri"`
@@ -77,6 +77,28 @@ func (cfg *Config) Clone() *Config {
7777
return &rv
7878
}
7979

80+
func (cfg *Config) Equal(other *Config) bool {
81+
if cfg == nil || other == nil {
82+
return cfg == other
83+
}
84+
85+
if cfg.Bucket != other.Bucket {
86+
return false
87+
}
88+
if cfg.Prefix != other.Prefix {
89+
return false
90+
}
91+
if cfg.ChunkSize != other.ChunkSize {
92+
return false
93+
}
94+
95+
if !reflect.DeepEqual(cfg.Credentials, other.Credentials) {
96+
return false
97+
}
98+
99+
return true
100+
}
101+
80102
func New(opts *Config, node string, l log.LogEvent) (*GCS, error) {
81103
g := &GCS{
82104
opts: opts,
@@ -241,22 +263,21 @@ func (g *GCS) Copy(src, dst string) error {
241263
func (g *GCS) gcsClient() (*gcs.Client, error) {
242264
ctx := context.Background()
243265

244-
if g.opts.Credentials.ProjectID == "" || g.opts.Credentials.PrivateKey == "" {
245-
return nil, errors.New("projectID and privateKey are required for GCS credentials")
266+
if g.opts.Credentials.PrivateKey == "" || g.opts.Credentials.ClientEmail == "" {
267+
return nil, errors.New("clientEmail and privateKey are required for GCS credentials")
246268
}
247269

248270
creds, err := json.Marshal(ServiceAccountCredentials{
249271
Type: "service_account",
250-
ProjectID: g.opts.Credentials.ProjectID,
251272
PrivateKey: g.opts.Credentials.PrivateKey,
252-
ClientEmail: fmt.Sprintf("service@%s.iam.gserviceaccount.com", g.opts.Credentials.ProjectID),
273+
ClientEmail: g.opts.Credentials.ClientEmail,
253274
AuthURI: "https://accounts.google.com/o/oauth2/auth",
254275
TokenURI: "https://oauth2.googleapis.com/token",
255276
UniverseDomain: "googleapis.com",
256277
AuthProviderCertURL: "https://www.googleapis.com/oauth2/v1/certs",
257278
ClientCertURL: fmt.Sprintf(
258-
"https://www.googleapis.com/robot/v1/metadata/x509/%s.iam.gserviceaccount.com",
259-
g.opts.Credentials.ProjectID,
279+
"https://www.googleapis.com/robot/v1/metadata/x509/%s",
280+
g.opts.Credentials.ClientEmail,
260281
),
261282
})
262283
if err != nil {

0 commit comments

Comments
 (0)