From 445de7926d877141824086e58a84eb25bbd279a0 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 11:49:45 +0100 Subject: [PATCH] cephfs: add validateCreateVolumeGroupSnapshotRequest added validateCreateVolumeGroupSnapshotRequest to validate the CreateVolumeGroupSnapshotRequest request and ensure that all the requirement options are set. if not, reject the RPC request. Signed-off-by: Madhu Rajanna --- internal/cephfs/groupcontrollerserver.go | 63 ++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 internal/cephfs/groupcontrollerserver.go diff --git a/internal/cephfs/groupcontrollerserver.go b/internal/cephfs/groupcontrollerserver.go new file mode 100644 index 000000000..6092f8a14 --- /dev/null +++ b/internal/cephfs/groupcontrollerserver.go @@ -0,0 +1,63 @@ +/* +Copyright 2024 The Ceph-CSI Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package cephfs + +import ( + "context" + + "github.com/ceph/ceph-csi/internal/util/log" + + "github.com/container-storage-interface/spec/lib/go/csi" + "github.com/kubernetes-csi/csi-lib-utils/protosanitizer" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// validateCreateVolumeGroupSnapshotRequest validates the request for creating +// a group snapshot of volumes. +func (cs *ControllerServer) validateCreateVolumeGroupSnapshotRequest( + ctx context.Context, + req *csi.CreateVolumeGroupSnapshotRequest, +) error { + if err := cs.Driver.ValidateGroupControllerServiceRequest( + csi.GroupControllerServiceCapability_RPC_CREATE_DELETE_GET_VOLUME_GROUP_SNAPSHOT); err != nil { + log.ErrorLog(ctx, "invalid create volume group snapshot req: %v", protosanitizer.StripSecrets(req)) + + return err + } + + // Check sanity of request volume group snapshot Name, Source Volume Id's + if req.GetName() == "" { + return status.Error(codes.InvalidArgument, "volume group snapshot Name cannot be empty") + } + + if len(req.GetSourceVolumeIds()) == 0 { + return status.Error(codes.InvalidArgument, "source volume ids cannot be empty") + } + + param := req.GetParameters() + // check for ClusterID and fsName + if value, ok := param["clusterID"]; !ok || value == "" { + return status.Error(codes.InvalidArgument, "missing or empty clusterID") + } + + if value, ok := param["fsName"]; !ok || value == "" { + return status.Error(codes.InvalidArgument, "missing or empty fsName") + } + + return nil +}