CreateMetadataISO writes the provided meta data to an iso file in the given state directory
(state, data string, dataPath string)
| 293 | |
| 294 | // CreateMetadataISO writes the provided meta data to an iso file in the given state directory |
| 295 | func CreateMetadataISO(state, data string, dataPath string) ([]string, error) { |
| 296 | var d []byte |
| 297 | |
| 298 | // if we have neither data nor dataPath, nothing to return |
| 299 | switch { |
| 300 | case data != "" && dataPath != "": |
| 301 | return nil, fmt.Errorf("cannot specify options for both data and dataPath") |
| 302 | case data == "" && dataPath == "": |
| 303 | return []string{}, nil |
| 304 | case data != "": |
| 305 | d = []byte(data) |
| 306 | case dataPath != "": |
| 307 | var err error |
| 308 | d, err = os.ReadFile(dataPath) |
| 309 | if err != nil { |
| 310 | return nil, fmt.Errorf("cannot read user data from path %s: %v", dataPath, err) |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | isoPath := filepath.Join(state, "data.iso") |
| 315 | if err := WriteMetadataISO(isoPath, d); err != nil { |
| 316 | return nil, fmt.Errorf("cannot write user data ISO: %v", err) |
| 317 | } |
| 318 | return []string{isoPath}, nil |
| 319 | } |
no test coverage detected