(bucket, region string)
| 122 | } |
| 123 | |
| 124 | func (t *Storage) createBucketClient(bucket, region string) (s3Client, error) { |
| 125 | t.mu.Lock() |
| 126 | defer t.mu.Unlock() |
| 127 | |
| 128 | // Check again if someone did this before us |
| 129 | if client := t.clientsByBucket[bucket]; client != nil { |
| 130 | return client, nil |
| 131 | } |
| 132 | |
| 133 | if client := t.clientsByRegion[region]; client != nil { |
| 134 | t.clientsByBucket[bucket] = client |
| 135 | return client, nil |
| 136 | } |
| 137 | |
| 138 | conf := t.defaultConfig.Copy() |
| 139 | conf.Region = region |
| 140 | |
| 141 | client, err := createClient(conf, t.clientOptions, t.config) |
| 142 | if err != nil { |
| 143 | return nil, errctx.Wrap(err, errctx.WithPrefix("can't create regional S3 client")) |
| 144 | } |
| 145 | |
| 146 | t.clientsByRegion[region] = client |
| 147 | t.clientsByBucket[bucket] = client |
| 148 | |
| 149 | return client, nil |
| 150 | } |
| 151 | |
| 152 | func createClient(conf aws.Config, opts []func(*s3.Options), config *Config) (s3Client, error) { |
| 153 | client := s3.NewFromConfig(conf, opts...) |
no test coverage detected