6
6
"fmt"
7
7
"io"
8
8
"path"
9
+ "reflect"
9
10
"strings"
10
11
"time"
11
12
@@ -32,8 +33,8 @@ type Config struct {
32
33
}
33
34
34
35
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"`
37
38
}
38
39
39
40
type Retryer struct {
@@ -52,7 +53,6 @@ type Retryer struct {
52
53
53
54
type ServiceAccountCredentials struct {
54
55
Type string `json:"type"`
55
- ProjectID string `json:"project_id"`
56
56
PrivateKey string `json:"private_key"`
57
57
ClientEmail string `json:"client_email"`
58
58
AuthURI string `json:"auth_uri"`
@@ -77,6 +77,28 @@ func (cfg *Config) Clone() *Config {
77
77
return & rv
78
78
}
79
79
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
+
80
102
func New (opts * Config , node string , l log.LogEvent ) (* GCS , error ) {
81
103
g := & GCS {
82
104
opts : opts ,
@@ -241,22 +263,21 @@ func (g *GCS) Copy(src, dst string) error {
241
263
func (g * GCS ) gcsClient () (* gcs.Client , error ) {
242
264
ctx := context .Background ()
243
265
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" )
246
268
}
247
269
248
270
creds , err := json .Marshal (ServiceAccountCredentials {
249
271
Type : "service_account" ,
250
- ProjectID : g .opts .Credentials .ProjectID ,
251
272
PrivateKey : g .opts .Credentials .PrivateKey ,
252
- ClientEmail : fmt . Sprintf ( "service@%s.iam.gserviceaccount.com" , g .opts .Credentials .ProjectID ) ,
273
+ ClientEmail : g .opts .Credentials .ClientEmail ,
253
274
AuthURI : "https://accounts.google.com/o/oauth2/auth" ,
254
275
TokenURI : "https://oauth2.googleapis.com/token" ,
255
276
UniverseDomain : "googleapis.com" ,
256
277
AuthProviderCertURL : "https://www.googleapis.com/oauth2/v1/certs" ,
257
278
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 ,
260
281
),
261
282
})
262
283
if err != nil {
0 commit comments