-
Notifications
You must be signed in to change notification settings - Fork 2
/
bridges.go
155 lines (137 loc) · 5.36 KB
/
bridges.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"bytes"
"fmt"
"log"
"text/template"
)
type BeeperEnv string
const (
EnvDevelopment BeeperEnv = "DEV"
EnvStaging BeeperEnv = "STAGING"
EnvProduction BeeperEnv = "PROD"
)
type BeeperChannel string
const (
ChannelStable BeeperChannel = "STABLE"
ChannelNightly BeeperChannel = "NIGHTLY"
ChannelInternal BeeperChannel = "INTERNAL"
)
type BridgeType string
const (
BridgeTelegram BridgeType = "telegram"
BridgeTelegramV2 BridgeType = "telegramv2"
BridgeWhatsApp BridgeType = "whatsapp"
BridgeFacebook BridgeType = "facebook"
BridgeFacebookGo BridgeType = "facebookgo"
BridgeGoogleChat BridgeType = "googlechat"
BridgeGroupMe BridgeType = "groupme"
BridgeTwitter BridgeType = "twitter"
BridgeSignal BridgeType = "signal"
BridgeInstagram BridgeType = "instagram"
BridgeInstagramGo BridgeType = "instagramgo"
BridgeMeta BridgeType = "meta"
BridgeDiscord BridgeType = "discordgo"
BridgeSlack BridgeType = "slackgo"
BridgeGoogleMessages BridgeType = "gmessages"
BridgeGoogleVoice BridgeType = "gvoice"
BridgeLinkedIn BridgeType = "linkedin"
BridgeiMessageCloud BridgeType = "imessagecloud"
BridgeiMessagego BridgeType = "imessagego"
BridgeHungryserv BridgeType = "hungryserv"
BridgeDummy BridgeType = "dummybridge"
BridgeDummyWebsocket BridgeType = "dummybridgews"
)
var defaultNotifications = []BridgeUpdateNotification{
{Environment: EnvDevelopment, Channel: ChannelStable},
{Environment: EnvStaging, Channel: ChannelStable},
{Environment: EnvProduction, Channel: ChannelInternal, DeployNext: true},
}
var bridgeNotifications = map[BridgeType][]BridgeUpdateNotification{
BridgeTelegram: {},
BridgeTelegramV2: {
{Environment: EnvDevelopment, Channel: ChannelStable, Bridge: BridgeTelegram},
{Environment: EnvStaging, Channel: ChannelStable, Bridge: BridgeTelegram},
{Environment: EnvProduction, Channel: ChannelInternal, Bridge: BridgeTelegram, DeployNext: true},
},
BridgeWhatsApp: defaultNotifications,
BridgeFacebook: defaultNotifications,
BridgeGoogleChat: defaultNotifications,
BridgeGroupMe: defaultNotifications,
BridgeTwitter: defaultNotifications,
BridgeSignal: defaultNotifications,
BridgeInstagram: defaultNotifications,
BridgeiMessagego: defaultNotifications,
BridgeDiscord: defaultNotifications,
BridgeSlack: defaultNotifications,
BridgeGoogleMessages: defaultNotifications,
BridgeGoogleVoice: defaultNotifications,
BridgeLinkedIn: defaultNotifications,
BridgeHungryserv: defaultNotifications,
BridgeDummy: {
{Environment: EnvDevelopment, Channel: ChannelStable},
{Environment: EnvDevelopment, Channel: ChannelStable, Bridge: BridgeDummyWebsocket},
{Environment: EnvStaging, Channel: ChannelStable},
{Environment: EnvStaging, Channel: ChannelStable, Bridge: BridgeDummyWebsocket},
},
BridgeDummyWebsocket: {},
BridgeiMessageCloud: {
{Environment: EnvDevelopment, Channel: ChannelStable, DeployNext: true},
{Environment: EnvStaging, Channel: ChannelStable, DeployNext: true},
{Environment: EnvProduction, Channel: ChannelInternal, DeployNext: true},
},
BridgeMeta: {
// These are the default notifications, but duplicated for each mode
{Environment: EnvDevelopment, Channel: ChannelStable, Bridge: BridgeFacebookGo},
{Environment: EnvStaging, Channel: ChannelStable, Bridge: BridgeFacebookGo},
{Environment: EnvProduction, Channel: ChannelInternal, DeployNext: true, Bridge: BridgeFacebookGo},
{Environment: EnvDevelopment, Channel: ChannelStable, Bridge: BridgeInstagramGo},
{Environment: EnvStaging, Channel: ChannelStable, Bridge: BridgeInstagramGo},
{Environment: EnvProduction, Channel: ChannelInternal, DeployNext: true, Bridge: BridgeInstagramGo},
},
}
const DefaultImageTemplate = "{{.Image}}:{{.Commit}}-amd64"
var imageTemplateOverrides = map[BridgeType]string{
BridgeDummy: "{{.Image}}:{{.Commit}}",
BridgeGroupMe: "{{.Image}}:{{.Commit}}",
BridgeHungryserv: "{{.Image}}:{{.Commit}}",
BridgeLinkedIn: "{{.Image}}:{{.Commit}}",
BridgeiMessageCloud: "{{.Commit}}",
BridgeiMessagego: "{{.Image}}:{{.Commit}}",
BridgeTelegramV2: "{{.Image}}:v2-{{.Commit}}-amd64",
}
const DefaultTargetRepoTemplate = "%s/bridge/%s"
var targetImageRepoOverrides = map[BridgeType]string{
BridgeHungryserv: "/hungryserv",
BridgeTelegramV2: "/bridge/telegram",
}
func (bridgeType BridgeType) NotificationTargets() []BridgeUpdateNotification {
notifications, ok := bridgeNotifications[bridgeType]
if !ok || len(notifications) == 0 {
log.Fatalf("No Beeper notifications defined for %q", bridgeType)
}
return notifications
}
func (bridgeType BridgeType) FormatImage(image, commit string) string {
templateString, ok := imageTemplateOverrides[bridgeType]
if !ok {
templateString = DefaultImageTemplate
}
var result bytes.Buffer
tmpl := template.Must(template.New("t").Parse(templateString))
err := tmpl.Execute(&result, map[string]string{
"Image": image,
"Commit": commit,
})
if err != nil {
log.Fatalf("Failed to format image for %q", bridgeType)
}
return result.String()
}
func (bridgeType BridgeType) TargetRepo(registry string) string {
repo, ok := targetImageRepoOverrides[bridgeType]
if !ok {
return fmt.Sprintf(DefaultTargetRepoTemplate, registry, string(bridgeType))
}
return registry + repo
}