Просмотр исходного кода

auto-open browser from the CLI and query param on /login for email auto population

sunguroku 5 лет назад
Родитель
Сommit
2fe81c4af4

+ 24 - 0
cli/cmd/start.go

@@ -3,7 +3,10 @@ package cmd
 import (
 	"fmt"
 	"os"
+	"os/exec"
 	"path/filepath"
+	"runtime"
+	"time"
 
 	"github.com/porter-dev/porter/cli/cmd/docker"
 	"k8s.io/client-go/util/homedir"
@@ -300,9 +303,30 @@ func start(
 		return err
 	}
 
+	fmt.Println("Spinning up the Server...")
+	time.Sleep(7 * time.Second)
+	openBrowser(fmt.Sprintf("http://localhost:%d/login?email=%s", port, username))
 	fmt.Printf("Server ready: listening on localhost:%d\n", port)
 
 	agent.WaitForContainerStop(id)
 
 	return nil
 }
+
+// openBrowser opens the specified URL in the default browser of the user.
+func openBrowser(url string) error {
+	var cmd string
+	var args []string
+
+	switch runtime.GOOS {
+	case "windows":
+		cmd = "cmd"
+		args = []string{"/c", "start"}
+	case "darwin":
+		cmd = "open"
+	default: // "linux", "freebsd", "openbsd", "netbsd"
+		cmd = "xdg-open"
+	}
+	args = append(args, url)
+	return exec.Command(cmd, args...).Start()
+}

+ 3 - 0
dashboard/src/main/Login.tsx

@@ -30,6 +30,9 @@ export default class Login extends Component<PropsType, StateType> {
   }
 
   componentDidMount() {
+    let urlParams = new URLSearchParams(window.location.search);
+    let emailFromCLI = urlParams.get('email');
+    emailFromCLI ? this.setState({email: emailFromCLI}) :
     document.addEventListener("keydown", this.handleKeyDown);
   }
 

+ 2 - 2
dashboard/src/main/home/dashboard/expanded-chart/ExpandedChart.tsx

@@ -46,7 +46,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
       namespace: currentChart.namespace,
       context: currentCluster,
       storage: StorageType.Secret
-    }, { name: currentChart.name, revision: 0 }, (err: any, res: any) => {
+    }, { name: currentChart.name, revision: currentChart.version }, (err: any, res: any) => {
       if (err) {
         console.log(err)
       } else {
@@ -74,7 +74,7 @@ export default class ExpandedChart extends Component<PropsType, StateType> {
 
   renderTabContents = () => {
     let { currentChart, refreshChart, setSidebar} = this.props;
-    
+
     if (this.state.currentTab === 'graph') {
       return (
         <GraphSection