2020-11-05 04:45:16 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2021-06-26 04:46:51 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/server/fleet"
|
2021-05-17 17:29:50 +00:00
|
|
|
"github.com/go-kit/kit/endpoint"
|
2020-11-05 04:45:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Begin File Carve
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type carveBeginRequest struct {
|
|
|
|
NodeKey string `json:"node_key"`
|
|
|
|
BlockCount int64 `json:"block_count"`
|
|
|
|
BlockSize int64 `json:"block_size"`
|
|
|
|
CarveSize int64 `json:"carve_size"`
|
|
|
|
CarveId string `json:"carve_id"`
|
|
|
|
RequestId string `json:"request_id"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type carveBeginResponse struct {
|
|
|
|
SessionId string `json:"session_id"`
|
|
|
|
Success bool `json:"success,omitempty"`
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r carveBeginResponse) error() error { return r.Err }
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func makeCarveBeginEndpoint(svc fleet.Service) endpoint.Endpoint {
|
2020-11-05 04:45:16 +00:00
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(carveBeginRequest)
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
payload := fleet.CarveBeginPayload{
|
2020-11-05 04:45:16 +00:00
|
|
|
BlockCount: req.BlockCount,
|
|
|
|
BlockSize: req.BlockSize,
|
|
|
|
CarveSize: req.CarveSize,
|
|
|
|
CarveId: req.CarveId,
|
|
|
|
RequestId: req.RequestId,
|
|
|
|
}
|
|
|
|
|
|
|
|
carve, err := svc.CarveBegin(ctx, payload)
|
|
|
|
if err != nil {
|
|
|
|
return carveBeginResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return carveBeginResponse{SessionId: carve.SessionId, Success: true}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Receive Block for File Carve
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
type carveBlockRequest struct {
|
|
|
|
NodeKey string `json:"node_key"`
|
|
|
|
BlockId int64 `json:"block_id"`
|
|
|
|
SessionId string `json:"session_id"`
|
|
|
|
RequestId string `json:"request_id"`
|
|
|
|
Data []byte `json:"data"`
|
|
|
|
}
|
|
|
|
|
|
|
|
type carveBlockResponse struct {
|
|
|
|
Success bool `json:"success,omitempty"`
|
|
|
|
Err error `json:"error,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r carveBlockResponse) error() error { return r.Err }
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
func makeCarveBlockEndpoint(svc fleet.Service) endpoint.Endpoint {
|
2020-11-05 04:45:16 +00:00
|
|
|
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
|
|
|
req := request.(carveBlockRequest)
|
|
|
|
|
2021-06-06 22:07:29 +00:00
|
|
|
payload := fleet.CarveBlockPayload{
|
2020-11-05 04:45:16 +00:00
|
|
|
SessionId: req.SessionId,
|
|
|
|
RequestId: req.RequestId,
|
|
|
|
BlockId: req.BlockId,
|
|
|
|
Data: req.Data,
|
|
|
|
}
|
|
|
|
|
|
|
|
err := svc.CarveBlock(ctx, payload)
|
|
|
|
if err != nil {
|
|
|
|
return carveBlockResponse{Err: err}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return carveBlockResponse{Success: true}, nil
|
|
|
|
}
|
|
|
|
}
|