in lib/backend/gcsbackend/client.go [86:131]
func NewClient(
config Config, userAuth UserAuthConfig, stats tally.Scope, opts ...Option) (*Client, error) {
config.applyDefaults()
if config.Username == "" {
return nil, errors.New("invalid config: username required")
}
if config.Bucket == "" {
return nil, errors.New("invalid config: bucket required")
}
if !path.IsAbs(config.RootDirectory) {
return nil, errors.New("invalid config: root_directory must be absolute path")
}
pather, err := namepath.New(config.RootDirectory, config.NamePath)
if err != nil {
return nil, fmt.Errorf("namepath: %s", err)
}
auth, ok := userAuth[config.Username]
if !ok {
return nil, errors.New("auth not configured for username")
}
if len(opts) > 0 {
// For mock.
client := &Client{config, pather, stats, nil}
for _, opt := range opts {
opt(client)
}
return client, nil
}
ctx := context.Background()
sClient, err := storage.NewClient(ctx,
option.WithCredentialsJSON([]byte(auth.GCS.AccessBlob)))
if err != nil {
return nil, fmt.Errorf("invalid gcs credentials: %s", err)
}
client := &Client{config, pather, stats,
NewGCS(ctx, sClient.Bucket(config.Bucket), &config)}
log.Infof("Initalized GCS backend with config: %s", config)
return client, nil
}