Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Oct 22, 2023
1 parent 852d066 commit 43ffb20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions server/backend/ios_notifications/apns/jwt_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type JWTToken struct {
}

func NewToken() (*JWTToken, error) {
encryptionKey, err := APNsEncryptionKeyFromFile()
encryptionKey, err := EncryptionKeyFromFile()
if err != nil {
return nil, err
}
Expand All @@ -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 {
Expand Down
17 changes: 5 additions & 12 deletions server/backend/ios_notifications/apns/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 43ffb20

Please sign in to comment.