-
Notifications
You must be signed in to change notification settings - Fork 6
/
config.go
122 lines (102 loc) · 2.27 KB
/
config.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
package main
import (
"sort"
"sync"
"github.com/fsouza/go-dockerclient"
)
type Config struct {
sync.RWMutex
Channels *Channels // Channels of which Lurch is a member.
BotName string
EnableDM bool
SlackToken string
Docker dockerConfig
DisablePull bool
Debug bool
ConnAttempts int
Stacks map[string]Stack
}
// GetStackList returns an ordered list of stack names.
func (c *Config) GetStackList() (stacks []string) {
for stack := range c.Stacks {
stacks = append(stacks, stack)
}
sort.Strings(stacks)
return
}
type ChannelType uint8
const (
None ChannelType = iota // 0
Channel // 1
Group // 2
)
type Channels struct {
sync.RWMutex
Names map[string]ChannelType
}
func NewChannels() *Channels {
return &Channels{
Names: make(map[string]ChannelType),
}
}
func (c *Channels) RemoveChannel(id string) {
c.Lock()
defer c.Unlock()
delete(c.Names, id)
}
func (c *Channels) AddChannel(id string, t ChannelType) {
c.Lock()
defer c.Unlock()
c.Names[id] = t
}
func (c *Channels) HasChannel(id string) (yes bool) {
c.RLock()
defer c.RUnlock()
_, yes = c.Names[id]
return
}
func (c *Channels) GetType(id string) (t ChannelType) {
c.RLock()
defer c.RUnlock()
t, _ = c.Names[id]
return
}
func (c *Channels) GetChannels() (chans []string) {
for id := range c.Names {
chans = append(chans, id)
}
return
}
type Stack struct {
Playbooks map[string]Playbook `yaml:",inline"`
}
// GetPlaybookList returns an ordered list of playbook names.
func (s Stack) GetPlaybookList() (playbooks []string) {
for playbook := range s.Playbooks {
playbooks = append(playbooks, playbook)
}
sort.Strings(playbooks)
return
}
type Playbook struct {
Location string `yaml:"playbook"`
About string `yaml:"about"`
Actions map[string]Action `yaml:"actions,omitempty"`
}
// GetActionList returns an ordered list of action names.
func (p Playbook) GetActionList() (actions []string) {
for action := range p.Actions {
actions = append(actions, action)
}
sort.Strings(actions)
return
}
type Action struct {
About string `yaml:"about"`
Vars map[string]string `yaml:"vars,omitempty"`
}
type dockerConfig struct {
Image string
Tag string
Auth docker.AuthConfiguration
}