-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat: Support config timeout for AlibabaCloud OSS requests #14856
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
Changes from 4 commits
323bdac
0c391ee
10111c0
06fd90e
dd898d4
b08b5dd
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 |
|---|---|---|
|
|
@@ -35,10 +35,12 @@ type OssObjectClient struct { | |
|
|
||
| // OssConfig is config for the OSS Chunk Client. | ||
| type OssConfig struct { | ||
| Bucket string `yaml:"bucket"` | ||
| Endpoint string `yaml:"endpoint"` | ||
| AccessKeyID string `yaml:"access_key_id"` | ||
| SecretAccessKey string `yaml:"secret_access_key"` | ||
| Bucket string `yaml:"bucket"` | ||
| Endpoint string `yaml:"endpoint"` | ||
| AccessKeyID string `yaml:"access_key_id"` | ||
| SecretAccessKey string `yaml:"secret_access_key"` | ||
| ConnectionTimeoutSec int64 `yaml:"conn_timeout_sec"` | ||
| ReadWriteTimeoutSec int64 `yaml:"read_write_timeout_sec"` | ||
| } | ||
|
|
||
| // RegisterFlags registers flags. | ||
|
|
@@ -52,11 +54,35 @@ func (cfg *OssConfig) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { | |
| f.StringVar(&cfg.Endpoint, prefix+"oss.endpoint", "", "oss Endpoint to connect to.") | ||
| f.StringVar(&cfg.AccessKeyID, prefix+"oss.access-key-id", "", "alibabacloud Access Key ID") | ||
| f.StringVar(&cfg.SecretAccessKey, prefix+"oss.secret-access-key", "", "alibabacloud Secret Access Key") | ||
| f.Int64Var(&cfg.ConnectionTimeoutSec, prefix+"oss.conn-timeout-sec", 30, "Connection timeout in seconds") | ||
| f.Int64Var(&cfg.ReadWriteTimeoutSec, prefix+"oss.read-write-timeout-sec", 60, "Read/Write timeout in seconds") | ||
| } | ||
|
|
||
| func (cfg *OssConfig) Validate() error { | ||
| if len(cfg.Bucket) == 0 { | ||
|
||
| return errors.New("bucket name is required") | ||
| } | ||
| if len(cfg.Endpoint) == 0 { | ||
| return errors.New("endpoint is required") | ||
| } | ||
| if len(cfg.AccessKeyID) == 0 { | ||
| return errors.New("access key id is required") | ||
| } | ||
| if len(cfg.SecretAccessKey) == 0 { | ||
| return errors.New("secret access key is required") | ||
| } | ||
| if cfg.ConnectionTimeoutSec <= 0 { | ||
| return errors.New("connection timeout must be greater than 0") | ||
| } | ||
| if cfg.ReadWriteTimeoutSec <= 0 { | ||
| return errors.New("read write timeout must be greater than 0") | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| // NewOssObjectClient makes a new chunk.Client that writes chunks to OSS. | ||
| func NewOssObjectClient(_ context.Context, cfg OssConfig) (client.ObjectClient, error) { | ||
| client, err := oss.New(cfg.Endpoint, cfg.AccessKeyID, cfg.SecretAccessKey) | ||
| client, err := oss.New(cfg.Endpoint, cfg.AccessKeyID, cfg.SecretAccessKey, oss.Timeout(cfg.ConnectionTimeoutSec, cfg.ReadWriteTimeoutSec)) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.