#510 add key id and team id ios cli flags (#511)

This commit is contained in:
Romanenko Alexey 2020-05-18 21:32:50 +07:00 committed by GitHub
parent b35a831a41
commit 6bad4797b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 1 deletions

View File

@ -98,7 +98,12 @@ func InitAPNSClient() error {
}
}
if ext == ".p8" && PushConf.Ios.KeyID != "" && PushConf.Ios.TeamID != "" {
if ext == ".p8" {
if PushConf.Ios.KeyID == "" || PushConf.Ios.TeamID == "" {
msg := "You should provide ios.KeyID and ios.TeamID for P8 token"
LogError.Error(msg)
return errors.New(msg)
}
token := &token.Token{
AuthKey: authKey,
// KeyID from developer account (Certificates, Identifiers & Profiles -> Keys)

View File

@ -609,6 +609,22 @@ func TestAPNSClientInvaildToken(t *testing.T) {
PushConf.Ios.KeyType = "p8"
err = InitAPNSClient()
assert.Error(t, err)
//empty key-id or team-id
PushConf.Ios.Enabled = true
PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8"
err = InitAPNSClient()
assert.Error(t, err)
PushConf.Ios.KeyID = "key-id"
PushConf.Ios.TeamID = ""
err = InitAPNSClient()
assert.Error(t, err)
PushConf.Ios.KeyID = ""
PushConf.Ios.TeamID = "team-id"
err = InitAPNSClient()
assert.Error(t, err)
}
func TestAPNSClientVaildToken(t *testing.T) {
@ -616,6 +632,8 @@ func TestAPNSClientVaildToken(t *testing.T) {
PushConf.Ios.Enabled = true
PushConf.Ios.KeyPath = "../certificate/authkey-valid.p8"
PushConf.Ios.KeyID = "key-id"
PushConf.Ios.TeamID = "team-id"
err := InitAPNSClient()
assert.NoError(t, err)
assert.Equal(t, apns2.HostDevelopment, ApnsClient.Host)

10
main.go
View File

@ -60,6 +60,8 @@ func main() {
flag.StringVar(&opts.Core.PID.Path, "pid", "", "PID file path.")
flag.StringVar(&opts.Ios.KeyPath, "i", "", "iOS certificate key file path")
flag.StringVar(&opts.Ios.KeyPath, "key", "", "iOS certificate key file path")
flag.StringVar(&opts.Ios.KeyID, "key-id", "", "iOS Key ID for P8 token")
flag.StringVar(&opts.Ios.TeamID, "team-id", "", "iOS Team ID for P8 token")
flag.StringVar(&opts.Ios.Password, "P", "", "iOS certificate password for gorush")
flag.StringVar(&opts.Ios.Password, "password", "", "iOS certificate password for gorush")
flag.StringVar(&opts.Android.APIKey, "k", "", "Android api key configuration for gorush")
@ -111,6 +113,14 @@ func main() {
gorush.PushConf.Ios.KeyPath = opts.Ios.KeyPath
}
if opts.Ios.KeyID != "" {
gorush.PushConf.Ios.KeyID = opts.Ios.KeyID
}
if opts.Ios.TeamID != "" {
gorush.PushConf.Ios.TeamID = opts.Ios.TeamID
}
if opts.Ios.Password != "" {
gorush.PushConf.Ios.Password = opts.Ios.Password
}