github.com/pluralsh/plural-cli@v0.9.5/pkg/proxy/web.go (about)

     1  package proxy
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	"github.com/pluralsh/plural-cli/pkg/kubernetes"
     8  	"github.com/pluralsh/plural-cli/pkg/utils"
     9  	"github.com/pluralsh/plural-operator/apis/platform/v1alpha1"
    10  )
    11  
    12  func execWeb(namespace string, proxy *v1alpha1.Proxy, kube kubernetes.Kube) error {
    13  	config := proxy.Spec.WebConfig
    14  	err := portForward(namespace, proxy, config.Port)
    15  	if err != nil {
    16  		return err
    17  	}
    18  
    19  	utils.Highlight("Wait a bit while the port-forward boots up\n\n")
    20  	time.Sleep(5 * time.Second)
    21  
    22  	if err := printCredentials(proxy, namespace, kube); err != nil {
    23  		return err
    24  	}
    25  	fmt.Printf("\nVisit http://localhost:%d%s\n", config.Port, config.Path)
    26  	if _, err := utils.ReadLine("Press enter to close the proxy"); err != nil {
    27  		return err
    28  	}
    29  	return nil
    30  }
    31  
    32  func printCredentials(proxy *v1alpha1.Proxy, namespace string, kube kubernetes.Kube) error {
    33  	creds := proxy.Spec.Credentials
    34  	if creds == nil {
    35  		return nil
    36  	}
    37  
    38  	secret, err := kube.Secret(namespace, creds.Secret)
    39  	if err != nil {
    40  		return err
    41  	}
    42  	user, err := fetchUserPassword(secret, creds)
    43  	if err != nil {
    44  		return err
    45  	}
    46  
    47  	highlightedEntry("Username", user.User)
    48  	highlightedEntry("Password", user.Password)
    49  
    50  	return nil
    51  }
    52  
    53  func highlightedEntry(label, value string) {
    54  	utils.Highlight(label + ": ")
    55  	fmt.Println(value)
    56  }