-
Notifications
You must be signed in to change notification settings - Fork 27
/
depnotify.go
88 lines (73 loc) · 1.81 KB
/
depnotify.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package depnotify
/*
Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
*/
import (
"os"
"github.com/facebookincubator/go2chef"
"github.com/mitchellh/mapstructure"
)
// TypeName is the name of this step plugin
const TypeName = "go2chef.step.depnotify"
// Step implements a depnotify execution step plugin
type Step struct {
SName string `mapstructure:"name"`
Status bool
Message string
logger go2chef.Logger
}
func (s *Step) String() string {
return "<" + TypeName + ":" + s.SName + ">"
}
// SetName sets the name of this step instance
func (s *Step) SetName(name string) {
s.SName = name
}
// Name returns the name of this step instance
func (s *Step) Name() string {
return s.SName
}
// Type returns the type of this step instance
func (s *Step) Type() string {
return TypeName
}
// Download does nothing for this step since there's no
// downloading to be done when running any ol' command.
func (s *Step) Download() error {
return nil
}
// Execute appends the status to the depnotify log file.
func (s *Step) Execute() error {
prefix := "Command: "
if s.Status {
prefix = "Status: "
}
message := prefix + s.Message + "\n"
f, err := os.OpenFile("/private/var/tmp/depnotify.log",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
return err
}
defer f.Close()
if _, err := f.WriteString(message); err != nil {
return err
}
return nil
}
// Loader provides an instantiation function for this step plugin
func Loader(config map[string]interface{}) (go2chef.Step, error) {
c := &Step{
logger: go2chef.GetGlobalLogger(),
}
if err := mapstructure.Decode(config, c); err != nil {
return nil, err
}
return c, nil
}
var _ go2chef.Step = &Step{}
var _ go2chef.StepLoader = Loader
func init() {
if go2chef.AutoRegisterPlugins {
go2chef.RegisterStep(TypeName, Loader)
}
}