Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
suggestions
  • Loading branch information
BrennaEpp committed Mar 15, 2024
commit e0ac127b2fe4595a6c633e2396908a2db1d4e20e
12 changes: 1 addition & 11 deletions storage/bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type BucketHandle struct {
userProject string // project for Requester Pays buckets
retry *retryConfig
enableObjectRetention *bool
softDeleted bool
}

// Bucket returns a BucketHandle, which provides operations on the named bucket.
Expand Down Expand Up @@ -141,7 +140,6 @@ func (b *BucketHandle) Object(name string) *ObjectHandle {
gen: -1,
userProject: b.userProject,
retry: retry,
softDeleted: b.softDeleted,
}
}

Expand Down Expand Up @@ -2145,15 +2143,7 @@ func toSoftDeletePolicyFromProto(p *storagepb.Bucket_SoftDeletePolicy) *SoftDele
// Note: The returned iterator is not safe for concurrent operations without explicit synchronization.
func (b *BucketHandle) Objects(ctx context.Context, q *Query) *ObjectIterator {
o := makeStorageOpts(true, b.retry, b.userProject)
return b.c.tc.ListObjects(ctx, b.name, q, b.softDeleted, o...)
}

// SoftDeleted returns a new BucketHandle with the option to include
// soft-deleted items in list results.
func (b *BucketHandle) SoftDeleted(include bool) *BucketHandle {
b2 := *b
b2.softDeleted = include
return &b2
return b.c.tc.ListObjects(ctx, b.name, q, o...)
}

