New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new http transport params to storage drivers #4160
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ Amazon S3 or S3 compatible services for object storage. | |
| `keyid` | no | Optional KMS key ID to use for encryption (encrypt must be true, or this parameter is ignored). The default is `none`. | | ||
| `secure` | no | Indicates whether to use HTTPS instead of HTTP. A boolean value. The default is `true`. | | ||
| `skipverify` | no | Skips TLS verification when the value is set to `true`. The default is `false`. | | ||
| `disablekeepalives` | no | Disables HTTP keep-alives on the HTTP tranport when `true`. Each connection to the server will be used for a single HTTP request. The default is `false`. | | ||
| `v4auth` | no | Indicates whether the registry uses Version 4 of AWS's authentication. The default is `true`. | | ||
| `chunksize` | no | The S3 API requires multipart upload chunks to be at least 5MB. This value should be a number that is larger than 5 * 1024 * 1024.| | ||
| `multipartcopychunksize` | no | Default chunk size for all but the last S3 Multipart Upload part when copying stored objects. | | ||
|
@@ -32,6 +33,9 @@ Amazon S3 or S3 compatible services for object storage. | |
| `usedualstack` | no | Use AWS dual-stack API endpoints. | | ||
| `accelerate` | no | Enable S3 Transfer Acceleration. | | ||
| `objectacl` | no | The S3 Canned ACL for objects. The default value is "private". | | ||
| `usedualstack` | no | Use AWS S3 dual-stack endpoints, which support both IPv6 and IPv4, when set to `true`. The default is `false`. | | ||
| `multipartcombinesmallpart` | no | Combines small pending uploads with the ready part when `true`. The default is `true`. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is this option implemented? I don't see it anywhere else in the PR nor could I find any evidence in the code base that this was already implemented. |
||
| `accelerate` | no | Use AWS S3 Transfer Acceleration endpoints when set to `true`. The default is `false`. | | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| `loglevel` | no | The log level for the S3 client. The default value is `off`. | | ||
|
||
> **Note** You can provide empty strings for your access and secret keys to run the driver | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,11 +151,41 @@ func FromParameters(ctx context.Context, parameters map[string]interface{}) (sto | |
} | ||
} | ||
|
||
disableKeepAlivesParam := false | ||
disableKeepAlives := parameters["disablekeepalives"] | ||
switch disableKeepAlives := disableKeepAlives.(type) { | ||
case string: | ||
b, err := strconv.ParseBool(disableKeepAlives) | ||
if err != nil { | ||
return nil, fmt.Errorf("the disablekeepalives parameter should be a boolean") | ||
} | ||
disableKeepAlivesParam = b | ||
case bool: | ||
disableKeepAlivesParam = disableKeepAlives | ||
case nil: | ||
// do nothing | ||
default: | ||
return nil, fmt.Errorf("the disablekeepalives parameter should be a boolean") | ||
} | ||
Comment on lines
+154
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is very repetitive. Given that the same validation rules apply to all the boolean parameters, how about extracting the common logic to a function or closure? E.g.: boolParam := func(name string) (bool, error) { /* ... */ }
disableKeepAlives, err := boolParam("disablekeepalives")
if err != nil {
return nil, err
} If you want to get really fancy, you could apply the panic-recover error handling pattern to elide having to write if boolParam("disablekeepalives") {
/* ... */
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should that kind of refactoring be a separate pr? I was trying to maintain the pattern in nearby code. I'm happy to do that here for gcs. The azure driver's config handling does seem easier to work with than the more manual extraction gcs & aws drivers do. Any reason we shouldn't move toward that for gcs, and aws? |
||
|
||
httpTransportModified := false | ||
httpTransport := http.DefaultTransport.(*http.Transport).Clone() | ||
|
||
if disableKeepAlivesParam { | ||
httpTransport.DisableKeepAlives = true | ||
httpTransportModified = true | ||
} | ||
|
||
var ts oauth2.TokenSource | ||
jwtConf := new(jwt.Config) | ||
var err error | ||
var gcs *storage.Client | ||
var options []option.ClientOption | ||
if httpTransportModified { | ||
options = append(options, option.WithHTTPClient(&http.Client{ | ||
Transport: httpTransport, | ||
})) | ||
} | ||
if keyfile, ok := parameters["keyfile"]; ok { | ||
jsonKey, err := os.ReadFile(fmt.Sprint(keyfile)) | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usedualstack
is already documented, three rows up.