This repository was archived by the owner on May 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathinteractor.go
122 lines (100 loc) · 2.46 KB
/
interactor.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 interactor
import (
"fmt"
evbus "github.com/asaskevich/EventBus"
"go.uber.org/zap"
)
type (
Interactor struct {
Store
SCM
// The channel to stop background workers.
stopCh chan struct{}
common *service
// services used for talking to different parts of the entities.
*ConfigInteractor
*DeploymentInteractor
*DeploymentStatisticsInteractor
*EventInteractor
*LicenseInteractor
*LockInteractor
*RepoInteractor
*ReviewInteractor
*UserInteractor
}
InteractorConfig struct {
ServerHost string
ServerProto string
ServerProxyHost string
ServerProxyProto string
OrgEntries []string
MemberEntries []string
AdminUsers []string
WebhookSecret string
LicenseKey string
Store
SCM
}
service struct {
store Store
scm SCM
log *zap.Logger
}
)
func NewInteractor(c *InteractorConfig) *Interactor {
i := &Interactor{
Store: c.Store,
SCM: c.SCM,
stopCh: make(chan struct{}),
}
log := zap.L().Named("interactor")
i.common = &service{
store: c.Store,
scm: c.SCM,
log: log,
}
i.ConfigInteractor = (*ConfigInteractor)(i.common)
i.DeploymentInteractor = (*DeploymentInteractor)(i.common)
i.DeploymentStatisticsInteractor = (*DeploymentStatisticsInteractor)(i.common)
i.EventInteractor = &EventInteractor{
service: i.common,
events: evbus.New(),
}
i.LicenseInteractor = &LicenseInteractor{
service: i.common,
LicenseKey: c.LicenseKey,
}
i.LockInteractor = (*LockInteractor)(i.common)
i.RepoInteractor = &RepoInteractor{
service: i.common,
WebhookURL: c.BuildWebhookURL(),
WebhookSSL: c.ServerProxyProto == "https",
WebhookSecret: c.WebhookSecret,
}
i.ReviewInteractor = (*ReviewInteractor)(i.common)
i.UserInteractor = &UserInteractor{
service: i.common,
admins: c.AdminUsers,
orgEntries: c.OrgEntries,
memberEntries: c.MemberEntries,
}
go func() {
log.Info("Start the working publishing events.")
i.runPublishingEvents(i.stopCh)
}()
go func() {
log.Info("Start the worker canceling inactive deployments.")
i.runClosingInactiveDeployment(i.stopCh)
}()
go func() {
log.Info("Start the worker for the auto unlock.")
i.runAutoUnlock(i.stopCh)
}()
return i
}
func (c *InteractorConfig) BuildWebhookURL() string {
if c.ServerProxyProto != "" && c.ServerProxyHost != "" {
return fmt.Sprintf("%s://%s/hooks", c.ServerProxyProto, c.ServerProxyHost)
}
return fmt.Sprintf("%s://%s/hooks", c.ServerProto, c.ServerHost)
}