Add credentials argument for GCS driver
Signed-off-by: Andrey Kostov <kostov.andrey@gmail.com>master
							parent
							
								
									9930542dc5
								
							
						
					
					
						commit
						78238ef1a0
					
				|  | @ -17,6 +17,7 @@ package gcs | ||||||
| import ( | import ( | ||||||
| 	"bytes" | 	"bytes" | ||||||
| 	"context" | 	"context" | ||||||
|  | 	"encoding/json" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"io" | 	"io" | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
|  | @ -140,6 +141,27 @@ func FromParameters(parameters map[string]interface{}) (storagedriver.StorageDri | ||||||
| 			return nil, err | 			return nil, err | ||||||
| 		} | 		} | ||||||
| 		ts = jwtConf.TokenSource(context.Background()) | 		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 { | 	} else { | ||||||
| 		var err error | 		var err error | ||||||
| 		ts, err = google.DefaultTokenSource(context.Background(), storage.ScopeFullControl) | 		ts, err = google.DefaultTokenSource(context.Background(), storage.ScopeFullControl) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue