-
Notifications
You must be signed in to change notification settings - Fork 37
/
kurtosis_yaml.go
40 lines (33 loc) · 1.48 KB
/
kurtosis_yaml.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package enclaves
import (
"github.com/go-yaml/yaml"
"github.com/kurtosis-tech/stacktrace"
"os"
)
const (
packagesUrl = "https://docs.kurtosis.com/concepts-reference/packages"
)
// fields are public because it's needed for YAML decoding
type KurtosisYaml struct {
PackageName string `yaml:"name"`
PackageDescription string `yaml:"description"`
PackageReplaceOptions map[string]string `yaml:"replace"`
}
func ParseKurtosisYaml(kurtosisYamlFilepath string) (*KurtosisYaml, error) {
kurtosisYamlContents, err := os.ReadFile(kurtosisYamlFilepath)
if err != nil {
if os.IsNotExist(err) {
return nil, stacktrace.NewError("Couldn't find a '%v' in the root of the package at '%v'. Packages are expected to have a '%v' at root; have a look at '%v' for more", kurtosisYamlFilename, kurtosisYamlFilepath, kurtosisYamlFilename, packagesUrl)
}
return nil, stacktrace.Propagate(err, "An error occurred while reading the '%v' file at '%v'", kurtosisYamlFilename, kurtosisYamlFilepath)
}
var kurtosisYaml KurtosisYaml
err = yaml.UnmarshalStrict(kurtosisYamlContents, &kurtosisYaml)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred while parsing the '%v' file at '%v'", kurtosisYamlFilename, kurtosisYamlFilepath)
}
if kurtosisYaml.PackageName == "" {
return nil, stacktrace.NewError("Field 'name', which is the Starlark package's name, in %v needs to be set and cannot be empty", kurtosisYamlFilename)
}
return &kurtosisYaml, nil
}