// Retryer returns a bucket handle that is configured with custom retry
Expand Down
12 changes: 6 additions & 6 deletions storage/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type storageClient interface {
GetBucket(ctx context.Context, bucket string, conds *BucketConditions, opts ...storageOption) (*BucketAttrs, error)
UpdateBucket(ctx context.Context, bucket string, uattrs *BucketAttrsToUpdate, conds *BucketConditions, opts ...storageOption) (*BucketAttrs, error)
LockBucketRetentionPolicy(ctx context.Context, bucket string, conds *BucketConditions, opts ...storageOption) error
ListObjects(ctx context.Context, bucket string, q *Query, softDeleted bool, opts ...storageOption) *ObjectIterator
ListObjects(ctx context.Context, bucket string, q *Query, opts ...storageOption) *ObjectIterator

// Object metadata methods.

Expand Down Expand Up @@ -296,11 +296,11 @@ type newRangeReaderParams struct {
}

type getObjectParams struct {
bucket, object string
gen int64
encryptionKey []byte
conds *Conditions
getOnlyIfSoftDeleted bool
bucket, object string
gen int64
encryptionKey []byte
conds *Conditions
softDeleted bool
}

type updateObjectParams struct {
Expand Down
4 changes: 2 additions & 2 deletions storage/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func TestListObjectsEmulated(t *testing.T) {
}

// Simple list, no query.
it := client.ListObjects(context.Background(), bucket, nil, false)
it := client.ListObjects(context.Background(), bucket, nil)
var o *ObjectAttrs
var got int
for i := 0; err == nil && i <= len(want); i++ {
Expand Down Expand Up @@ -483,7 +483,7 @@ func TestListObjectsWithPrefixEmulated(t *testing.T) {
}

// Query with Prefix.
it := client.ListObjects(context.Background(), bucket, &Query{Prefix: strconv.Itoa(prefix)}, false)
it := client.ListObjects(context.Background(), bucket, &Query{Prefix: strconv.Itoa(prefix)})
var o *ObjectAttrs
var got int
want = want[:2]
Expand Down
8 changes: 4 additions & 4 deletions storage/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func (c *grpcStorageClient) LockBucketRetentionPolicy(ctx context.Context, bucke
}, s.retry, s.idempotent)

}
func (c *grpcStorageClient) ListObjects(ctx context.Context, bucket string, q *Query, softDeleted bool, opts ...storageOption) *ObjectIterator {
func (c *grpcStorageClient) ListObjects(ctx context.Context, bucket string, q *Query, opts ...storageOption) *ObjectIterator {
s := callSettings(c.settings, opts...)
it := &ObjectIterator{
ctx: ctx,
Expand All @@ -418,7 +418,7 @@ func (c *grpcStorageClient) ListObjects(ctx context.Context, bucket string, q *Q
IncludeTrailingDelimiter: it.query.IncludeTrailingDelimiter,
MatchGlob: it.query.MatchGlob,
ReadMask: q.toFieldMask(), // a nil Query still results in a "*" FieldMask
SoftDeleted: softDeleted,
SoftDeleted: it.query.SoftDeleted,
}
if s.userProject != "" {
ctx = setUserProjectMetadata(ctx, s.userProject)
Expand Down Expand Up @@ -505,8 +505,8 @@ func (c *grpcStorageClient) GetObject(ctx context.Context, params *getObjectPara
if params.encryptionKey != nil {
req.CommonObjectRequestParams = toProtoCommonObjectRequestParams(params.encryptionKey)
}
if params.getOnlyIfSoftDeleted {
req.SoftDeleted = &params.getOnlyIfSoftDeleted
if params.softDeleted {
req.SoftDeleted = &params.softDeleted
}

var attrs *ObjectAttrs
Expand Down
10 changes: 5 additions & 5 deletions storage/http_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ func (c *httpStorageClient) LockBucketRetentionPolicy(ctx context.Context, bucke
return err
}, s.retry, s.idempotent)
}
func (c *httpStorageClient) ListObjects(ctx context.Context, bucket string, q *Query, softDeleted bool, opts ...storageOption) *ObjectIterator {
func (c *httpStorageClient) ListObjects(ctx context.Context, bucket string, q *Query, opts ...storageOption) *ObjectIterator {
s := callSettings(c.settings, opts...)
it := &ObjectIterator{
ctx: ctx,
Expand All @@ -336,8 +336,8 @@ func (c *httpStorageClient) ListObjects(ctx context.Context, bucket string, q *Q
}
fetch := func(pageSize int, pageToken string) (string, error) {
req := c.raw.Objects.List(bucket)
if softDeleted {
req.SoftDeleted(softDeleted)
if it.query.SoftDeleted {
req.SoftDeleted(it.query.SoftDeleted)
}
setClientHeader(req.Header())
projection := it.query.Projection
Expand Down Expand Up @@ -423,8 +423,8 @@ func (c *httpStorageClient) GetObject(ctx context.Context, params *getObjectPara
if err := setEncryptionHeaders(req.Header(), params.encryptionKey, false); err != nil {
return nil, err
}
if params.getOnlyIfSoftDeleted {
req.SoftDeleted(params.getOnlyIfSoftDeleted)
if params.softDeleted {
req.SoftDeleted(params.softDeleted)
}

var obj *raw.Object
Expand Down
12 changes: 1 addition & 11 deletions storage/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4277,7 +4277,7 @@ func TestIntegration_SoftDelete(t *testing.T) {

var gen int64
// List soft deleted objects.
it := b.SoftDeleted(true).Objects(ctx, nil)
it := b.Objects(ctx, &Query{SoftDeleted: true})
var gotNames []string
for {
attrs, err := it.Next()
Expand Down Expand Up @@ -4325,15 +4325,6 @@ func TestIntegration_SoftDelete(t *testing.T) {
t.Fatalf("HardDeleteTime of soft deleted object should be equal to SoftDeleteTime+RetentionDuration, got: %v, expected: %v", got, expected)
}

// Get soft deleted object with SoftDeleted set on the bucket handle.
oAttrs, err = b.SoftDeleted(true).Object(deletedObject.ObjectName()).Generation(gen).Attrs(ctx)
if err != nil {
t.Fatalf("b.SoftDeleted(true).Object(deletedObject).Attrs: %v", err)
}
if oAttrs.SoftDeleteTime.Before(testStart) {
t.Fatalf("SoftDeleteTime of soft deleted object should not be in the past, got: %v, test start: %v", oAttrs.SoftDeleteTime, testStart.UTC())
}

// Restore a soft deleted object.
_, err = deletedObject.Generation(gen).Restore(ctx, true)
if err != nil {
Expand All @@ -4349,7 +4340,6 @@ func TestIntegration_SoftDelete(t *testing.T) {
if got, expect := attrs.SoftDeletePolicy.RetentionDuration, time.Duration(0); got != expect {
t.Fatalf("mismatching retention duration; got: %+v, expected: %+v", got, expect)
}

})
}

Expand Down
12 changes: 9 additions & 3 deletions storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -1068,7 +1068,7 @@ func (o *ObjectHandle) SoftDeleted() *ObjectHandle {
return &o2
}

// Restore will restore a soft-deleted object to full object status.
// Restore will restore a soft-deleted object to a live object.
// Note that you must specify a generation to use this method.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really should have samples for this feature; people are going to be so confused otherwise.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If generation is not specified, do we get an intelligible error from the server based on whatever the Go client sends by default? Might be good to check this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error should be intelligible, let me check...

GRPC
rpc error: code = InvalidArgument desc = You must specify a generation. error details: name = BadRequest field = desc = You must specify a generation.

Ah, HTTP's is no longer intelligible since it's a required param googleapi: Error 400: Invalid argument., invalid

What do you suggest we do here? Set if o.gen < 0 { gen = 0 } to get the intelligible error? Sending generation=0 results in googleapi: Error 400: Restore request must specify a generation., required

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sending zero seems fine since the default of -1 seems to be a placeholder for the most recent generation. Or we could just return an error without sending the request since a required param is missing. @JesseLovelace what are other languages doing for this case, assuming that it is relevant?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think sending zero to get the intelligible error seems best here

// copySourceACL indicates whether the restored object should copy the
// access controls of the source object.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this only relevant for buckets with fine-grained access? If UBLA is enabled, is this ignored or does it cause an error?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the target bucket has UBLA enforced, the user will get an error warning that object ACLs will not be restored and the object will not be restored.

Expand Down Expand Up @@ -1421,14 +1421,16 @@ type ObjectAttrs struct {

// SoftDeleteTime is the time when the object became soft-deleted.
// Soft-deleted objects are only accessible on an object handle returned by
Comment thread
tritone marked this conversation as resolved.
Resolved
// ObjectHandle.SoftDeleted.
// ObjectHandle.SoftDeleted; if ObjectHandle.SoftDeleted has not been set,
// ObjectHandle.Attrs will return ErrObjectNotExist if the object is soft-deleted.
// This field is read-only.
SoftDeleteTime time.Time

// HardDeleteTime is the time when the object will be permanently deleted.
// Only set when an object becomes soft-deleted with a soft delete policy.
// Soft-deleted objects are only accessible on an object handle returned by
// ObjectHandle.SoftDeleted.
// ObjectHandle.SoftDeleted; if ObjectHandle.SoftDeleted has not been set,
// ObjectHandle.Attrs will return ErrObjectNotExist if the object is soft-deleted.
// This field is read-only.
HardDeleteTime time.Time
}
Expand Down Expand Up @@ -1682,6 +1684,10 @@ type Query struct {
// prefixes returned by the query. Only applicable if Delimiter is set to /.
// IncludeFoldersAsPrefixes is not yet implemented in the gRPC API.
IncludeFoldersAsPrefixes bool

// SoftDeleted indicates whether to list soft-deleted objects. If true, only
// objects that have been soft-deleted will be listed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note as well that by default, soft deleted objects will not be listed.

SoftDeleted bool
}

// attrToFieldMap maps the field names of ObjectAttrs to the underlying field
Expand Down
⌂ 换网址