util: add ValidateGroupControllerServiceRequest helper

added ValidateGroupControllerServiceRequest
helper function which can be used to validate the
group controller service request.

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
This commit is contained in:
Madhu Rajanna 2024-02-05 09:49:04 +01:00 committed by mergify[bot]
parent 5ecfa0660f
commit 2af26ca62d

View File

@ -130,3 +130,21 @@ func (d *CSIDriver) AddGroupControllerServiceCapabilities(cl []csi.GroupControll
d.groupCapabilities = csc 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())
}