Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 247f479

Browse files
committed
api/types/events: add "Type" type for event-type enum
Currently just an alias for string, but we can change it to be an actual type. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 2561e33 commit 247f479

File tree

4 files changed

+25
-32
lines changed

4 files changed

+25
-32
lines changed

api/types/events/events.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,26 @@
11
package events // import "github.com/docker/docker/api/types/events"
22

3+
// Type is used for event-types.
4+
type Type = string
5+
6+
// List of known event types.
37
const (
4-
// BuilderEventType is the event type that the builder generates
5-
BuilderEventType = "builder"
6-
// ContainerEventType is the event type that containers generate
7-
ContainerEventType = "container"
8-
// DaemonEventType is the event type that daemon generate
9-
DaemonEventType = "daemon"
10-
// ImageEventType is the event type that images generate
11-
ImageEventType = "image"
12-
// NetworkEventType is the event type that networks generate
13-
NetworkEventType = "network"
14-
// PluginEventType is the event type that plugins generate
15-
PluginEventType = "plugin"
16-
// VolumeEventType is the event type that volumes generate
17-
VolumeEventType = "volume"
18-
// ServiceEventType is the event type that services generate
19-
ServiceEventType = "service"
20-
// NodeEventType is the event type that nodes generate
21-
NodeEventType = "node"
22-
// SecretEventType is the event type that secrets generate
23-
SecretEventType = "secret"
24-
// ConfigEventType is the event type that configs generate
25-
ConfigEventType = "config"
8+
BuilderEventType Type = "builder" // BuilderEventType is the event type that the builder generates.
9+
ConfigEventType Type = "config" // ConfigEventType is the event type that configs generate.
10+
ContainerEventType Type = "container" // ContainerEventType is the event type that containers generate.
11+
DaemonEventType Type = "daemon" // DaemonEventType is the event type that daemon generate.
12+
ImageEventType Type = "image" // ImageEventType is the event type that images generate.
13+
NetworkEventType Type = "network" // NetworkEventType is the event type that networks generate.
14+
NodeEventType Type = "node" // NodeEventType is the event type that nodes generate.
15+
PluginEventType Type = "plugin" // PluginEventType is the event type that plugins generate.
16+
SecretEventType Type = "secret" // SecretEventType is the event type that secrets generate.
17+
ServiceEventType Type = "service" // ServiceEventType is the event type that services generate.
18+
VolumeEventType Type = "volume" // VolumeEventType is the event type that volumes generate.
2619
)
2720

2821
// Actor describes something that generates events,
2922
// like a container, or a network, or a volume.
30-
// It has a defined name and a set or attributes.
23+
// It has a defined name and a set of attributes.
3124
// The container attributes are its labels, other actors
3225
// can generate these attributes from other properties.
3326
type Actor struct {
@@ -39,11 +32,11 @@ type Actor struct {
3932
type Message struct {
4033
// Deprecated information from JSONMessage.
4134
// With data only in container events.
42-
Status string `json:"status,omitempty"`
43-
ID string `json:"id,omitempty"`
44-
From string `json:"from,omitempty"`
35+
Status string `json:"status,omitempty"` // Deprecated: use Action instead.
36+
ID string `json:"id,omitempty"` // Deprecated: use Actor.ID instead.
37+
From string `json:"from,omitempty"` // Deprecated: use Actor.Attributes["image"] instead.
4538

46-
Type string
39+
Type Type
4740
Action string
4841
Actor Actor
4942
// Engine events are local scope. Cluster events are swarm scope.

client/events_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,17 @@ func TestEvents(t *testing.T) {
9191
},
9292
events: []events.Message{
9393
{
94-
Type: "container",
94+
Type: events.BuilderEventType,
9595
ID: "1",
9696
Action: "create",
9797
},
9898
{
99-
Type: "container",
99+
Type: events.BuilderEventType,
100100
ID: "2",
101101
Action: "die",
102102
},
103103
{
104-
Type: "container",
104+
Type: events.BuilderEventType,
105105
ID: "3",
106106
Action: "create",
107107
},

daemon/events/events.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (e *Events) Evict(l chan interface{}) {
7979
}
8080

8181
// Log creates a local scope message and publishes it
82-
func (e *Events) Log(action, eventType string, actor eventtypes.Actor) {
82+
func (e *Events) Log(action string, eventType eventtypes.Type, actor eventtypes.Actor) {
8383
now := time.Now().UTC()
8484
jm := eventtypes.Message{
8585
Action: action,

daemon/events/filter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func (ef *Filter) matchConfig(ev events.Message) bool {
102102
return ef.fuzzyMatchName(ev, events.ConfigEventType)
103103
}
104104

105-
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType string) bool {
105+
func (ef *Filter) fuzzyMatchName(ev events.Message, eventType events.Type) bool {
106106
return ef.filter.FuzzyMatch(eventType, ev.Actor.ID) ||
107107
ef.filter.FuzzyMatch(eventType, ev.Actor.Attributes["name"])
108108
}

0 commit comments

Comments
 (0)