Skip to content

Commit c72c2fd

Browse files
committed
remove unneeded variable
1 parent 7feedda commit c72c2fd

File tree

4 files changed

+79
-52
lines changed

4 files changed

+79
-52
lines changed

config/mattermost-push-proxy.json

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,22 @@
33
"ThrottlePerSec":300,
44
"ThrottleMemoryStoreSize":50000,
55
"ThrottleVaryByHeader":"X-Forwarded-For",
6-
"EnableMetrics": false,
7-
"ApplePushSettings":[
6+
"EnableMetrics": true,
7+
"ApplePushSettings": [
88
{
9-
"Type":"apple",
10-
"ApplePushUseDevelopment":false,
11-
"ApplePushCertPrivate":"",
12-
"ApplePushCertPassword":"",
13-
"ApplePushTopic":"com.mattermost.Mattermost"
14-
},
15-
{
16-
"Type":"apple_rn",
17-
"ApplePushUseDevelopment":false,
18-
"ApplePushCertPrivate":"",
19-
"ApplePushCertPassword":"",
20-
"ApplePushTopic":"com.mattermost.react.native"
9+
"Type" : "apple_rnbeta",
10+
"ApplePushUseDevelopment": true,
11+
12+
"ApplePushTopic": "com.mattermost.rnbeta",
13+
"AppleAuthKeyFile": "./config/beta/AuthKey_3B2U95G7RV.p8",
14+
"AppleAuthKeyID": "3B2U95G7RV",
15+
"AppleTeamID": "UQ8HT4Q2XM"
2116
}
2217
],
23-
"AndroidPushSettings":[
24-
{
25-
"Type":"android",
26-
"AndroidApiKey":""
27-
},
18+
"AndroidPushSettings": [
2819
{
29-
"Type":"android_rn",
30-
"AndroidApiKey":""
20+
"Type" : "android_rn",
21+
"AndroidApiKey": "AAAAKw6zMJI:APA91bH6ar_yDJK-wSmerlbmdTwlP7WsN-OWaHbW85gzCpMLoqkFowF48bQpJxOChzB4NYVXsYTET7qUbuuNqtvgVtfNotpTg6tQ7cb-rhSKv_pQTBQZCNbU5AsbhG0hNka2ULYSHSK-"
3122
}
3223
],
3324
"EnableConsoleLog": true,

server/apple_notification_server.go

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
apns "github.com/sideshow/apns2"
1414
"github.com/sideshow/apns2/certificate"
1515
"github.com/sideshow/apns2/payload"
16+
"github.com/sideshow/apns2/token"
1617
"golang.org/x/net/http2"
1718
)
1819

@@ -31,13 +32,68 @@ func NewAppleNotificationServer(settings ApplePushSettings, logger *Logger, metr
3132
}
3233
}
3334

