Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Apple and Google secrets to be used directly rather than only via file #2826

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading