Skip to content

Commit

Permalink
telophase: use helper for valid token
Browse files Browse the repository at this point in the history
We want to ensure the same rules are being used when checking if a token
is ignored.

Before this would result in the error:

error creating account in telophase: {"error":"invalid token"}
  • Loading branch information
dschofie committed Dec 18, 2023
1 parent cbb22ed commit d927258
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"

"github.com/santiago-labs/telophasecli/lib/metrics"
"github.com/santiago-labs/telophasecli/lib/telophase"
"github.com/spf13/cobra"
)

Expand All @@ -22,7 +23,7 @@ func Execute() {
metrics.RegisterCommand()
defer metrics.Close()

if os.Getenv("TELOPHASE_TOKEN") == "" && os.Getenv("TELOPHASE_TOKEN") != "ignore" {
if !telophase.ValidTelophaseToken(os.Getenv("TELOPHASE_TOKEN")) {
fmt.Println("(Optional) Signup for Telophase for an even better experience! https://app.telophase.dev. Set TELOPHASE_TOKEN=ignore in your env to hide this message.")
}

Expand Down
13 changes: 11 additions & 2 deletions lib/telophase/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ import (
"os"
)

func ValidTelophaseToken(token string) bool {
if token == "" ||
token == "ignore" {
return false
}

return true
}

func UpsertAccount(accountID string, accountName string) {
token := os.Getenv("TELOPHASE_TOKEN")
if token != "" {
if ValidTelophaseToken(token) {
reqBody, _ := json.Marshal(map[string]string{
"account_id": accountID,
"name": accountName,
Expand All @@ -37,7 +46,7 @@ func UpsertAccount(accountID string, accountName string) {

func RecordDeploy(accountID string, accountName string) {
token := os.Getenv("TELOPHASE_TOKEN")
if token != "" {
if ValidTelophaseToken(token) {
reqBody, _ := json.Marshal(map[string]string{})
client := &http.Client{}
req, _ := http.NewRequest("PATCH", fmt.Sprintf("https://api.telophase.dev/cloudAccount/%s", accountID), bytes.NewBuffer(reqBody))
Expand Down

0 comments on commit d927258

Please sign in to comment.