Skip to content

Commit b29bab8

Browse files
committed
fix(grpc): validate the payload for Kernel info
1 parent 5ced644 commit b29bab8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

infrastructure/grpc/convert.go

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import (
1010
"github.com/liquidmetal-dev/flintlock/pkg/ptr"
1111
)
1212

13+
func validateMicroVMSpec(spec *types.MicroVMSpec) error {
14+
if spec.Kernel == nil {
15+
return fmt.Errorf("MicroVMSpec.Kernel is required")
16+
}
17+
if spec.Kernel.Image == "" {
18+
return fmt.Errorf("MicroVMSpec.Kernel.Image is required")
19+
}
20+
return nil
21+
}
22+
1323
func convertMicroVMToModel(spec *types.MicroVMSpec) (*models.MicroVM, error) {
1424
uid := ""
1525

@@ -22,6 +32,11 @@ func convertMicroVMToModel(spec *types.MicroVMSpec) (*models.MicroVM, error) {
2232
return nil, fmt.Errorf("creating vmid from spec: %w", err)
2333
}
2434

35+
// Validate the spec
36+
if err := validateMicroVMSpec(spec); err != nil {
37+
return nil, err
38+
}
39+
2540
convertedModel := &models.MicroVM{
2641
ID: *vmid,
2742
// Labels

0 commit comments

Comments
 (0)