/
schema.go
133 lines (116 loc) · 4.34 KB
/
schema.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
130
131
132
133
// Copyright 2019 Honey Science Corporation
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at http://mozilla.org/MPL/2.0/.
package config
// Event is the runtime data representation of an event.
type Event struct {
System string
Trigger string
}
// Action is the runtime data representation of an action.
type Action struct {
System string
Function string
}
// Trigger is the datastructure hold the information to match and process an event.
type Trigger struct {
Driver string
RawEvent string
Match map[string]interface{} `json:"if_match" mapstructure:"if_match"`
Parameters map[string]interface{}
// A trigger should have only one of source event a raw event.
Source Event
Export map[string]interface{}
Description string
Meta interface{}
}
// Function is the datastructure hold the information to run actions.
type Function struct {
Driver string
RawAction string
Parameters map[string](interface{})
// An action should have only one of target action or a raw action.
Target Action
Export map[string]interface{}
ExportOnSuccess map[string]interface{} `json:"export_on_success" mapstructure:"export_on_success"`
ExportOnFailure map[string]interface{} `json:"export_on_failure" mapstructure:"export_on_failure"`
Description string
Meta interface{}
}
// System is an abstract construct to group data, trigger and function definitions.
type System struct {
Data map[string](interface{})
Triggers map[string]Trigger
Functions map[string]Function
Extends []string
Description string
Meta interface{}
}
// Workflow defines one or more actions needed to complete certain task and how they are orchestrated.
type Workflow struct {
Name string
Description string
Meta interface{}
Context string
Contexts interface{}
Local map[string]interface{} `json:"with" mapstructure:"with"`
Match interface{} `json:"if_match" mapstructure:"if_match"`
UnlessMatch interface{} `json:"unless_match" mapstructure:"unelss_match"`
WhileMatch interface{} `json:"while_match" mapstructure:"while_match"`
UntilMatch interface{} `json:"until_match" mapstructure:"until_match"`
If []string
IfAny []string `json:"if_any" mapstructure:"if_any"`
Unless []string
UnlessAll []string `json:"unless_any" mapstructure:"unless_all"`
While []string
WhileAny []string `json:"while_any" mapstructure:"while_any"`
Until []string
UntilAll []string `json:"until_any" mapstructure:"until_all"`
Else interface{} `json:"else,omitempty"`
Iterate interface{}
IterateParallel interface{} `json:"iterate_parallel" mapstructure:"iterate_parallel"`
IterateAs string `json:"iterate_as" mapstructure:"iterate_as"`
Retry string
Backoff string
OnError string `json:"on_error" mapstructure:"on_error"`
OnFailure string `json:"on_failure" mapstructure:"on_failure"`
Workflow string `json:"call_workflow" mapstructure:"call_workflow"`
Function Function
CallFunction string `json:"call_function" mapstructure:"call_function"`
CallDriver string `json:"call_driver" mapstructure:"call_driver"`
Steps []Workflow
Threads []Workflow
Wait string
Switch string
Cases map[string]interface{}
Default interface{}
Export map[string]interface{}
ExportOnSuccess map[string]interface{} `json:"export_on_success" mapstructure:"export_on_success"`
ExportOnFailure map[string]interface{} `json:"export_on_failure" mapstructure:"export_on_failure"`
NoExport []string `json:"no_export" mapstructure:"no_export"`
}
// Rule is a data structure defining what action to take when certain event happen.
type Rule struct {
When Trigger
Do Workflow
}
// RepoInfo points to a git repo where config data can be read from.
type RepoInfo struct {
Repo string
Branch string
Path string
Name string
Description string
}
// DataSet is a subset of configuration that can be assembled to the complete final configuration.
type DataSet struct {
Systems map[string]System
Rules []Rule
Drivers map[string]interface{}
Includes []string
Repos []RepoInfo
Workflows map[string]Workflow
Contexts map[string]interface{}
}