LoadYAMLByFilePath loads and validates the yaml.
(ctx context.Context, filePath string)
| 108 | |
| 109 | // LoadYAMLByFilePath loads and validates the yaml. |
| 110 | func LoadYAMLByFilePath(ctx context.Context, filePath string) (*limatype.LimaYAML, error) { |
| 111 | // We need to use the absolute path because it may be used to determine hostSocket locations. |
| 112 | absPath, err := filepath.Abs(filePath) |
| 113 | if err != nil { |
| 114 | return nil, err |
| 115 | } |
| 116 | yContent, err := os.ReadFile(absPath) |
| 117 | if err != nil { |
| 118 | return nil, err |
| 119 | } |
| 120 | y, err := limayaml.Load(ctx, yContent, absPath) |
| 121 | if err != nil { |
| 122 | return nil, err |
| 123 | } |
| 124 | if err := driverutil.ResolveVMType(ctx, y, filePath); err != nil { |
| 125 | return nil, fmt.Errorf("failed to resolve vm for %q: %w", filePath, err) |
| 126 | } |
| 127 | if err := limayaml.Validate(y, false); err != nil { |
| 128 | return nil, err |
| 129 | } |
| 130 | return y, nil |
| 131 | } |