/
dummy.go
129 lines (119 loc) · 4.18 KB
/
dummy.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package fabric
import (
"time"
"github.com/shieldproject/shield/core/scheduler"
"github.com/shieldproject/shield/core/vault"
"github.com/shieldproject/shield/db"
)
func Dummy(delay int) DummyFabric {
return DummyFabric{
delay: delay,
}
}
type DummyFabric struct {
delay int
}
func (f DummyFabric) Sleep() {
if f.delay > 0 {
time.Sleep(time.Duration(f.delay) * time.Second)
}
}
func (f DummyFabric) Backup(task *db.Task, encryption vault.Parameters) scheduler.Chore {
return scheduler.NewChore(
task.UUID,
func(chore scheduler.Chore) {
chore.Errorf("DUMMY> starting a backup operation; delay is %ds", f.delay)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> target plugin: '%s'", task.TargetPlugin)
chore.Errorf("DUMMY> target endpoint: '%s'", task.TargetEndpoint)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> store plugin: '%s'", task.StorePlugin)
chore.Errorf("DUMMY> store endpoint: '%s'", task.StoreEndpoint)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> compression: '%s'", task.Compression)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> encryption type: '%s'", encryption.Type)
chore.Errorf("DUMMY> encryption key: '%s'", encryption.Key)
chore.Errorf("DUMMY> encryption iv: '%s'", encryption.IV)
f.Sleep()
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> backup operation complete.")
chore.Infof(`{"key":"%s","archive_size":1337,"compression":"%s"}`,
time.Now().Format("2006/01/02/15/04/05/2006-01-02T1504.archive"),
task.Compression)
chore.UnixExit(0)
return
})
}
func (f DummyFabric) Restore(task *db.Task, encryption vault.Parameters) scheduler.Chore {
return scheduler.NewChore(
task.UUID,
func(chore scheduler.Chore) {
chore.Errorf("DUMMY> starting a restore operation; delay is %ds", f.delay)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> restore key: '%s'", task.RestoreKey)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> target plugin: '%s'", task.TargetPlugin)
chore.Errorf("DUMMY> target endpoint: '%s'", task.TargetEndpoint)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> store plugin: '%s'", task.StorePlugin)
chore.Errorf("DUMMY> store endpoint: '%s'", task.StoreEndpoint)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> compression: '%s'", task.Compression)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> encryption type: '%s'", encryption.Type)
chore.Errorf("DUMMY> encryption key: '%s'", encryption.Key)
chore.Errorf("DUMMY> encryption iv: '%s'", encryption.IV)
f.Sleep()
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> restore operation complete.")
chore.UnixExit(0)
return
})
}
func (f DummyFabric) Status(task *db.Task) scheduler.Chore {
return scheduler.NewChore(
task.UUID,
func(chore scheduler.Chore) {
chore.Errorf("DUMMY> starting an agent-status operation; delay is %ds", f.delay)
f.Sleep()
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> (there is no status; this is a test/dev fabric...")
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> agent-status operation complete.")
chore.UnixExit(0)
return
})
}
func (f DummyFabric) Purge(task *db.Task) scheduler.Chore {
return scheduler.NewChore(
task.UUID,
func(chore scheduler.Chore) {
chore.Errorf("DUMMY> starting an archive purge operation; delay is %ds", f.delay)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> archive key: '%s'", task.RestoreKey)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> store plugin: '%s'", task.StorePlugin)
chore.Errorf("DUMMY> store endpoint: '%s'", task.StoreEndpoint)
f.Sleep()
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> archive purge operation complete.")
chore.UnixExit(0)
return
})
}
func (f DummyFabric) TestStore(task *db.Task) scheduler.Chore {
return scheduler.NewChore(
task.UUID,
func(chore scheduler.Chore) {
chore.Errorf("DUMMY> starting storage test operation; delay is %ds", f.delay)
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> store plugin: '%s'", task.StorePlugin)
chore.Errorf("DUMMY> store endpoint: '%s'", task.StoreEndpoint)
f.Sleep()
chore.Errorf("DUMMY>")
chore.Errorf("DUMMY> storage test operation complete.")
chore.UnixExit(0)
return
})
}