-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
95 lines (74 loc) · 2.1 KB
/
main.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
package main
import (
"github.com/hashicorp/go-hclog"
"github.com/reeveci/reeve-lib/plugin"
"github.com/reeveci/reeve-lib/schema"
)
const PLUGIN_NAME = "webui"
func main() {
log := hclog.New(&hclog.LoggerOptions{})
plugin.Serve(&plugin.PluginConfig{
Plugin: &WebUIPlugin{
Log: log,
JWTSecret: GenerateTokenSecret(),
History: NewPipelineHistory(10),
Actions: NewActionStore(),
Env: NewEnvStore(),
},
Logger: log,
})
}
type WebUIPlugin struct {
HTTPPort, HTTPSPort string
TLSCert, TLSKey string
AdminUsername, AdminPassword string
CORSOrigin string
Log hclog.Logger
API plugin.ReeveAPI
JWTSecret string
History *PipelineHistory
Actions *ActionStore
Env *EnvStore
}
func (p *WebUIPlugin) Name() (string, error) {
return PLUGIN_NAME, nil
}
func (p *WebUIPlugin) Register(settings map[string]string, api plugin.ReeveAPI) (capabilities plugin.Capabilities, err error) {
p.API = api
var enabled bool
if enabled, err = boolSetting(settings, "ENABLED"); !enabled || err != nil {
return
}
p.HTTPPort = settings["HTTP_PORT"]
p.HTTPSPort = settings["HTTPS_PORT"]
p.TLSCert = settings["TLS_CERT_FILE"]
p.TLSKey = settings["TLS_KEY_FILE"]
if p.AdminUsername, err = requireSetting(settings, "ADMIN_USERNAME"); err != nil {
return
}
if p.AdminPassword, err = requireSetting(settings, "ADMIN_PASSWORD"); err != nil {
return
}
p.CORSOrigin = settings["CORS_ORIGIN"]
if p.HTTPPort == "" && (p.HTTPSPort == "" || p.TLSCert == "" || p.TLSKey == "") {
p.HTTPPort = "9180"
}
go Serve(p)
p.API.NotifyMessages([]schema.Message{schema.BroadcastMessage(map[string]string{"webui": "present"}, nil)})
capabilities.Message = true
capabilities.Notify = true
return
}
func (p *WebUIPlugin) Unregister() error {
p.API.Close()
return nil
}
func (p *WebUIPlugin) Discover(trigger schema.Trigger) ([]schema.Pipeline, error) {
return nil, nil
}
func (p *WebUIPlugin) Resolve(env []string) (map[string]schema.Env, error) {
return nil, nil
}
func (p *WebUIPlugin) CLIMethod(method string, args []string) (string, error) {
return "", nil
}