/
hooks.go
70 lines (60 loc) · 1.91 KB
/
hooks.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
// Copyright 2013 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
// hooks provides types and constants that define the hooks known to Juju.
package hooks
// Kind enumerates the different kinds of hooks that exist.
type Kind string
const (
// None of these hooks are ever associated with a relation; each of them
// represents a change to the state of the unit as a whole. The values
// themselves are all valid hook names.
Install Kind = "install"
Start Kind = "start"
ConfigChanged Kind = "config-changed"
UpgradeCharm Kind = "upgrade-charm"
Stop Kind = "stop"
// These hooks require an associated relation, and the name of the relation
// unit whose change triggered the hook. The hook file names that these
// kinds represent will be prefixed by the relation name; for example,
// "db-relation-joined".
RelationJoined Kind = "relation-joined"
RelationChanged Kind = "relation-changed"
RelationDeparted Kind = "relation-departed"
// This hook requires an associated relation. The represented hook file name
// will be prefixed by the relation name, just like the other Relation* Kind
// values.
RelationBroken Kind = "relation-broken"
)
var unitHooks = []Kind{
Install,
Start,
ConfigChanged,
UpgradeCharm,
Stop,
}
// UnitHooks returns all known unit hook kinds.
func UnitHooks() []Kind {
hooks := make([]Kind, len(unitHooks))
copy(hooks, unitHooks)
return hooks
}
var relationHooks = []Kind{
RelationJoined,
RelationChanged,
RelationDeparted,
RelationBroken,
}
// RelationHooks returns all known relation hook kinds.
func RelationHooks() []Kind {
hooks := make([]Kind, len(relationHooks))
copy(hooks, relationHooks)
return hooks
}
// IsRelation returns whether the Kind represents a relation hook.
func (kind Kind) IsRelation() bool {
switch kind {
case RelationJoined, RelationChanged, RelationDeparted, RelationBroken:
return true
}
return false
}