Skip to content

Commit

Permalink
removed firebase public key from repo
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodeassassin committed Nov 22, 2022
1 parent 98174a0 commit 003f190
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,5 @@ jobs:
args: release --rm-dist
env:
GPG_FINGERPRINT: ${{ steps.import_gpg.outputs.fingerprint }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
FIREBASE_TOKEN: ${{ secrets.FIREBASE_TOKEN }}
1 change: 1 addition & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ builds:
- darwin
ldflags:
- -X github.com/symbiosis-cloud/cli/commands.Version={{ .Version }}
- -X github.com/symbiosis-cloud/cli/pkg/util/firebase.FirebaseToken={{ .Env.FIREBASE_TOKEN }}
archives:
- replacements:
darwin: Darwin
Expand Down
9 changes: 4 additions & 5 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,14 @@ import (
"path/filepath"
"strings"

"github.com/jedib0t/go-pretty/v6/text"
"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/symbiosis-cloud/cli/pkg/symcommand"
"github.com/symbiosis-cloud/cli/pkg/util"
)

const (
VERSION = "v0.0.2"
)

var (
EnableBetaCommands bool
commands []symcommand.Command
Expand Down Expand Up @@ -89,7 +86,9 @@ func init() {
// TODO: find a way to toggle beta commands via a flag
if os.Getenv("SYM_BETA") != "" {
commands = append(commands, betaCommands...)
fmt.Println("You enabled beta commands, these are currently not considered fully functional so use with caution.")
defer text.EnableColors()

fmt.Printf("%s** NOTE ** You enabled beta commands, these are currently not considered fully functional so use with caution.%s\n", text.FgRed.EscapeSeq(), text.FgWhite.EscapeSeq())
}

for _, command := range commands {
Expand Down
14 changes: 13 additions & 1 deletion pkg/util/firebase/firebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"os"
"time"

"github.com/golang-jwt/jwt/v4"
Expand All @@ -22,6 +23,10 @@ type Token struct {
ProjectID string `json:"project_id"`
}

var (
FirebaseToken string
)

func ValidateToken() error {
if viper.GetString("auth.method") == "token" {
claims := jwt.MapClaims{}
Expand All @@ -36,10 +41,17 @@ func ValidateToken() error {
timeSec := time.Unix(int64(claims["exp"].(float64)), 0)
tokenExpired := time.Now().UTC().After(timeSec.UTC())

if FirebaseToken == "" {
FirebaseToken = os.Getenv("FIREBASE_TOKEN")
if FirebaseToken == "" {
return fmt.Errorf("Firebase token not set...")
}
}

// if the access token has expired we have to renew it
if tokenExpired {
payload := bytes.NewBufferString(fmt.Sprintf("grant_type=refresh_token&refresh_token=%s", viper.GetString("auth.refresh_token")))
res, err := http.Post("https://securetoken.googleapis.com/v1/token?key=AIzaSyBbGgIU15KOodwZXwH_e0OpKWLwt0udAz0", "application/x-www-form-urlencoded", payload)
res, err := http.Post("https://securetoken.googleapis.com/v1/token?key="+FirebaseToken, "application/x-www-form-urlencoded", payload)

if err != nil {
return err
Expand Down

0 comments on commit 003f190

Please sign in to comment.