generated from getporter/skeletor
-
Notifications
You must be signed in to change notification settings - Fork 2
/
uninstall.go
40 lines (35 loc) · 828 Bytes
/
uninstall.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 nomad
import (
"context"
"io"
"github.com/pkg/errors"
"gopkg.in/yaml.v3"
)
type UninstallAction struct {
Uninstalls []Uninstall `yaml:"uninstall"`
}
type Uninstall struct {
Nomad Nomad `yaml:"nomad"`
}
func (m *Mixin) Uninstall(context context.Context) error {
action, err := parseUninstallAction(m)
if err != nil {
return err
}
return m.DoAction(action)
}
func parseUninstallAction(m *Mixin) (*Nomad, error) {
data, err := io.ReadAll(m.In)
if err != nil {
return nil, errors.Wrap(err, "could not read payload from STDIN")
}
var action UninstallAction
err = yaml.Unmarshal(data, &action)
if err != nil {
return nil, err
}
if len(action.Uninstalls) != 1 {
return nil, errors.Errorf("expected 1 uninstall steps, got %d", len(action.Uninstalls))
}
return &action.Uninstalls[0].Nomad, nil
}