feat(iOS): load iOS key from base64 input. (#336)

* feat(iOS): load iOS key from base64 input.

* test: check key type exist.
This commit is contained in:
Bo-Yi Wu
2018-02-18 17:12:51 +08:00
committed by GitHub
parent c3167f77f3
commit 2d2f62d19b
7 changed files with 129 additions and 20 deletions

View File

@@ -23,6 +23,8 @@ core:
ssl: false
cert_path: "cert.pem"
key_path: "key.pem"
cert_base64: ""
key_base64: ""
http_proxy: "" # only working for FCM server
pid:
enabled: false
@@ -54,6 +56,8 @@ android:
ios:
enabled: false
key_path: "key.pem"
key_base64: "" # load iOS key from base64 input
key_type: "pem" # could be pem, p12 or p8 type
password: "" # certificate password, default as empty string.
production: false
max_retry: 0 # resend fail notification, default value zero is disabled
@@ -107,6 +111,8 @@ type SectionCore struct {
SSL bool `yaml:"ssl"`
CertPath string `yaml:"cert_path"`
KeyPath string `yaml:"key_path"`
CertBase64 string `yaml:"cert_base64"`
KeyBase64 string `yaml:"key_base64"`
HTTPProxy string `yaml:"http_proxy"`
PID SectionPID `yaml:"pid"`
AutoTLS SectionAutoTLS `yaml:"auto_tls"`
@@ -141,6 +147,8 @@ type SectionAndroid struct {
type SectionIos struct {
Enabled bool `yaml:"enabled"`
KeyPath string `yaml:"key_path"`
KeyBase64 string `yaml:"key_base64"`
KeyType string `yaml:"key_type"`
Password string `yaml:"password"`
Production bool `yaml:"production"`
MaxRetry int `yaml:"max_retry"`
@@ -247,6 +255,8 @@ func LoadConf(confPath string) (ConfYaml, error) {
conf.Core.SSL = viper.GetBool("core.ssl")
conf.Core.CertPath = viper.GetString("core.cert_path")
conf.Core.KeyPath = viper.GetString("core.key_path")
conf.Core.CertBase64 = viper.GetString("core.cert_base64")
conf.Core.KeyBase64 = viper.GetString("core.key_base64")
conf.Core.MaxNotification = int64(viper.GetInt("core.max_notification"))
conf.Core.HTTPProxy = viper.GetString("core.http_proxy")
conf.Core.PID.Enabled = viper.GetBool("core.pid.enabled")
@@ -273,6 +283,8 @@ func LoadConf(confPath string) (ConfYaml, error) {
// iOS
conf.Ios.Enabled = viper.GetBool("ios.enabled")
conf.Ios.KeyPath = viper.GetString("ios.key_path")
conf.Ios.KeyBase64 = viper.GetString("ios.key_base64")
conf.Ios.KeyType = viper.GetString("ios.key_type")
conf.Ios.Password = viper.GetString("ios.password")
conf.Ios.Production = viper.GetBool("ios.production")
conf.Ios.MaxRetry = viper.GetInt("ios.max_retry")

View File

@@ -10,6 +10,8 @@ core:
ssl: false
cert_path: "cert.pem"
key_path: "key.pem"
cert_base64: ""
key_base64: ""
http_proxy: "" # only working for FCM server
pid:
enabled: false
@@ -41,6 +43,8 @@ android:
ios:
enabled: false
key_path: "key.pem"
key_base64: "" # load iOS key from base64 input
key_type: "pem" # could be pem, p12 or p8 type
password: "" # certificate password, default as empty string.
production: false
max_retry: 0 # resend fail notification, default value zero is disabled

View File

@@ -47,6 +47,8 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Core.SSL)
assert.Equal(suite.T(), "cert.pem", suite.ConfGorushDefault.Core.CertPath)
assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Core.KeyPath)
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.KeyBase64)
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.CertBase64)
assert.Equal(suite.T(), int64(100), suite.ConfGorushDefault.Core.MaxNotification)
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Core.HTTPProxy)
// Pid
@@ -74,6 +76,8 @@ func (suite *ConfigTestSuite) TestValidateConfDefault() {
// iOS
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Ios.Enabled)
assert.Equal(suite.T(), "key.pem", suite.ConfGorushDefault.Ios.KeyPath)
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Ios.KeyBase64)
assert.Equal(suite.T(), "pem", suite.ConfGorushDefault.Ios.KeyType)
assert.Equal(suite.T(), "", suite.ConfGorushDefault.Ios.Password)
assert.Equal(suite.T(), false, suite.ConfGorushDefault.Ios.Production)
assert.Equal(suite.T(), 0, suite.ConfGorushDefault.Ios.MaxRetry)
@@ -115,6 +119,8 @@ func (suite *ConfigTestSuite) TestValidateConf() {
assert.Equal(suite.T(), false, suite.ConfGorush.Core.SSL)
assert.Equal(suite.T(), "cert.pem", suite.ConfGorush.Core.CertPath)
assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Core.KeyPath)
assert.Equal(suite.T(), "", suite.ConfGorush.Core.CertBase64)
assert.Equal(suite.T(), "", suite.ConfGorush.Core.KeyBase64)
assert.Equal(suite.T(), int64(100), suite.ConfGorush.Core.MaxNotification)
assert.Equal(suite.T(), "", suite.ConfGorush.Core.HTTPProxy)
// Pid
@@ -142,6 +148,8 @@ func (suite *ConfigTestSuite) TestValidateConf() {
// iOS
assert.Equal(suite.T(), false, suite.ConfGorush.Ios.Enabled)
assert.Equal(suite.T(), "key.pem", suite.ConfGorush.Ios.KeyPath)
assert.Equal(suite.T(), "", suite.ConfGorush.Ios.KeyBase64)
assert.Equal(suite.T(), "pem", suite.ConfGorush.Ios.KeyType)
assert.Equal(suite.T(), "", suite.ConfGorush.Ios.Password)
assert.Equal(suite.T(), false, suite.ConfGorush.Ios.Production)
assert.Equal(suite.T(), 0, suite.ConfGorush.Ios.MaxRetry)