| giolekva | b1f19ee | 2020-05-16 11:31:20 +0400 | [diff] [blame] | 1 | package appmanager |
| 2 | |
| 3 | import ( |
| 4 | "io/ioutil" |
| 5 | "os" |
| 6 | |
| 7 | "gopkg.in/yaml.v2" |
| 8 | ) |
| 9 | |
| 10 | type Action struct { |
| 11 | Name string `yaml:"name"` |
| 12 | Template string `yaml:"template"` |
| 13 | } |
| 14 | |
| 15 | type Actions struct { |
| 16 | Actions []Action `yaml:"actions"` |
| 17 | } |
| 18 | |
| giolekva | 1c0372c | 2020-05-16 21:18:59 +0400 | [diff] [blame] | 19 | type CallAction struct { |
| 20 | App string `yaml:"app"` |
| 21 | Action string `yaml:"action"` |
| 22 | Args map[string]interface{} `yaml:"args"` |
| 23 | } |
| 24 | |
| 25 | type PostInstall struct { |
| 26 | CallAction []CallAction `yaml:"callAction"` |
| 27 | } |
| 28 | |
| 29 | type Init struct { |
| 30 | PostInstall PostInstall `yaml:"postInstall"` |
| 31 | } |
| 32 | |
| giolekva | b1f19ee | 2020-05-16 11:31:20 +0400 | [diff] [blame] | 33 | func FromYaml(str string, out interface{}) error { |
| 34 | return yaml.Unmarshal([]byte(str), out) |
| 35 | } |
| 36 | |
| 37 | func FromYamlFile(actionsFile string, out interface{}) error { |
| 38 | f, err := os.Open(actionsFile) |
| 39 | if err != nil { |
| 40 | return err |
| 41 | } |
| 42 | defer f.Close() |
| 43 | b, err := ioutil.ReadAll(f) |
| 44 | if err != nil { |
| 45 | return err |
| 46 | } |
| 47 | return FromYaml(string(b), out) |
| 48 | } |