diff --git a/.github/workflows/linters.yaml b/.github/workflows/linters.yaml index 6e8a6ca..9b2eafd 100644 --- a/.github/workflows/linters.yaml +++ b/.github/workflows/linters.yaml @@ -28,3 +28,4 @@ jobs: with: version: latest skip-cache: true + args: --out-format=colored-line-number diff --git a/dell-csi-helm-installer/csi-offline-bundle.sh b/dell-csi-helm-installer/csi-offline-bundle.sh index 55e2c9a..5203b97 100755 --- a/dell-csi-helm-installer/csi-offline-bundle.sh +++ b/dell-csi-helm-installer/csi-offline-bundle.sh @@ -63,6 +63,7 @@ run_command() { # build_image_manifest # builds a manifest of all the images referred to by the helm chart build_image_manifest() { + local REGEX_COMMENTS="(#.*)" local REGEX="([-_./:A-Za-z0-9]{3,}):([-_.A-Za-z0-9]{1,})" status "Building image manifest file" @@ -82,7 +83,7 @@ build_image_manifest() { # - search all files in a diectory looking for strings that make $REGEX # - exclude anything with double '//'' as that is a URL and not an image name # - make sure at least one '/' is found - find "${D}" -type f -exec egrep -oh "${REGEX}" {} \; | egrep -v '//' | egrep '/' >> "${IMAGEMANIFEST}.tmp" + find "${D}" -type f -exec egrep -v "${REGEX_COMMENTS}" {} \; | egrep -oh "${REGEX}"| egrep -v '//' | egrep '/' >> "${IMAGEMANIFEST}.tmp" fi done diff --git a/service/controller.go b/service/controller.go index c5bc3a5..ff064e7 100644 --- a/service/controller.go +++ b/service/controller.go @@ -168,7 +168,7 @@ func (s *service) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest nasServer, ok := params[keyNasServer] if !ok { - return nil, status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "`%s` is a required parameter", keyNasServer)) + return nil, status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "`%s` is a required parameter", keyNasServer)) } // Add AdditionalFilesystemSize in size as Unity XT use this much size for metadata in filesystem @@ -193,7 +193,7 @@ func (s *service) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest filesystem, _ := fileAPI.FindFilesystemByName(ctx, volName) if filesystem != nil { content := filesystem.FileContent - if int64(content.SizeTotal) == size && content.NASServer.ID == nasServer && content.Pool.ID == storagePool { + if int64(content.SizeTotal) /* #nosec G115 -- This is a false positive */ == size && content.NASServer.ID == nasServer && content.Pool.ID == storagePool { log.Info("Filesystem exists in the requested state with same size, NAS server and storage pool") filesystem.FileContent.SizeTotal -= AdditionalFilesystemSize return utils.GetVolumeResponseFromFilesystem(filesystem, arrayID, protocol, preferredAccessibility), nil @@ -252,7 +252,7 @@ func (s *service) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest vol, _ := volumeAPI.FindVolumeByName(ctx, volName) if vol != nil { content := vol.VolumeContent - if int64(content.SizeTotal) == size { + if int64(content.SizeTotal) /* #nosec G115 -- This is a false positive */ == size { log.Info("Volume exists in the requested state with same size") return utils.GetVolumeResponseFromVolume(vol, arrayID, protocol, preferredAccessibility), nil } @@ -666,7 +666,7 @@ func (s *service) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsReque // Process the source snapshots and make CSI Snapshot entries, err := s.getCSISnapshots(snaps, req.SourceVolumeId, protocol, arrayID) if err != nil { - return nil, status.Error(codes.Unknown, utils.GetMessageWithRunID(rid, err.Error())) + return nil, status.Error(codes.Unknown, utils.GetMessageWithRunID(rid, "%s", err.Error())) } log.Debugf("ListSnapshot successful for snapid: [%s]", req.SnapshotId) return &csi.ListSnapshotsResponse{ @@ -846,7 +846,7 @@ func (s *service) ControllerExpandVolume(ctx context.Context, req *csi.Controlle if err != nil { return nil, status.Error(codes.NotFound, utils.GetMessageWithRunID(rid, "Find filesystem failed with error: %v", err)) } - expandVolumeResp.CapacityBytes = int64(filesystem.FileContent.SizeTotal) - AdditionalFilesystemSize + expandVolumeResp.CapacityBytes = int64(filesystem.FileContent.SizeTotal) /* #nosec G115 -- This is a false positive */ - AdditionalFilesystemSize expandVolumeResp.NodeExpansionRequired = false return expandVolumeResp, err } @@ -878,7 +878,7 @@ func (s *service) ControllerExpandVolume(ctx context.Context, req *csi.Controlle if err != nil { return nil, status.Error(codes.NotFound, utils.GetMessageWithRunID(rid, "Find volume failed with error: %v", err)) } - expandVolumeResp.CapacityBytes = int64(volume.VolumeContent.SizeTotal) + expandVolumeResp.CapacityBytes = int64(volume.VolumeContent.SizeTotal) /* #nosec G115 -- This is a false positive */ expandVolumeResp.NodeExpansionRequired = nodeExpansionRequired return expandVolumeResp, err } @@ -896,7 +896,7 @@ func (s *service) getCSIVolumes(volumes []types.Volume) ([]*csi.ListVolumesRespo // Create CSI volume vi := &csi.Volume{ VolumeId: vol.VolumeContent.ResourceID, - CapacityBytes: int64(vol.VolumeContent.SizeTotal), + CapacityBytes: int64(vol.VolumeContent.SizeTotal), /* #nosec G115 -- This is a false positive */ VolumeContext: attributes, } @@ -1152,7 +1152,7 @@ func (s *service) createVolumeClone(ctx context.Context, crParams *CRParams, sou // Validate the size parameter snapSize := int64(snapResp.SnapshotContent.Size - AdditionalFilesystemSize) if snapSize != size { - return nil, status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Requested size %d should be same as source filesystem size %d", size, snapSize)) + return nil, status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Requested size %d should be same as source filesystem size %d", size, snapSize)) } // Idempotency check snapResp, err := snapAPI.FindSnapshotByName(ctx, volName) @@ -1170,9 +1170,9 @@ func (s *service) createVolumeClone(ctx context.Context, crParams *CRParams, sou csiVolResp.Volume.ContentSource = contentSource return csiVolResp, nil } - fsSize := int64(filesystem.FileContent.SizeTotal - AdditionalFilesystemSize) + fsSize := int64(filesystem.FileContent.SizeTotal - AdditionalFilesystemSize) /* #nosec G115 -- This is a false positive */ if size != fsSize { - return nil, status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Requested size %d should be same as source volume size %d", + return nil, status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Requested size %d should be same as source volume size %d", size, fsSize)) } @@ -1274,7 +1274,7 @@ func (s *service) createVolumeFromSnap(ctx context.Context, crParams *CRParams, // Validate the size parameter snapSize := int64(snapResp.SnapshotContent.Size - AdditionalFilesystemSize) if snapSize != size { - return nil, status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Requested size %d should be same as source snapshot size %d", size, snapSize)) + return nil, status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Requested size %d should be same as source snapshot size %d", size, snapSize)) } snapResp, err := snapAPI.FindSnapshotByName(ctx, volName) @@ -1320,7 +1320,7 @@ func (s *service) createVolumeFromSnap(ctx context.Context, crParams *CRParams, // Validate the size parameter if snapResp.SnapshotContent.Size != size { - return nil, status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Requested size %d should be same as source snapshot size %d", size, snapResp.SnapshotContent.Size)) + return nil, status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Requested size %d should be same as source snapshot size %d", size, snapResp.SnapshotContent.Size)) } volResp, _ := volumeAPI.FindVolumeByName(ctx, volName) diff --git a/service/csi_extension_server.go b/service/csi_extension_server.go index da1011d..4a22648 100644 --- a/service/csi_extension_server.go +++ b/service/csi_extension_server.go @@ -287,7 +287,7 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no } else { message = fmt.Sprintf("Host lookup failed. Error: %v", err) } - log.Infof(message) + log.Infof("%s", message) rep.Messages = append(rep.Messages, message) rep.Connected = false return nil @@ -307,7 +307,7 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no healthContent := hostInitiator.HostInitiatorContent.Health if healthContent.DescriptionIDs[0] == componentOkMessage { message = fmt.Sprintf("FC Health is good for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) - log.Infof(message) + log.Infof("%s", message) rep.Messages = append(rep.Messages, message) rep.Connected = true fcConnectivity = true @@ -332,7 +332,7 @@ func (s *service) checkIfNodeIsConnected(ctx context.Context, arrayID string, no healthContent := hostInitiator.HostInitiatorContent.Health if healthContent.DescriptionIDs[0] == componentOkMessage { message = fmt.Sprintf("iSCSI Health is good for array:%s, Health:%s", arrayID, healthContent.DescriptionIDs[0]) - log.Infof(message) + log.Infof("%s", message) rep.Messages = append(rep.Messages, message) rep.Connected = true break diff --git a/service/node.go b/service/node.go index 7c7ce49..3c2e405 100644 --- a/service/node.go +++ b/service/node.go @@ -17,7 +17,6 @@ package service import ( "context" "errors" - "fmt" "io" "os" "path" @@ -322,12 +321,12 @@ func (s *service) NodeUnstageVolume( // Get the device mounts dev, err := GetDevice(ctx, devicePath) if err != nil { - return nil, status.Error(codes.Internal, utils.GetMessageWithRunID(rid, err.Error())) + return nil, status.Error(codes.Internal, utils.GetMessageWithRunID(rid, "%s", err.Error())) } log.Debug("Rechecking dev mounts") mnts, err := getDevMounts(ctx, dev) if err != nil { - return nil, status.Error(codes.Internal, utils.GetMessageWithRunID(rid, err.Error())) + return nil, status.Error(codes.Internal, utils.GetMessageWithRunID(rid, "%s", err.Error())) } if len(mnts) > 0 { return nil, status.Error(codes.Internal, utils.GetMessageWithRunID(rid, "Device mounts still present after unmounting target and staging mounts %#v", mnts)) @@ -1205,7 +1204,7 @@ func (s *service) checkVolumeMapping(ctx context.Context, volume *types.Volume, hostcontent := hostaccess.HostContent hostAccessID := hostcontent.ID if hostAccessID == hostID { - log.Debugf(fmt.Sprintf("Volume %s has been published to the current node %s.", volName, host.HostContent.Name)) + log.Debugf("Volume %s has been published to the current node %s.", volName, host.HostContent.Name) return hostaccess.HLU, nil } } @@ -1482,7 +1481,7 @@ func (s *service) disconnectVolume(ctx context.Context, volumeWWN, protocol stri log.Debugf("Disconnect succesful for colume wwn %s", volumeWWN) return nil } - return status.Errorf(codes.Internal, utils.GetMessageWithRunID(rid, "disconnectVolume exceeded retry limit WWN %s devPath %s", volumeWWN, devPath)) + return status.Errorf(codes.Internal, "%s", utils.GetMessageWithRunID(rid, "disconnectVolume exceeded retry limit WWN %s devPath %s", volumeWWN, devPath)) } type publishContextData struct { diff --git a/service/utils/emcutils.go b/service/utils/emcutils.go index aee5328..861cead 100644 --- a/service/utils/emcutils.go +++ b/service/utils/emcutils.go @@ -75,7 +75,7 @@ func getVolumeResponse(name, protocol, arrayID, resourceID string, size uint64, volumeReq := &csi.Volume{ VolumeId: volID, - CapacityBytes: int64(size), + CapacityBytes: int64(size), /* #nosec G115 -- This is a false positive */ VolumeContext: VolumeContext, AccessibleTopology: preferredAccessibility, } diff --git a/service/validator.go b/service/validator.go index 5eda773..cc52339 100644 --- a/service/validator.go +++ b/service/validator.go @@ -139,31 +139,31 @@ func validateCreateFsFromSnapshot(ctx context.Context, sourceFilesystemResp *typ // Validate the storagePool parameter if sourceFilesystemResp.FileContent.Pool.ID != storagePool { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source filesystem storage pool %s is different than the requested storage pool %s", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source filesystem storage pool %s is different than the requested storage pool %s", sourceFilesystemResp.FileContent.Pool.ID, storagePool)) } // Validate the thinProvisioned parameter if sourceFilesystemResp.FileContent.IsThinEnabled != thin { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source filesystem thin provision %v is different than the requested thin provision %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source filesystem thin provision %v is different than the requested thin provision %v", sourceFilesystemResp.FileContent.IsThinEnabled, thin)) } // Validate the dataReduction parameter if sourceFilesystemResp.FileContent.IsDataReductionEnabled != dataReduction { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source filesystem data reduction %v is different than the requested data reduction %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source filesystem data reduction %v is different than the requested data reduction %v", sourceFilesystemResp.FileContent.IsDataReductionEnabled, dataReduction)) } // Validate the tieringPolicy parameter - if int64(sourceFilesystemResp.FileContent.TieringPolicy) != tieringPolicy { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source filesystem tiering policy %v is different than the requested tiering policy %v", + if int64(sourceFilesystemResp.FileContent.TieringPolicy) /* #nosec G115 -- This is a false positive */ != tieringPolicy { + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source filesystem tiering policy %v is different than the requested tiering policy %v", sourceFilesystemResp.FileContent.TieringPolicy, tieringPolicy)) } // Validate the hostIOSize parameter if sourceFilesystemResp.FileContent.HostIOSize != hostIoSize { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source filesystem host IO size %v is different than the requested host IO size %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source filesystem host IO size %v is different than the requested host IO size %v", sourceFilesystemResp.FileContent.HostIOSize, hostIoSize)) } @@ -176,22 +176,22 @@ func validateCreateVolumeFromSource(ctx context.Context, sourceVolResp *types.Vo // Validate the storagePool parameter if sourceVolResp.VolumeContent.Pool.ID != storagePool { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source volume storage pool %s is different than the requested storage pool %s", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source volume storage pool %s is different than the requested storage pool %s", sourceVolResp.VolumeContent.Pool.ID, storagePool)) } // Validate the tieringPolicy parameter if int64(sourceVolResp.VolumeContent.TieringPolicy) != tieringPolicy { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source volume tiering policy %v is different than the requested tiering policy %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source volume tiering policy %v is different than the requested tiering policy %v", sourceVolResp.VolumeContent.TieringPolicy, tieringPolicy)) } // Validate the thinProvisioned parameter if sourceVolResp.VolumeContent.IsThinEnabled != thin { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source volume thin provision %v is different than the requested thin provision %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source volume thin provision %v is different than the requested thin provision %v", sourceVolResp.VolumeContent.IsThinEnabled, thin)) } // Validate the dataReduction parameter if sourceVolResp.VolumeContent.IsDataReductionEnabled != dataReduction { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Source volume data reduction %v is different than the requested data reduction %v", + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Source volume data reduction %v is different than the requested data reduction %v", sourceVolResp.VolumeContent.IsDataReductionEnabled, dataReduction)) } @@ -200,9 +200,9 @@ func validateCreateVolumeFromSource(ctx context.Context, sourceVolResp *types.Vo } // Validate the size parameter - if int64(sourceVolResp.VolumeContent.SizeTotal) != size { - return status.Errorf(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Requested size %d should be same as source volume size %d", - size, int64(sourceVolResp.VolumeContent.SizeTotal))) + if int64(sourceVolResp.VolumeContent.SizeTotal) /* #nosec G115 -- This is a false positive */ != size { + return status.Errorf(codes.InvalidArgument, "%s", utils.GetMessageWithRunID(rid, "Requested size %d should be same as source volume size %d", + size, int64(sourceVolResp.VolumeContent.SizeTotal))) /* #nosec G115 -- This is a false positive */ } return nil @@ -281,12 +281,12 @@ func ValidateCreateVolumeRequest(ctx context.Context, req *csi.CreateVolumeReque // Validate volume capabilities vcs := req.GetVolumeCapabilities() if len(vcs) == 0 { - return "", "", 0, 0, 0, false, false, status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Controller Volume Capability are not provided")) + return "", "", 0, 0, 0, false, false, status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "%s", "Controller Volume Capability are not provided")) } supported, reason := valVolumeCaps(vcs, protocol) if !supported { - return "", "", 0, 0, 0, false, false, status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "Volume Capabilities are not supported. Reason=["+reason+"]")) + return "", "", 0, 0, 0, false, false, status.Error(codes.InvalidArgument, utils.GetMessageWithRunID(rid, "%s", "Volume Capabilities are not supported. Reason=["+reason+"]")) } return