Skip to content

Commit

Permalink
Merge pull request #2826 from manuelsc/nobids/filerework
Browse files Browse the repository at this point in the history
Allow Apple and Google secrets to be used directly rather than only via file
  • Loading branch information
recy21 authored Jan 25, 2024
2 parents c164b61 + 13c145a commit 9adaa87
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
33 changes: 27 additions & 6 deletions exporter/appsubscription_oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,41 @@ func VerifyReceipt(googleClient *playstore.Client, appleClient *api.StoreClient,
}

func initGoogle() (*playstore.Client, error) {
jsonKey, err := os.ReadFile(utils.Config.Frontend.AppSubsGoogleJSONPath)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Can not read google json key file %v", utils.Config.Frontend.AppSubsGoogleJSONPath))
if len(utils.Config.Frontend.AppSubsGoogleJSONPath) == 0 {
return nil, errors.New("google app subs json path not set")
}

var jsonKey []byte
var err error
if strings.Contains(utils.Config.Frontend.AppSubsGoogleJSONPath, ".json") {
jsonKey, err = os.ReadFile(utils.Config.Frontend.AppSubsGoogleJSONPath)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("Can not read google json key file %v", utils.Config.Frontend.AppSubsGoogleJSONPath))
}
} else {
jsonKey = []byte(utils.Config.Frontend.AppSubsGoogleJSONPath)
}

client, err := playstore.New(jsonKey)
return client, err
}

func initApple() (*api.StoreClient, error) {
keyContent, err := os.ReadFile(utils.Config.Frontend.Apple.Certificate)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("can not load apple certificate for file %v", utils.Config.Frontend.Apple.Certificate))
if len(utils.Config.Frontend.Apple.Certificate) == 0 {
return nil, errors.New("apple certificate path not set")
}

var keyContent []byte
var err error
if strings.Contains(utils.Config.Frontend.Apple.Certificate, "BEGIN PRIVATE KEY") {
keyContent = []byte(utils.Config.Frontend.Apple.Certificate)
} else {
keyContent, err = os.ReadFile(utils.Config.Frontend.Apple.Certificate)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("can not load apple certificate for file %v", utils.Config.Frontend.Apple.Certificate))
}
}

return api.NewStoreClient(&api.StoreConfig{
KeyContent: keyContent, // Loads a .p8 certificate
KeyID: utils.Config.Frontend.Apple.KeyID, // Your private key ID from App Store Connect (Ex: 2X9R4HXF34)
Expand Down
11 changes: 3 additions & 8 deletions notify/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package notify
import (
"context"
"eth2-exporter/utils"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -36,14 +35,10 @@ func SendPushBatch(messages []*messaging.Message) error {
ctx := context.Background()
var opt option.ClientOption

if strings.HasPrefix(credentialsPath, "projects/") {
x, err := utils.AccessSecretVersion(credentialsPath)
if err != nil {
return fmt.Errorf("error getting firebase config from secret store: %v", err)
}
opt = option.WithCredentialsJSON([]byte(*x))
} else {
if strings.Contains(credentialsPath, ".json") && len(credentialsPath) < 200 {
opt = option.WithCredentialsFile(credentialsPath)
} else {
opt = option.WithCredentialsJSON([]byte(credentialsPath))
}

app, err := firebase.NewApp(context.Background(), nil, opt)
Expand Down

0 comments on commit 9adaa87

Please sign in to comment.