Skip to content

Commit

Permalink
add more grpc abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
noboruma committed Jul 8, 2024
1 parent bf90277 commit 4196e3b
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/server/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func init() {
type GRPCScannerServer struct {
HostMountPath, SocketPath string
InactiveThreshold int
extractorConfig cfg.Config
yaraRules *yararules.YaraRules
ExtractorConfig cfg.Config
YaraRules *yararules.YaraRules
pluginName string
pb.UnimplementedAgentPluginServer
pb.UnimplementedScannersServer
scanMap sync.Map
ScanMap sync.Map
}

type MalwareRPCServer struct {
Expand All @@ -68,7 +68,7 @@ func (s *GRPCScannerServer) StopScan(c context.Context, req *pb.StopScanRequest)
Description: "",
}

obj, found := s.scanMap.Load(scanID)
obj, found := s.ScanMap.Load(scanID)
if !found {
msg := "Failed to Stop scan"
log.Infof("%s, may have already completed, scan_id: %s", msg, scanID)
Expand Down Expand Up @@ -98,7 +98,7 @@ func (s *GRPCScannerServer) GetUID(context.Context, *pb.Empty) (*pb.Uid, error)
}

func (s *MalwareRPCServer) FindMalwareInfo(c context.Context, r *pb.MalwareRequest) (*pb.MalwareResult, error) {
yaraScanner, err := s.yaraRules.NewScanner()
yaraScanner, err := s.YaraRules.NewScanner()
if err != nil {
return &pb.MalwareResult{}, err
}
Expand All @@ -123,9 +123,9 @@ func (s *MalwareRPCServer) FindMalwareInfo(c context.Context, r *pb.MalwareReque
DoScan(
r.ScanId,
s.HostMountPath,
s.extractorConfig,
s.ExtractorConfig,
s.InactiveThreshold,
&s.scanMap,
&s.ScanMap,
namespace,
path,
image,
Expand All @@ -142,17 +142,17 @@ func (s *MalwareRPCServer) FindMalwareInfo(c context.Context, r *pb.MalwareReque
func DoScan(
scanID string,
hostMountPath string,
extractorConfig cfg.Config,
ExtractorConfig cfg.Config,

Check failure on line 145 in pkg/server/grpc.go

View workflow job for this annotation

GitHub Actions / lint

captLocal: `ExtractorConfig' should not be capitalized (gocritic)
inactiveThreshold int,
scanMap *sync.Map,
ScanMap *sync.Map,

Check failure on line 147 in pkg/server/grpc.go

View workflow job for this annotation

GitHub Actions / lint

captLocal: `ScanMap' should not be capitalized (gocritic)
namespace,
path, image, container string,
yaraScanner *yara.Scanner, writeToFile func(res output.IOCFound, scanID string)) {

jobs.StartScanJob()
defer jobs.StopScanJob()

scanner := scan.New(hostMountPath, extractorConfig, yaraScanner, scanID)
scanner := scan.New(hostMountPath, ExtractorConfig, yaraScanner, scanID)
res, ctx := tasks.StartStatusReporter(
scanID,
func(status tasks.ScanStatus) error {
Expand All @@ -166,10 +166,10 @@ func DoScan(
SUCCESS: "COMPLETE",
},
time.Duration(inactiveThreshold)*time.Second)
scanMap.Store(scanner.ScanID, ctx)
ScanMap.Store(scanner.ScanID, ctx)
var err error
defer func() {
scanMap.Delete(scanner.ScanID)
ScanMap.Delete(scanner.ScanID)
res <- err
close(res)
}()
Expand Down Expand Up @@ -208,12 +208,12 @@ func NewGRPCScannerServer(
HostMountPath: hostMoundPath,
SocketPath: socketPath,
InactiveThreshold: InactiveThreshold,
extractorConfig: config,
yaraRules: yaraRules,
ExtractorConfig: config,
YaraRules: yaraRules,
pluginName: pluginName,
UnimplementedAgentPluginServer: pb.UnimplementedAgentPluginServer{},
UnimplementedScannersServer: pb.UnimplementedScannersServer{},
scanMap: sync.Map{},
ScanMap: sync.Map{},
}

return res, nil
Expand Down

0 comments on commit 4196e3b

Please sign in to comment.