From a86be4527e5534654a092f9834ab8afcbb377d09 Mon Sep 17 00:00:00 2001 From: Madhu Rajanna Date: Mon, 5 Feb 2024 09:49:04 +0100 Subject: [PATCH] util: add ValidateGroupControllerServiceRequest helper added ValidateGroupControllerServiceRequest helper function which can be used to validate the group controller service request. Signed-off-by: Madhu Rajanna --- internal/csi-common/driver.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/csi-common/driver.go b/internal/csi-common/driver.go index 87120ee64657..4062845b4cb0 100644 --- a/internal/csi-common/driver.go +++ b/internal/csi-common/driver.go @@ -130,3 +130,21 @@ func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControll d.groupCapabilities = csc } + +// ValidateGroupControllerServiceRequest validates the group controller +// plugin capabilities. +// +//nolint:interfacer // c can be of type fmt.Stringer, but that does not make the API clearer +func (d *CSIDriver) ValidateGroupControllerServiceRequest(c csi.GroupControllerServiceCapability_RPC_Type) error { + if c == csi.GroupControllerServiceCapability_RPC_UNKNOWN { + return nil + } + + for _, capability := range d.groupCapabilities { + if c == capability.GetRpc().GetType() { + return nil + } + } + + return status.Error(codes.InvalidArgument, c.String()) +}