Skip to content

Commit fc5ed22

Browse files
authored
pass context to S3 and dynamoDB storage calls (#27927)
* pass context to S3 and dynamoDB storage calls * add changelog * fix changelog
1 parent 2fc8e35 commit fc5ed22

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

changelog/27927.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
```release-note:improvement
2+
storage/s3: Pass context to AWS SDK calls
3+
```
4+
```release-note:improvement
5+
storage/dynamodb: Pass context to AWS SDK calls
6+
```

physical/dynamodb/dynamodb.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (d *DynamoDBBackend) Put(ctx context.Context, entry *physical.Entry) error
294294
})
295295
}
296296

297-
return d.batchWriteRequests(requests)
297+
return d.batchWriteRequests(ctx, requests)
298298
}
299299

300300
// Get is used to fetch an entry
@@ -304,7 +304,7 @@ func (d *DynamoDBBackend) Get(ctx context.Context, key string) (*physical.Entry,
304304
d.permitPool.Acquire()
305305
defer d.permitPool.Release()
306306

307-
resp, err := d.client.GetItem(&dynamodb.GetItemInput{
307+
resp, err := d.client.GetItemWithContext(ctx, &dynamodb.GetItemInput{
308308
TableName: aws.String(d.table),
309309
ConsistentRead: aws.Bool(true),
310310
Key: map[string]*dynamodb.AttributeValue{
@@ -363,7 +363,7 @@ func (d *DynamoDBBackend) Delete(ctx context.Context, key string) error {
363363
excluded = append(excluded, recordKeyForVaultKey(prefixes[index-1]))
364364
}
365365

366-
hasChildren, err := d.hasChildren(prefix, excluded)
366+
hasChildren, err := d.hasChildren(ctx, prefix, excluded)
367367
if err != nil {
368368
return err
369369
}
@@ -387,7 +387,7 @@ func (d *DynamoDBBackend) Delete(ctx context.Context, key string) error {
387387
}
388388
}
389389

390-
return d.batchWriteRequests(requests)
390+
return d.batchWriteRequests(ctx, requests)
391391
}
392392

393393
// List is used to list all the keys under a given
@@ -420,7 +420,7 @@ func (d *DynamoDBBackend) List(ctx context.Context, prefix string) ([]string, er
420420
d.permitPool.Acquire()
421421
defer d.permitPool.Release()
422422

423-
err := d.client.QueryPages(queryInput, func(out *dynamodb.QueryOutput, lastPage bool) bool {
423+
err := d.client.QueryPagesWithContext(ctx, queryInput, func(out *dynamodb.QueryOutput, lastPage bool) bool {
424424
var record DynamoDBRecord
425425
for _, item := range out.Items {
426426
dynamodbattribute.UnmarshalMap(item, &record)
@@ -443,7 +443,7 @@ func (d *DynamoDBBackend) List(ctx context.Context, prefix string) ([]string, er
443443
// before any deletes take place. To account for that hasChildren accepts a slice of
444444
// strings representing values we expect to find that should NOT be counted as children
445445
// because they are going to be deleted.
446-
func (d *DynamoDBBackend) hasChildren(prefix string, exclude []string) (bool, error) {
446+
func (d *DynamoDBBackend) hasChildren(ctx context.Context, prefix string, exclude []string) (bool, error) {
447447
prefix = strings.TrimSuffix(prefix, "/")
448448
prefix = escapeEmptyPath(prefix)
449449

@@ -473,7 +473,7 @@ func (d *DynamoDBBackend) hasChildren(prefix string, exclude []string) (bool, er
473473
d.permitPool.Acquire()
474474
defer d.permitPool.Release()
475475

476-
out, err := d.client.Query(queryInput)
476+
out, err := d.client.QueryWithContext(ctx, queryInput)
477477
if err != nil {
478478
return false, err
479479
}
@@ -519,7 +519,7 @@ func (d *DynamoDBBackend) HAEnabled() bool {
519519

520520
// batchWriteRequests takes a list of write requests and executes them in badges
521521
// with a maximum size of 25 (which is the limit of BatchWriteItem requests).
522-
func (d *DynamoDBBackend) batchWriteRequests(requests []*dynamodb.WriteRequest) error {
522+
func (d *DynamoDBBackend) batchWriteRequests(ctx context.Context, requests []*dynamodb.WriteRequest) error {
523523
for len(requests) > 0 {
524524
batchSize := int(math.Min(float64(len(requests)), 25))
525525
batch := map[string][]*dynamodb.WriteRequest{d.table: requests[:batchSize]}
@@ -534,7 +534,7 @@ func (d *DynamoDBBackend) batchWriteRequests(requests []*dynamodb.WriteRequest)
534534

535535
for len(batch) > 0 {
536536
var output *dynamodb.BatchWriteItemOutput
537-
output, err = d.client.BatchWriteItem(&dynamodb.BatchWriteItemInput{
537+
output, err = d.client.BatchWriteItemWithContext(ctx, &dynamodb.BatchWriteItemInput{
538538
RequestItems: batch,
539539
})
540540
if err != nil {

physical/s3/s3.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *S3Backend) Put(ctx context.Context, entry *physical.Entry) error {
183183
putObjectInput.SSEKMSKeyId = aws.String(s.kmsKeyId)
184184
}
185185

186-
_, err := s.client.PutObject(putObjectInput)
186+
_, err := s.client.PutObjectWithContext(ctx, putObjectInput)
187187
if err != nil {
188188
return err
189189
}
@@ -201,7 +201,7 @@ func (s *S3Backend) Get(ctx context.Context, key string) (*physical.Entry, error
201201
// Setup key
202202
key = path.Join(s.path, key)
203203

204-
resp, err := s.client.GetObject(&s3.GetObjectInput{
204+
resp, err := s.client.GetObjectWithContext(ctx, &s3.GetObjectInput{
205205
Bucket: aws.String(s.bucket),
206206
Key: aws.String(key),
207207
})
@@ -254,7 +254,7 @@ func (s *S3Backend) Delete(ctx context.Context, key string) error {
254254
// Setup key
255255
key = path.Join(s.path, key)
256256

257-
_, err := s.client.DeleteObject(&s3.DeleteObjectInput{
257+
_, err := s.client.DeleteObjectWithContext(ctx, &s3.DeleteObjectInput{
258258
Bucket: aws.String(s.bucket),
259259
Key: aws.String(key),
260260
})
@@ -289,7 +289,7 @@ func (s *S3Backend) List(ctx context.Context, prefix string) ([]string, error) {
289289

290290
keys := []string{}
291291

292-
err := s.client.ListObjectsV2Pages(params,
292+
err := s.client.ListObjectsV2PagesWithContext(ctx, params,
293293
func(page *s3.ListObjectsV2Output, lastPage bool) bool {
294294
if page != nil {
295295
// Add truncated 'folder' paths

0 commit comments

Comments
 (0)