forked from TrueCloudLab/distribution
update: set User-Agent header in GCS storage driver (#4203)
This commit is contained in:
commit
ec617ca6d2
1 changed files with 13 additions and 11 deletions
|
@ -155,6 +155,7 @@ func FromParameters(ctx context.Context, parameters map[string]interface{}) (sto
|
||||||
jwtConf := new(jwt.Config)
|
jwtConf := new(jwt.Config)
|
||||||
var err error
|
var err error
|
||||||
var gcs *storage.Client
|
var gcs *storage.Client
|
||||||
|
var options []option.ClientOption
|
||||||
if keyfile, ok := parameters["keyfile"]; ok {
|
if keyfile, ok := parameters["keyfile"]; ok {
|
||||||
jsonKey, err := os.ReadFile(fmt.Sprint(keyfile))
|
jsonKey, err := os.ReadFile(fmt.Sprint(keyfile))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -165,10 +166,7 @@ func FromParameters(ctx context.Context, parameters map[string]interface{}) (sto
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ts = jwtConf.TokenSource(ctx)
|
ts = jwtConf.TokenSource(ctx)
|
||||||
gcs, err = storage.NewClient(ctx, option.WithCredentialsFile(fmt.Sprint(keyfile)))
|
options = append(options, option.WithCredentialsFile(fmt.Sprint(keyfile)))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else if credentials, ok := parameters["credentials"]; ok {
|
} else if credentials, ok := parameters["credentials"]; ok {
|
||||||
credentialMap, ok := credentials.(map[interface{}]interface{})
|
credentialMap, ok := credentials.(map[interface{}]interface{})
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -194,10 +192,7 @@ func FromParameters(ctx context.Context, parameters map[string]interface{}) (sto
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
ts = jwtConf.TokenSource(ctx)
|
ts = jwtConf.TokenSource(ctx)
|
||||||
gcs, err = storage.NewClient(ctx, option.WithCredentialsJSON(data))
|
options = append(options, option.WithCredentialsJSON(data))
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
var err error
|
var err error
|
||||||
// DefaultTokenSource is a convenience method. It first calls FindDefaultCredentials,
|
// DefaultTokenSource is a convenience method. It first calls FindDefaultCredentials,
|
||||||
|
@ -207,12 +202,19 @@ func FromParameters(ctx context.Context, parameters map[string]interface{}) (sto
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
gcs, err = storage.NewClient(ctx)
|
}
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
if userAgent, ok := parameters["useragent"]; ok {
|
||||||
|
if ua, ok := userAgent.(string); ok && ua != "" {
|
||||||
|
options = append(options, option.WithUserAgent(ua))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcs, err = storage.NewClient(ctx, options...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
maxConcurrency, err := base.GetLimitFromParameter(parameters["maxconcurrency"], minConcurrency, defaultMaxConcurrency)
|
maxConcurrency, err := base.GetLimitFromParameter(parameters["maxconcurrency"], minConcurrency, defaultMaxConcurrency)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("maxconcurrency config error: %s", err)
|
return nil, fmt.Errorf("maxconcurrency config error: %s", err)
|
||||||
|
|
Loading…
Reference in a new issue