Skip to content

Commit

Permalink
GCS: fix the WithoutAuthentication option (#290)
Browse files Browse the repository at this point in the history
* GCS: fix the WithoutAuthentication option

* fix test
  • Loading branch information
Xin Hao committed Sep 20, 2023
1 parent 1cbec84 commit bc8b40d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ log:
level: INFO
console: true
files:
- logs/nebula-importer.log
- logs/nebula-importer.log
```

* `log.level`: **Optional**. Specifies the log level, optional values is `DEBUG`, `INFO`, `WARN`, `ERROR`, `PANIC` or `FATAL`. The default value is `INFO`.
Expand Down Expand Up @@ -299,13 +299,15 @@ gcs:
key: <key>
credentialsFile: <Service account or refresh token JSON credentials file>
credentialsJSON: <Service account or refresh token JSON credentials>
withoutAuthentication: <false | true>
```

* `endpoint`: **Optional**. The endpoint of GCS service.
* `bucket`: **Required**. The bucket of file in GCS service.
* `key`: **Required**. The object key of file in GCS service.
* `credentialsFile`: **Optional**. Path to the service account or refresh token JSON credentials file. Not required for public data.
* `credentialsJSON`: **Optional**. Content of the service account or refresh token JSON credentials file. Not required for public data.
* `withoutAuthentication`: **Optional**. Specifies that no authentication should be used, defaults to `false`.

#### batch

Expand Down
13 changes: 7 additions & 6 deletions pkg/source/gcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ var _ Source = (*gcsSource)(nil)

type (
GCSConfig struct {
Endpoint string `yaml:"endpoint,omitempty"`
CredentialsFile string `yaml:"credentialsFile,omitempty"`
CredentialsJSON string `yaml:"credentialsJSON,omitempty"`
Bucket string `yaml:"bucket,omitempty"`
Key string `yaml:"key,omitempty"`
Endpoint string `yaml:"endpoint,omitempty"`
CredentialsFile string `yaml:"credentialsFile,omitempty"`
CredentialsJSON string `yaml:"credentialsJSON,omitempty"`
WithoutAuthentication bool `yaml:"withoutAuthentication,omitempty"`
Bucket string `yaml:"bucket,omitempty"`
Key string `yaml:"key,omitempty"`
}

gcsSource struct {
Expand Down Expand Up @@ -46,7 +47,7 @@ func (s *gcsSource) Open() error {
gcsOptions = append(gcsOptions, option.WithCredentialsFile(s.c.GCS.CredentialsFile))
} else if s.c.GCS.CredentialsJSON != "" {
gcsOptions = append(gcsOptions, option.WithCredentialsJSON([]byte(s.c.GCS.CredentialsJSON)))
} else {
} else if s.c.GCS.WithoutAuthentication {
gcsOptions = append(gcsOptions, option.WithoutAuthentication())
}

Expand Down
7 changes: 4 additions & 3 deletions pkg/source/gcs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ var _ = Describe("gcsSource", func() {

c := Config{
GCS: &GCSConfig{
Endpoint: httpServer.URL,
Bucket: "bucket",
Key: "key",
Endpoint: httpServer.URL,
Bucket: "bucket",
Key: "key",
WithoutAuthentication: true,
},
}

Expand Down

0 comments on commit bc8b40d

Please sign in to comment.