-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathrecipe.go
69 lines (59 loc) · 2.31 KB
/
recipe.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"os"
"path/filepath"
"slices"
"sort"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
core "k8s.io/api/core/v1"
"sigs.k8s.io/yaml"
)
type AdditionalStep struct {
pipeline.Step
At int `json:"at"`
}
type Recipe struct {
Add []string `json:"add"`
AddEnvironment []core.EnvVar `json:"addEnvironment"`
AdditionalSteps []AdditionalStep `json:"additionalSteps"`
AddParams pipeline.ParamSpecs `json:"addParams"`
AddResult []pipeline.TaskResult `json:"addResult"`
AddVolume []core.Volume `json:"addVolume"`
AddVolumeMount []core.VolumeMount `json:"addVolumeMount"`
AddTAVolumeMount []core.VolumeMount `json:"addTAVolumeMount"`
Base string `json:"base"`
Description string `json:"description"`
DisplaySuffix string `json:"displaySuffix"`
PreferStepTemplate bool `json:"preferStepTemplate"`
UseTAVolumeMount bool `json:"useTAVolumeMount"`
RegexReplacements map[string]string `json:"regexReplacements"`
RemoveParams []string `json:"removeParams"`
RemoveVolumes []string `json:"removeVolumes"`
RemoveWorkspaces []string `json:"removeWorkspaces"`
Replacements map[string]string `json:"replacements"`
Suffix string `json:"suffix"`
createCachi2 bool
createSource bool
useCachi2 bool
useSource bool
}
func readRecipe(path string) (*Recipe, error) {
b := expectValue(os.ReadFile(path)) // #nosec G304 -- the file is passed in by the user, this is expected
// with defaults
recipe := Recipe{
Suffix: "-oci-ta",
DisplaySuffix: " oci trusted artifacts",
}
if err := yaml.Unmarshal(b, &recipe); err != nil {
return nil, err
}
sort.Strings(recipe.Add)
_, recipe.createCachi2 = slices.BinarySearch(recipe.Add, "create-cachi2")
_, recipe.createSource = slices.BinarySearch(recipe.Add, "create-source")
_, recipe.useCachi2 = slices.BinarySearch(recipe.Add, "use-cachi2")
_, recipe.useSource = slices.BinarySearch(recipe.Add, "use-source")
if !filepath.IsAbs(recipe.Base) {
recipe.Base = filepath.Join(filepath.Dir(path), recipe.Base)
}
return &recipe, nil
}