-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtask.go
48 lines (42 loc) · 1.1 KB
/
task.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
package main
import (
"fmt"
log "github.com/sirupsen/logrus"
)
type taskWrite struct {
Path string
Description string
Data map[string]interface{}
// Defer function to run on the completion of the write operation
Defer func()
}
type taskDelete struct {
Description string
Path string
}
func (t taskWrite) run(workerNum int) bool {
defer wg.Done()
if t.Defer != nil {
defer t.Defer()
}
log.Debugf("Writing %s {worker-%d}", t.Description, workerNum)
_, err := Vault.Write(t.Path, t.Data)
if err != nil {
log.Fatalf("Error writing %s: %v", t.Description, err)
return false
}
return true
}
func (t taskDelete) run(workerNum int) bool {
log.Infof("%s does not exist in configuration, prompting to delete {worker-%d}", t.Description, workerNum)
if askForConfirmation(fmt.Sprintf("Delete %s [y/n]?: ", t.Description), 3) {
_, err := Vault.Delete(t.Path)
if err != nil {
log.Fatalf("Error deleting %s: %v", t.Description, err)
}
log.Infof("%s deleted", t.Description)
} else {
log.Infof("Leaving %s even though it is not in config", t.Description)
}
return true
}