Skip to content

Commit

Permalink
fix: gcs driver various fixes (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles546 committed Aug 25, 2023
1 parent 34f5008 commit ef8c850
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions drivers/cmd/gcloud-storage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,10 @@ func getStorageClient(serviceAccountBytes string) *storage.Client {
return client
}

func getCommonParams(params interface{}) (string, string) {
func getCommonParams(params interface{}) string {
serviceAccountBytes, _ := dipper.GetMapDataStr(params, "service_account")
project, ok := dipper.GetMapDataStr(params, "project")
if !ok {
panic(ErrMissingProject)
}

return serviceAccountBytes, project
return serviceAccountBytes
}

// BucketIterator is an interface for iterate BucketAttrs.
Expand All @@ -103,7 +99,11 @@ type ObjectIterator interface {
func listBuckets(msg *dipper.Message) {
msg = dipper.DeserializePayload(msg)
params := msg.Payload
serviceAccountBytes, project := getCommonParams(params)
serviceAccountBytes := getCommonParams(params)
project, ok := dipper.GetMapDataStr(params, "project")
if !ok {
panic(ErrMissingProject)
}

client := getStorageClient(serviceAccountBytes)

Expand Down Expand Up @@ -135,7 +135,7 @@ func listBucketsHelper(msg *dipper.Message, it BucketIterator) {
func listFiles(msg *dipper.Message) {
msg = dipper.DeserializePayload(msg)
params := msg.Payload
serviceAccountBytes, _ := getCommonParams(params)
serviceAccountBytes := getCommonParams(params)

bucket, ok := dipper.GetMapDataStr(params, "bucket")
if !ok {
Expand Down Expand Up @@ -185,7 +185,7 @@ func listFilesHelper(msg *dipper.Message, it ObjectIterator) {
func fetchFile(msg *dipper.Message) {
msg = dipper.DeserializePayload(msg)
params := msg.Payload
serviceAccountBytes, _ := getCommonParams(params)
serviceAccountBytes := getCommonParams(params)

bucket, ok := dipper.GetMapDataStr(params, "bucket")
if !ok {
Expand Down Expand Up @@ -227,7 +227,7 @@ func fetchFile(msg *dipper.Message) {
func writeFile(msg *dipper.Message) {
msg = dipper.DeserializePayload(msg)
params := msg.Payload
serviceAccountBytes, _ := getCommonParams(params)
serviceAccountBytes := getCommonParams(params)

bucket, ok := dipper.GetMapDataStr(params, "bucket")
if !ok {
Expand All @@ -252,7 +252,7 @@ func writeFile(msg *dipper.Message) {
fileType = attr.ContentType
}

wc := dipper.Must(obj.NewWriter(ctx)).(*storage.Writer)
wc := obj.NewWriter(ctx)
defer wc.Close()

switch v := content.(type) {
Expand Down Expand Up @@ -286,7 +286,7 @@ func writeFile(msg *dipper.Message) {
func getAttrs(msg *dipper.Message) {
msg = dipper.DeserializePayload(msg)
params := msg.Payload
serviceAccountBytes, _ := getCommonParams(params)
serviceAccountBytes := getCommonParams(params)

bucket, ok := dipper.GetMapDataStr(params, "bucket")
if !ok {
Expand All @@ -308,7 +308,7 @@ func getAttrs(msg *dipper.Message) {
msg.Reply <- dipper.Message{
Payload: map[string]interface{}{
"attrs": attr,
"exists": err != nil,
"exists": err == nil,
},
}
}

0 comments on commit ef8c850

Please sign in to comment.