Skip to content

Commit

Permalink
Add credentials argument for GCS driver
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Kostov <kostov.andrey@gmail.com>
  • Loading branch information
AndreyKostov authored and caervs committed Sep 5, 2018
1 parent 9930542 commit 78238ef
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions registry/storage/driver/gcs/gcs.go
Expand Up @@ -17,6 +17,7 @@ package gcs
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -140,6 +141,27 @@ func FromParameters(parameters map[string]interface{}) (storagedriver.StorageDri
return nil, err
}
ts = jwtConf.TokenSource(context.Background())
} else if credentials, ok := parameters["credentials"]; ok {
credentialMap, ok := credentials.(map[interface{}]interface{})
if !ok {
return nil, fmt.Errorf("The credentials were not specified in the correct format")
}

stringMap := map[string]interface{}{}
for k, v := range credentialMap {
key, ok := k.(string)
if !ok {
return nil, fmt.Errorf("One of the credential keys was not a string")
}
stringMap[key] = v
}

data, err := json.Marshal(stringMap)
jwtConf, err := google.JWTConfigFromJSON(data, storage.ScopeFullControl)
if err != nil {
return nil, err
}
ts = jwtConf.TokenSource(context.Background())
} else {
var err error
ts, err = google.DefaultTokenSource(context.Background(), storage.ScopeFullControl)
Expand Down

0 comments on commit 78238ef

Please sign in to comment.