diff --git a/server/backend/ios_notifications/apns/jwt_token.go b/server/backend/ios_notifications/apns/jwt_token.go index ed31a089..7e4df0c5 100644 --- a/server/backend/ios_notifications/apns/jwt_token.go +++ b/server/backend/ios_notifications/apns/jwt_token.go @@ -25,7 +25,7 @@ type JWTToken struct { } func NewToken() (*JWTToken, error) { - encryptionKey, err := APNsEncryptionKeyFromFile() + encryptionKey, err := EncryptionKeyFromFile() if err != nil { return nil, err } @@ -43,10 +43,10 @@ func NewToken() (*JWTToken, error) { return &token, nil } -// APNsEncryptionKeyFromFile reads the APNs encryption key from the file system +// EncryptionKeyFromFile reads the APNs encryption key from the file system // and returns it as an ecdsa.PrivateKey // The file location is defined by the APNS_P8_FILE_PATH environment variable -func APNsEncryptionKeyFromFile() (*ecdsa.PrivateKey, error) { +func EncryptionKeyFromFile() (*ecdsa.PrivateKey, error) { path, err := filepath.Abs(os.Getenv("APNS_P8_FILE_PATH")) if err != nil { diff --git a/server/backend/ios_notifications/apns/service.go b/server/backend/ios_notifications/apns/service.go index 1a285b7e..27700525 100644 --- a/server/backend/ios_notifications/apns/service.go +++ b/server/backend/ios_notifications/apns/service.go @@ -41,22 +41,15 @@ func (s *Service) RequestGradeUpdateForDevice(deviceID string) error { } func ValidateRequirementsForIOSNotificationsService() error { - if os.Getenv("APNS_KEY_ID") == "" { - return errors.New("APNS_KEY_ID env variable is not set") + for _, envVar := range []string{"APNS_KEY_ID", "APNS_TEAM_ID", "APNS_P8_FILE_PATH"} { + if os.Getenv(envVar) == "" { + return errors.New(envVar + " env variable is not set") + } } - if os.Getenv("APNS_TEAM_ID") == "" { - return errors.New("APNS_TEAM_ID env variable is not set") - } - - if os.Getenv("APNS_P8_FILE_PATH") == "" { - return errors.New("APNS_P8_FILE_PATH env variable is not set") - } - - if _, err := APNsEncryptionKeyFromFile(); err != nil { + if _, err := EncryptionKeyFromFile(); err != nil { return errors.New("APNS P8 token is not valid or not set") } - return nil }