Skip to content
This repository was archived by the owner on Dec 3, 2024. It is now read-only.

Fix handling of nil parameters in B and BA #29

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 10 additions & 2 deletions pkg/controller/bucket/bucket_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (bl *bucketListener) Add(ctx context.Context, obj *v1alpha1.Bucket) error {

req := osspec.ProvisionerCreateBucketRequest{
BucketName: obj.Name,
BucketContext: obj.Spec.Parameters,
BucketContext: bl.getParams(obj),
}

req.BucketContext["ProtocolVersion"] = obj.Spec.Protocol.Version
Expand Down Expand Up @@ -147,7 +147,7 @@ func (bl *bucketListener) Delete(ctx context.Context, obj *v1alpha1.Bucket) erro
}

req := osspec.ProvisionerDeleteBucketRequest{
BucketContext: obj.Spec.Parameters,
BucketContext: bl.getParams(obj),
}

switch obj.Spec.Protocol.Name {
Expand Down Expand Up @@ -198,3 +198,11 @@ func (bl *bucketListener) updateStatus(ctx context.Context, name, msg string, st
})
return err
}

func (bl *bucketListener) getParams(obj *v1alpha1.Bucket) map[string]string {
params := map[string]string{}
if obj.Spec.Parameters != nil {
params = obj.Spec.Parameters
}
return params
}
53 changes: 51 additions & 2 deletions pkg/controller/bucket/bucket_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,20 @@ func TestAddValidProtocols(t *testing.T) {
"AnonymousAccessMode": anonAccess,
},
},
{
name: "Empty parameters",
protocolName: v1alpha1.ProtocolNameS3,
createFunc: func(ctx context.Context, in *osspec.ProvisionerCreateBucketRequest, opts ...grpc.CallOption) (*osspec.ProvisionerCreateBucketResponse, error) {
if in.BucketName != bucketName {
t.Errorf("expected %s, got %s", bucketName, in.BucketName)
}
if in.BucketContext["ProtocolVersion"] != protocolVersion {
t.Errorf("expected %s, got %s", protocolVersion, in.BucketContext["ProtocolVersion"])
}
return &osspec.ProvisionerCreateBucketResponse{}, nil
},
params: nil,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -242,7 +256,7 @@ func TestAddValidProtocols(t *testing.T) {
kubeClient: kubeClient,
}

t.Logf("Testing protocol %s", tc.name)
t.Logf(tc.name)
err := bl.Add(ctx, &b)
if err != nil {
t.Errorf("add returned: %+v", err)
Expand Down Expand Up @@ -405,6 +419,41 @@ func TestDeleteValidProtocols(t *testing.T) {
extraParamName: extraParamValue,
},
},
{
name: "Empty parameters",
setProtocol: func(b *v1alpha1.Bucket) {
b.Spec.Protocol.S3 = &v1alpha1.S3Protocol{
Region: region,
Version: protocolVersion,
SignatureVersion: sigVersion,
BucketName: bucketName,
Endpoint: endpoint,
}
},
protocolName: v1alpha1.ProtocolNameS3,
deleteFunc: func(ctx context.Context, in *osspec.ProvisionerDeleteBucketRequest, opts ...grpc.CallOption) (*osspec.ProvisionerDeleteBucketResponse, error) {
if in.BucketName != bucketName {
t.Errorf("expected %s, got %s", bucketName, in.BucketName)
}
if in.BucketContext["Region"] != region {
t.Errorf("expected %s, got %s", region, in.BucketContext["Region"])
}
if in.BucketContext["ProtocolVersion"] != protocolVersion {
t.Errorf("expected %s, got %s", protocolVersion, in.BucketContext["ProtocolVersion"])
}
if in.BucketContext["SignatureVersion"] != string(sigVersion) {
t.Errorf("expected %s, got %s", sigVersion, in.BucketContext["SignatureVersion"])
}
if in.BucketContext["Endpoint"] != endpoint {
t.Errorf("expected %s, got %s", endpoint, in.BucketContext["Endpoint"])
}
if in.BucketContext["ProtocolVersion"] != protocolVersion {
t.Errorf("expected %s, got %s", protocolVersion, in.BucketContext["ProtocolVersion"])
}
return &osspec.ProvisionerDeleteBucketResponse{}, nil
},
params: nil,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -434,7 +483,7 @@ func TestDeleteValidProtocols(t *testing.T) {
}

tc.setProtocol(&b)
t.Logf("Testing protocol %s", tc.name)
t.Logf(tc.name)
err := bl.Delete(ctx, &b)
if err != nil {
t.Errorf("delete returned: %+v", err)
Expand Down
12 changes: 10 additions & 2 deletions pkg/controller/bucketaccess/bucket_access_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (bal *bucketAccessListener) Add(ctx context.Context, obj *v1alpha1.BucketAc
req := osspec.ProvisionerGrantBucketAccessRequest{
Principal: obj.Spec.Principal,
AccessPolicy: obj.Spec.PolicyActionsConfigMapData,
BucketContext: obj.Spec.Parameters,
BucketContext: bal.getParams(obj),
}

switch bucket.Spec.Protocol.Name {
Expand Down Expand Up @@ -206,7 +206,7 @@ func (bal *bucketAccessListener) Delete(ctx context.Context, obj *v1alpha1.Bucke

req := osspec.ProvisionerRevokeBucketAccessRequest{
Principal: obj.Spec.Principal,
BucketContext: obj.Spec.Parameters,
BucketContext: bal.getParams(obj),
}

switch bucket.Spec.Protocol.Name {
Expand Down Expand Up @@ -277,3 +277,11 @@ func (bal *bucketAccessListener) updatePrincipal(ctx context.Context, name strin
})
return err
}

func (bal *bucketAccessListener) getParams(obj *v1alpha1.BucketAccess) map[string]string {
params := map[string]string{}
if obj.Spec.Parameters != nil {
params = obj.Spec.Parameters
}
return params
}
79 changes: 79 additions & 0 deletions pkg/controller/bucketaccess/bucket_access_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,47 @@ func TestAdd(t *testing.T) {
extraParamName: extraParamValue,
},
},
{
name: "Empty parameters",
setProtocol: func(b *v1alpha1.Bucket) {
b.Spec.Protocol.S3 = &v1alpha1.S3Protocol{
Region: region,
Version: protocolVersion,
SignatureVersion: sigVersion,
BucketName: bucketName,
Endpoint: endpoint,
}
},
protocolName: v1alpha1.ProtocolNameS3,
grantFunc: func(ctx context.Context, in *osspec.ProvisionerGrantBucketAccessRequest, opts ...grpc.CallOption) (*osspec.ProvisionerGrantBucketAccessResponse, error) {
if in.BucketName != bucketName {
t.Errorf("expected %s, got %s", bucketName, in.BucketName)
}
if in.BucketContext["Region"] != region {
t.Errorf("expected %s, got %s", region, in.BucketContext["Region"])
}
if in.Principal != principal {
t.Errorf("expected %s, got %s", principal, in.Principal)
}
if in.BucketContext["Version"] != protocolVersion {
t.Errorf("expected %s, got %s", protocolVersion, in.BucketContext["Version"])
}
if in.BucketContext["SignatureVersion"] != string(sigVersion) {
t.Errorf("expected %s, got %s", sigVersion, in.BucketContext["SignatureVersion"])
}
if in.BucketContext["Endpoint"] != endpoint {
t.Errorf("expected %s, got %s", endpoint, in.BucketContext["Endpoint"])
}
return &osspec.ProvisionerGrantBucketAccessResponse{
Principal: principal,
CredentialsFileContents: credsContents,
CredentialsFilePath: credsFile,
}, nil
},
principal: principal,
serviceAccount: "",
params: nil,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -347,6 +388,7 @@ func TestAdd(t *testing.T) {
kubeClient: kubeClient,
}

t.Logf(tc.name)
err := bal.Add(ctx, &ba)
if err != nil {
t.Errorf("add returned: %+v", err)
Expand Down Expand Up @@ -576,6 +618,42 @@ func TestDelete(t *testing.T) {
extraParamName: extraParamValue,
},
},
{
name: "Empty parameters",
setProtocol: func(b *v1alpha1.Bucket) {
b.Spec.Protocol.S3 = &v1alpha1.S3Protocol{
Region: region,
Version: protocolVersion,
SignatureVersion: sigVersion,
BucketName: bucketName,
Endpoint: endpoint,
}
},
protocolName: v1alpha1.ProtocolNameS3,
revokeFunc: func(ctx context.Context, in *osspec.ProvisionerRevokeBucketAccessRequest, opts ...grpc.CallOption) (*osspec.ProvisionerRevokeBucketAccessResponse, error) {
if in.BucketName != bucketName {
t.Errorf("expected %s, got %s", bucketName, in.BucketName)
}
if in.BucketContext["Region"] != region {
t.Errorf("expected %s, got %s", region, in.BucketContext["Region"])
}
if in.Principal != principal {
t.Errorf("expected %s, got %s", principal, in.Principal)
}
if in.BucketContext["Version"] != protocolVersion {
t.Errorf("expected %s, got %s", protocolVersion, in.BucketContext["Version"])
}
if in.BucketContext["SignatureVersion"] != string(sigVersion) {
t.Errorf("expected %s, got %s", sigVersion, in.BucketContext["SignatureVersion"])
}
if in.BucketContext["Endpoint"] != endpoint {
t.Errorf("expected %s, got %s", endpoint, in.BucketContext["Endpoint"])
}
return &osspec.ProvisionerRevokeBucketAccessResponse{}, nil
},
serviceAccount: "",
params: nil,
},
}

for _, tc := range testCases {
Expand Down Expand Up @@ -619,6 +697,7 @@ func TestDelete(t *testing.T) {
Type: v1.SecretTypeOpaque,
}

t.Logf(tc.name)
ctx := context.TODO()
tc.setProtocol(&b)
client := fakebucketclientset.NewSimpleClientset(&ba, &b)
Expand Down