forked from C2FO/vfs
/
options.go
34 lines (29 loc) · 1.12 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package gs
import (
"google.golang.org/api/option"
"github.com/c2fo/vfs"
)
// Options holds Google Cloud Storage -specific options. Currently only client options are used.
type Options struct {
APIKey string `json:"apiKey,omitempty"`
CredentialFile string `json:"credentialFilePath,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Scopes []string `json:"WithoutAuthentication,omitempty"`
}
func parseClientOptions(opts vfs.Options) []option.ClientOption {
var googleClientOpts []option.ClientOption
// we only care about 'gs.Options' types, skip anything else
if opts, ok := opts.(Options); ok {
switch {
case opts.APIKey != "":
googleClientOpts = append(googleClientOpts, option.WithAPIKey(opts.APIKey))
case opts.CredentialFile != "":
googleClientOpts = append(googleClientOpts, option.WithServiceAccountFile(opts.CredentialFile))
case opts.Endpoint != "":
googleClientOpts = append(googleClientOpts, option.WithEndpoint(opts.Endpoint))
case len(opts.Scopes) > 0:
googleClientOpts = append(googleClientOpts, option.WithScopes(opts.Scopes...))
}
}
return googleClientOpts
}