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

feat: Detokenize ngrok #784

Merged
merged 1 commit into from
Nov 30, 2022
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
3 changes: 1 addition & 2 deletions cmd/local/local.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package local

import (
"context"
"fmt"
"log"
"sync"
Expand Down Expand Up @@ -99,7 +98,7 @@ func runLocal(cmd *cobra.Command, args []string) error {

// todo need to add go channel to control when ngrok should close
// and use context to handle closing the open goroutine/connection
go pkg.RunNgrok(context.TODO(), pkg.LocalAtlantisURL)
//go pkg.RunNgrok(context.TODO(), pkg.LocalAtlantisURL)

if !viper.GetBool("kubefirst.done") {
if viper.GetString("gitprovider") == "github" {
Expand Down
9 changes: 6 additions & 3 deletions cmd/local/prerun.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package local

import (
"context"
"fmt"
"log"
"net/http"
"time"

"github.com/dustin/go-humanize"
"github.com/kubefirst/kubefirst/configs"
"github.com/kubefirst/kubefirst/internal/addon"
Expand All @@ -14,9 +19,6 @@ import (
"github.com/kubefirst/kubefirst/pkg"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"log"
"net/http"
"time"
)

func validateLocal(cmd *cobra.Command, args []string) error {
Expand Down Expand Up @@ -77,6 +79,7 @@ func validateLocal(cmd *cobra.Command, args []string) error {

viper.Set("argocd.local.service", pkg.ArgoCDLocalURL)
viper.Set("vault.local.service", pkg.VaultLocalURL)
go pkg.RunNgrok(context.TODO(), pkg.AtlantisLocalURL)

// addons
addon.AddAddon("github")
Expand Down
2 changes: 2 additions & 0 deletions pkg/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error {
githubRepoOwner := viper.GetString("github.owner")
githubOrg := viper.GetString("github.owner")
githubUser := viper.GetString("github.user")
ngrokUrl := viper.GetString("ngrok.url")

githubToken := os.Getenv("KUBEFIRST_GITHUB_AUTH_TOKEN")

Expand All @@ -147,6 +148,7 @@ func DetokenizeDirectory(path string, fi os.FileInfo, err error) error {
newContents = strings.Replace(newContents, "<GITHUB_USER>", githubUser, -1)
newContents = strings.Replace(newContents, "<GITHUB_TOKEN>", githubToken, -1)
newContents = strings.Replace(newContents, "<KUBEFIRST_VERSION>", configs.K1Version, -1)
newContents = strings.Replace(newContents, "<NGROK_HOST>", ngrokUrl, -1)

var repoPathHTTPS string
var repoPathSSH string
Expand Down
8 changes: 5 additions & 3 deletions pkg/ngrok.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package pkg
import (
"context"
"fmt"
"io"
"log"
"net"

"github.com/ngrok/ngrok-go"
"github.com/ngrok/ngrok-go/config"
"github.com/spf13/viper"
"golang.org/x/sync/errgroup"
"io"
"log"
"net"
)

func RunNgrok(ctx context.Context, dest string) {
Expand All @@ -29,6 +30,7 @@ func RunNgrok(ctx context.Context, dest string) {

fmt.Println("tunnel created: ", tunnel.URL())
viper.Set("github.atlantis.webhook.url", tunnel.URL()+"/events")
viper.Set("ngrok.url", tunnel.URL())
viper.WriteConfig()

for {
Expand Down