From 49c376a76533712cb3c63a1410739bf7dec80300 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Fri, 27 May 2016 14:53:54 +0800 Subject: [PATCH] fixed #91 Remove pem_cert_path config setting. Signed-off-by: Bo-Yi Wu --- README.md | 3 +-- config/config.go | 10 ++++------ config/config.yml | 3 +-- gorush.go | 2 +- gorush/notification.go | 4 ++-- gorush/notification_test.go | 18 +++++++++--------- 6 files changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index aef93b3..91133e5 100644 --- a/README.md +++ b/README.md @@ -48,8 +48,7 @@ android: ios: enabled: false - pem_cert_path: "cert.pem" - pem_key_path: "key.pem" + pem_path: "key.pem" production: false log: diff --git a/config/config.go b/config/config.go index c3f768f..6c47b47 100644 --- a/config/config.go +++ b/config/config.go @@ -44,10 +44,9 @@ type SectionAndroid struct { // SectionIos is sub seciont of config. type SectionIos struct { - Enabled bool `yaml:"enabled"` - PemCertPath string `yaml:"pem_cert_path"` - PemKeyPath string `yaml:"pem_key_path"` - Production bool `yaml:"production"` + Enabled bool `yaml:"enabled"` + PemPath string `yaml:"pem_path"` + Production bool `yaml:"production"` } // SectionLog is sub seciont of config. @@ -106,8 +105,7 @@ func BuildDefaultPushConf() ConfYaml { // iOS conf.Ios.Enabled = false - conf.Ios.PemCertPath = "cert.pem" - conf.Ios.PemKeyPath = "key.pem" + conf.Ios.PemPath = "key.pem" conf.Ios.Production = false // log diff --git a/config/config.yml b/config/config.yml index 0d4fe6a..0f791e9 100644 --- a/config/config.yml +++ b/config/config.yml @@ -20,8 +20,7 @@ android: ios: enabled: false - pem_cert_path: "cert.pem" - pem_key_path: "key.pem" + pem_path: "key.pem" production: false log: diff --git a/gorush.go b/gorush.go index 4f74951..f8bd672 100644 --- a/gorush.go +++ b/gorush.go @@ -58,7 +58,7 @@ func main() { } if *certificateKeyPath != "" { - gorush.PushConf.Ios.PemKeyPath = *certificateKeyPath + gorush.PushConf.Ios.PemPath = *certificateKeyPath } if *apiKey != "" { diff --git a/gorush/notification.go b/gorush/notification.go index ee68dc7..fe17a91 100644 --- a/gorush/notification.go +++ b/gorush/notification.go @@ -122,7 +122,7 @@ func CheckPushConf() error { } if PushConf.Ios.Enabled { - if PushConf.Ios.PemKeyPath == "" { + if PushConf.Ios.PemPath == "" { return errors.New("Missing iOS certificate path") } } @@ -141,7 +141,7 @@ func InitAPNSClient() error { if PushConf.Ios.Enabled { var err error - CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemKeyPath, "") + CertificatePemIos, err = certificate.FromPemFile(PushConf.Ios.PemPath, "") if err != nil { LogError.Error("Cert Error:", err.Error()) diff --git a/gorush/notification_test.go b/gorush/notification_test.go index ddcebfa..fef32dc 100644 --- a/gorush/notification_test.go +++ b/gorush/notification_test.go @@ -26,7 +26,7 @@ func TestMissingIOSCertificate(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "" + PushConf.Ios.PemPath = "" err := CheckPushConf() @@ -53,7 +53,7 @@ func TestCorrectConf(t *testing.T) { PushConf.Android.APIKey = "xxxxx" PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "xxxxx" + PushConf.Ios.PemPath = "xxxxx" err := CheckPushConf() @@ -221,7 +221,7 @@ func TestPushToIOS(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() InitAppStatus() @@ -331,7 +331,7 @@ func TestSenMultipleNotifications(t *testing.T) { InitWorkers(2, 2) PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() PushConf.Android.Enabled = true @@ -364,7 +364,7 @@ func TestDisabledAndroidNotifications(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() PushConf.Android.Enabled = false @@ -397,7 +397,7 @@ func TestDisabledIosNotifications(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = false - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() PushConf.Android.Enabled = true @@ -430,7 +430,7 @@ func TestMissingIosCertificate(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "test" + PushConf.Ios.PemPath = "test" err := InitAPNSClient() assert.Error(t, err) @@ -440,7 +440,7 @@ func TestAPNSClientDevHost(t *testing.T) { PushConf = config.BuildDefaultPushConf() PushConf.Ios.Enabled = true - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host) @@ -451,7 +451,7 @@ func TestAPNSClientProdHost(t *testing.T) { PushConf.Ios.Enabled = true PushConf.Ios.Production = true - PushConf.Ios.PemKeyPath = "../certificate/certificate-valid.pem" + PushConf.Ios.PemPath = "../certificate/certificate-valid.pem" InitAPNSClient() assert.Equal(t, apns2.HostProduction, ApnsClient.Host)