Skip to content

Commit

Permalink
chore(storage): implement gRPC ListObjects read_mask support (#6808)
Browse files Browse the repository at this point in the history
This adds `Query`-to-`FieldMask` conversion for `Object` attributes and incorporates that into `ListObjects` for gRPC.

This also carves out the `ListObjects`-specific tests from `TestIntegration_Objects` and enables those tests for multi-transport testing.
  • Loading branch information
noahdietz committed Oct 11, 2022
1 parent afbc2dd commit 1d0116a
Show file tree
Hide file tree
Showing 4 changed files with 559 additions and 414 deletions.
24 changes: 16 additions & 8 deletions storage/grpc_client.go
Expand Up @@ -380,14 +380,14 @@ func (c *grpcStorageClient) ListObjects(ctx context.Context, bucket string, q *Q
it.query = *q
}
req := &storagepb.ListObjectsRequest{
Parent: bucketResourceName(globalProjectAlias, bucket),
Prefix: it.query.Prefix,
Delimiter: it.query.Delimiter,
Versions: it.query.Versions,
LexicographicStart: it.query.StartOffset,
LexicographicEnd: it.query.EndOffset,
// TODO(noahietz): Convert a projection to a FieldMask.
// ReadMask: q.Projection,
Parent: bucketResourceName(globalProjectAlias, bucket),
Prefix: it.query.Prefix,
Delimiter: it.query.Delimiter,
Versions: it.query.Versions,
LexicographicStart: it.query.StartOffset,
LexicographicEnd: it.query.EndOffset,
IncludeTrailingDelimiter: it.query.IncludeTrailingDelimiter,
ReadMask: q.toFieldMask(), // a nil Query still results in a "*" FieldMask
}
if s.userProject != "" {
ctx = setUserProjectMetadata(ctx, s.userProject)
Expand All @@ -411,6 +411,12 @@ func (c *grpcStorageClient) ListObjects(ctx context.Context, bucket string, q *Q
it.items = append(it.items, b)
}

// Response is always non-nil after a successful request.
res := gitr.Response.(*storagepb.ListObjectsResponse)
for _, prefix := range res.GetPrefixes() {
it.items = append(it.items, &ObjectAttrs{Prefix: prefix})
}

return token, nil
}
it.pageInfo, it.nextFunc = iterator.NewPageInfo(
Expand Down Expand Up @@ -449,6 +455,8 @@ func (c *grpcStorageClient) GetObject(ctx context.Context, bucket, object string
req := &storagepb.GetObjectRequest{
Bucket: bucketResourceName(globalProjectAlias, bucket),
Object: object,
// ProjectionFull by default.
ReadMask: &fieldmaskpb.FieldMask{Paths: []string{"*"}},
}
if err := applyCondsProto("grpcStorageClient.GetObject", gen, conds, req); err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions storage/http_client.go
Expand Up @@ -344,8 +344,8 @@ func (c *httpStorageClient) ListObjects(ctx context.Context, bucket string, q *Q
req.EndOffset(it.query.EndOffset)
req.Versions(it.query.Versions)
req.IncludeTrailingDelimiter(it.query.IncludeTrailingDelimiter)
if len(it.query.fieldSelection) > 0 {
req.Fields("nextPageToken", googleapi.Field(it.query.fieldSelection))
if selection := it.query.toFieldSelection(); selection != "" {
req.Fields("nextPageToken", googleapi.Field(selection))
}
req.PageToken(pageToken)
if s.userProject != "" {
Expand Down

0 comments on commit 1d0116a

Please sign in to comment.