35+
func (me *AppleNotificationServer) setupProxySettings(appleCert *tls.Certificate) bool {
36+
// Override the native transport.
37+
proxyServer := getProxyServer()
38+
if proxyServer != "" {
39+
transport := &http.Transport{
40+
Proxy: func(request *http.Request) (*url.URL, error) {
41+
return url.Parse(proxyServer)
42+
},
43+
IdleConnTimeout: apns.HTTPClientTimeout,
44+
}
45+
46+
if appleCert != nil {
47+
transport.TLSClientConfig = &tls.Config{
48+
Certificates: []tls.Certificate{*appleCert},
49+
}
50+
}
51+
52+
err := http2.ConfigureTransport(transport)
53+
if err != nil {
54+
me.logger.Errorf("Transport Error: %v", err)
55+
return false
56+
}
57+
58+
me.AppleClient.HTTPClient.Transport = transport
59+
}
60+
61+
if appleCert != nil {
62+
me.logger.Infof("Initializing apple notification server for type=%v with PEM certificate", me.ApplePushSettings.Type)
63+
} else {
64+
me.logger.Infof("Initializing apple notification server for type=%v with AuthKey", me.ApplePushSettings.Type)
65+
}
66+
67+
return true
68+
}
69+
3470
func (me *AppleNotificationServer) Initialize() bool {
35-
me.logger.Infof("Initializing apple notification server for type=%v", me.ApplePushSettings.Type)
71+
if me.ApplePushSettings.AppleAuthKeyFile != "" && me.ApplePushSettings.AppleAuthKeyID != "" && me.ApplePushSettings.AppleTeamID != "" {
72+
authKey, err := token.AuthKeyFromFile(me.ApplePushSettings.AppleAuthKeyFile)
73+
if err != nil {
74+
me.logger.Panicf("Failed to initialize apple notification service with AuthKey file err=%v ", err)
75+
}
76+
77+
appleToken := &token.Token{
78+
AuthKey: authKey,
79+
KeyID: me.ApplePushSettings.AppleAuthKeyID,
80+
TeamID: me.ApplePushSettings.AppleTeamID,
81+
}
82+
83+
if me.ApplePushSettings.ApplePushUseDevelopment {
84+
me.AppleClient = apns.NewTokenClient(appleToken).Development()
85+
} else {
86+
me.AppleClient = apns.NewTokenClient(appleToken).Production()
87+
}
88+
89+
// Override the native transport.
90+
return me.setupProxySettings(nil)
91+
}
3692

3793
if me.ApplePushSettings.ApplePushCertPrivate != "" {
3894
appleCert, appleCertErr := certificate.FromPemFile(me.ApplePushSettings.ApplePushCertPrivate, me.ApplePushSettings.ApplePushCertPassword)
3995
if appleCertErr != nil {
40-
me.logger.Panicf("Failed to load the apple pem cert err=%v for type=%v", appleCertErr, me.ApplePushSettings.Type)
96+
me.logger.Panicf("Failed to initialize apple notification service with pem cert err=%v for type=%v", appleCertErr, me.ApplePushSettings.Type)
4197
return false
4298
}
4399

@@ -48,33 +104,11 @@ func (me *AppleNotificationServer) Initialize() bool {
48104
}
49105

50106
// Override the native transport.
51-
proxyServer := getProxyServer()
52-
if proxyServer != "" {
53-
tlsConfig := &tls.Config{
54-
Certificates: []tls.Certificate{appleCert},
55-
}
56-
57-
transport := &http.Transport{
58-
TLSClientConfig: tlsConfig,
59-
Proxy: func(request *http.Request) (*url.URL, error) {
60-
return url.Parse(proxyServer)
61-
},
62-
IdleConnTimeout: apns.HTTPClientTimeout,
63-
}
64-
err := http2.ConfigureTransport(transport)
65-
if err != nil {
66-
me.logger.Errorf("Transport Error: %v", err)
67-
return false
68-
}
69-
70-
me.AppleClient.HTTPClient.Transport = transport
71-
}
72-
73-
return true
74-
} else {
75-
me.logger.Errorf("Apple push notifications not configured. Missing ApplePushCertPrivate. for type=%v", me.ApplePushSettings.Type)
76-
return false
107+
return me.setupProxySettings(&appleCert)
77108
}
109+
110+
me.logger.Errorf("Apple push notifications not configured. Missing ApplePushCertPrivate. for type=%v", me.ApplePushSettings.Type)
111+
return false
78112
}
79113

80114
func (me *AppleNotificationServer) SendNotification(msg *PushNotification) PushResponse {

server/config_push_proxy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ type ApplePushSettings struct {
2929
ApplePushCertPrivate string
3030
ApplePushCertPassword string
3131
ApplePushTopic string
32+
AppleAuthKeyFile string
33+
AppleAuthKeyID string
34+
AppleTeamID string
3235
ApplePushUseDevelopment bool
3336
}
3437

server/server.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,19 +196,18 @@ func (s *Server) handleSendNotification(w http.ResponseWriter, r *http.Request)
196196
// Parse the app version if available
197197
index := strings.Index(msg.Platform, "-v")
198198
platform := msg.Platform
199-
appVersion := 1
199+
msg.AppVersion = 1
200200
if index > -1 {
201201
msg.Platform = platform[:index]
202202
appVersionString := platform[index+2:]
203203
version, e := strconv.Atoi(appVersionString)
204204
if e == nil {
205-
appVersion = version
205+
msg.AppVersion = version
206206
} else {
207207
rMsg := fmt.Sprintf("Could not determine the app version in %v appVersion=%v", msg.Platform, appVersionString)
208208
s.logger.Error(rMsg)
209209
}
210210
}
211-
msg.AppVersion = appVersion
212211

213212
if server, ok := s.pushTargets[msg.Platform]; ok {
214213
rMsg := server.SendNotification(msg)

0 commit comments

Comments
 (0)