-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ROX-13934: Scanner running in Node Inventory mode (#1116)
- Loading branch information
Showing
13 changed files
with
1,484 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package nodeinventory | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/grpc-ecosystem/grpc-gateway/runtime" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
apiGRPC "github.com/stackrox/scanner/api/grpc" | ||
v1 "github.com/stackrox/scanner/generated/scanner/api/v1" | ||
"github.com/stackrox/scanner/pkg/nodeinventory" | ||
"google.golang.org/grpc" | ||
) | ||
|
||
// Service defines the node scanning service. | ||
type Service interface { | ||
apiGRPC.APIService | ||
|
||
v1.NodeInventoryServiceServer | ||
} | ||
|
||
// NewService returns the service for node scanning | ||
func NewService(nodeName string) Service { | ||
return &serviceImpl{ | ||
inventoryCollector: &nodeinventory.Scanner{}, | ||
nodeName: nodeName, | ||
} | ||
} | ||
|
||
type serviceImpl struct { | ||
inventoryCollector *nodeinventory.Scanner | ||
nodeName string | ||
} | ||
|
||
func (s *serviceImpl) GetNodeInventory(ctx context.Context, req *v1.GetNodeInventoryRequest) (*v1.GetNodeInventoryResponse, error) { | ||
inventoryScan, err := s.inventoryCollector.Scan(s.nodeName) | ||
if err != nil { | ||
log.Errorf("Error running inventoryCollector.Scan(%s): %v", s.nodeName, err) | ||
return nil, errors.New("Internal scanner error: failed to scan node") | ||
} | ||
|
||
log.Debugf("InventoryScan: %+v", inventoryScan) | ||
|
||
return &v1.GetNodeInventoryResponse{ | ||
NodeName: s.nodeName, | ||
Components: inventoryScan.Components, | ||
Notes: inventoryScan.Notes, | ||
}, nil | ||
} | ||
|
||
// RegisterServiceServer registers this service with the given gRPC Server. | ||
func (s *serviceImpl) RegisterServiceServer(grpcServer *grpc.Server) { | ||
v1.RegisterNodeInventoryServiceServer(grpcServer, s) | ||
} | ||
|
||
// RegisterServiceHandler registers this service with the given gRPC Gateway endpoint. | ||
func (s *serviceImpl) RegisterServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { | ||
return v1.RegisterNodeInventoryServiceHandler(ctx, mux, conn) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.