Skip to content

Commit

Permalink
chore(storage): enable several tests for grpc + related fixes (#6827)
Browse files Browse the repository at this point in the history
Enables tests: BucketPolicyOnly, ACL, PredefinedACLs

Fixes: gets all fields in GetBucket and GetObject (were missing ACLs); makes sure ACL is sent when ACL is not sent but PredefinedACL is; initializes Bucket_IamConfig (was causing segfault); sends UBLA field when disabled in an update

Additionally cleans up acl checking in tests to use the same method
  • Loading branch information
BrennaEpp committed Oct 12, 2022
1 parent 84e1508 commit c65fd1b
Show file tree
Hide file tree
Showing 3 changed files with 291 additions and 255 deletions.
35 changes: 21 additions & 14 deletions storage/bucket.go
Expand Up @@ -907,23 +907,30 @@ func (ua *BucketAttrsToUpdate) toProtoBucket() *storagepb.Bucket {
if ua.RequesterPays != nil {
bb = &storagepb.Bucket_Billing{RequesterPays: optional.ToBool(ua.RequesterPays)}
}

var bktIAM *storagepb.Bucket_IamConfig
var ublaEnabled bool
var bktPolicyOnlyEnabled bool
if ua.UniformBucketLevelAccess != nil {
ublaEnabled = optional.ToBool(ua.UniformBucketLevelAccess.Enabled)
}
if ua.BucketPolicyOnly != nil {
bktPolicyOnlyEnabled = optional.ToBool(ua.BucketPolicyOnly.Enabled)
}
if ublaEnabled || bktPolicyOnlyEnabled {
bktIAM.UniformBucketLevelAccess = &storagepb.Bucket_IamConfig_UniformBucketLevelAccess{
Enabled: true,
if ua.UniformBucketLevelAccess != nil || ua.BucketPolicyOnly != nil || ua.PublicAccessPrevention != PublicAccessPreventionUnknown {
bktIAM = &storagepb.Bucket_IamConfig{}

if ua.BucketPolicyOnly != nil {
bktIAM.UniformBucketLevelAccess = &storagepb.Bucket_IamConfig_UniformBucketLevelAccess{
Enabled: optional.ToBool(ua.BucketPolicyOnly.Enabled),
}
}

if ua.UniformBucketLevelAccess != nil {
// UniformBucketLevelAccess takes precedence over BucketPolicyOnly,
// so Enabled will be overriden here if both are set
bktIAM.UniformBucketLevelAccess = &storagepb.Bucket_IamConfig_UniformBucketLevelAccess{
Enabled: optional.ToBool(ua.UniformBucketLevelAccess.Enabled),
}
}

if ua.PublicAccessPrevention != PublicAccessPreventionUnknown {
bktIAM.PublicAccessPrevention = ua.PublicAccessPrevention.String()
}
}
if ua.PublicAccessPrevention != PublicAccessPreventionUnknown {
bktIAM.PublicAccessPrevention = ua.PublicAccessPrevention.String()
}

var defaultHold bool
if ua.DefaultEventBasedHold != nil {
defaultHold = optional.ToBool(ua.DefaultEventBasedHold)
Expand Down
10 changes: 4 additions & 6 deletions storage/grpc_client.go
Expand Up @@ -246,7 +246,8 @@ func (c *grpcStorageClient) DeleteBucket(ctx context.Context, bucket string, con
func (c *grpcStorageClient) GetBucket(ctx context.Context, bucket string, conds *BucketConditions, opts ...storageOption) (*BucketAttrs, error) {
s := callSettings(c.settings, opts...)
req := &storagepb.GetBucketRequest{
Name: bucketResourceName(globalProjectAlias, bucket),
Name: bucketResourceName(globalProjectAlias, bucket),
ReadMask: &fieldmaskpb.FieldMask{Paths: []string{"*"}},
}
if err := applyBucketCondsProto("grpcStorageClient.GetBucket", conds, req); err != nil {
return nil, err
Expand Down Expand Up @@ -500,10 +501,7 @@ func (c *grpcStorageClient) UpdateObject(ctx context.Context, bucket, object str
req.CommonObjectRequestParams = toProtoCommonObjectRequestParams(encryptionKey)
}

var paths []string
fieldMask := &fieldmaskpb.FieldMask{
Paths: paths,
}
fieldMask := &fieldmaskpb.FieldMask{Paths: nil}
if uattrs.EventBasedHold != nil {
fieldMask.Paths = append(fieldMask.Paths, "event_based_hold")
}
Expand All @@ -530,7 +528,7 @@ func (c *grpcStorageClient) UpdateObject(ctx context.Context, bucket, object str
}
// Note: This API currently does not support entites using project ID.
// Use project numbers in ACL entities. Pending b/233617896.
if uattrs.ACL != nil {
if uattrs.ACL != nil || len(uattrs.PredefinedACL) > 0 {
fieldMask.Paths = append(fieldMask.Paths, "acl")
}
// TODO(cathyo): Handle metadata. Pending b/230510191.
Expand Down

0 comments on commit c65fd1b

Please sign in to comment.