mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
Merge branch 'main' into websockets
This commit is contained in:
commit
4ccff8c1d5
@ -1,5 +1,9 @@
|
||||
# v0.3.2
|
||||
|
||||
CHANGE: Include missing `--headless` flag for `zrok enable` and `zrok access private` (https://github.com/openziti/zrok/issues/246)
|
||||
|
||||
CHANGE: Fix for `zrok enable` error path handling (https://github.com/openziti/zrok/issues/244)
|
||||
|
||||
FEATURE: `zrok controller validate` and `zrok access public validate` will both perform a quick syntax validation on controller and public frontend configuration documents (https://github.com/openziti/zrok/issues/238)
|
||||
|
||||
$ zrok controller validate etc/dev.yml
|
||||
|
@ -24,8 +24,9 @@ func init() {
|
||||
}
|
||||
|
||||
type accessPrivateCommand struct {
|
||||
cmd *cobra.Command
|
||||
bindAddress string
|
||||
headless bool
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
func newAccessPrivateCommand() *accessPrivateCommand {
|
||||
@ -35,6 +36,7 @@ func newAccessPrivateCommand() *accessPrivateCommand {
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &accessPrivateCommand{cmd: cmd}
|
||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||
cmd.Run = command.run
|
||||
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
|
||||
return command
|
||||
@ -112,28 +114,40 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
}()
|
||||
|
||||
mdl := newAccessModel(shrToken, endpointUrl.String())
|
||||
logrus.SetOutput(mdl)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
mdl.prg = prg
|
||||
|
||||
go func() {
|
||||
if cmd.headless {
|
||||
logrus.Infof("access the zrok share at the followind endpoint: %v", endpointUrl.String())
|
||||
for {
|
||||
select {
|
||||
case req := <-cfg.RequestsChan:
|
||||
if req != nil {
|
||||
prg.Send(req)
|
||||
}
|
||||
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := prg.Run(); err != nil {
|
||||
tui.Error("An error occurred", err)
|
||||
} else {
|
||||
mdl := newAccessModel(shrToken, endpointUrl.String())
|
||||
logrus.SetOutput(mdl)
|
||||
prg := tea.NewProgram(mdl, tea.WithAltScreen())
|
||||
mdl.prg = prg
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case req := <-cfg.RequestsChan:
|
||||
if req != nil {
|
||||
prg.Send(req)
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err := prg.Run(); err != nil {
|
||||
tui.Error("An error occurred", err)
|
||||
}
|
||||
|
||||
close(cfg.RequestsChan)
|
||||
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
|
||||
|
||||
}
|
||||
|
||||
close(cfg.RequestsChan)
|
||||
cmd.destroy(accessResp.Payload.FrontendToken, zrd.Env.ZId, shrToken, zrok, auth)
|
||||
}
|
||||
|
||||
func (cmd *accessPrivateCommand) destroy(frotendName, envZId, shrToken string, zrok *rest_client_zrok.Zrok, auth runtime.ClientAuthInfoWriter) {
|
||||
|
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"os"
|
||||
user2 "os/user"
|
||||
"time"
|
||||
@ -23,6 +24,7 @@ func init() {
|
||||
|
||||
type enableCommand struct {
|
||||
description string
|
||||
headless bool
|
||||
cmd *cobra.Command
|
||||
}
|
||||
|
||||
@ -33,6 +35,7 @@ func newEnableCommand() *enableCommand {
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
command := &enableCommand{cmd: cmd}
|
||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||
cmd.Flags().StringVarP(&command.description, "description", "d", "<user>@<hostname>", "Description of this environment")
|
||||
cmd.Run = command.run
|
||||
return command
|
||||
@ -74,50 +77,84 @@ func (cmd *enableCommand) run(_ *cobra.Command, args []string) {
|
||||
}
|
||||
|
||||
var prg *tea.Program
|
||||
var mdl enableTuiModel
|
||||
var done = make(chan struct{})
|
||||
go func() {
|
||||
mdl = newEnableTuiModel()
|
||||
mdl.msg = "contacting the zrok service..."
|
||||
prg = tea.NewProgram(mdl)
|
||||
if _, err := prg.Run(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
close(done)
|
||||
if mdl.quitting {
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
if !cmd.headless {
|
||||
var mdl enableTuiModel
|
||||
go func() {
|
||||
mdl = newEnableTuiModel()
|
||||
mdl.msg = "contacting the zrok service..."
|
||||
prg = tea.NewProgram(mdl)
|
||||
if _, err := prg.Run(); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
close(done)
|
||||
if mdl.quitting {
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
} else {
|
||||
logrus.Infof("contacting the zrok service...")
|
||||
}
|
||||
|
||||
resp, err := zrok.Environment.Enable(req, auth)
|
||||
//Switch on err type (401, 400, 500, etc...)
|
||||
if err != nil {
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
prg.Send(fmt.Sprintf("the zrok service returned an error: %v\n", err))
|
||||
prg.Quit()
|
||||
<-done
|
||||
if !cmd.headless && prg != nil {
|
||||
prg.Send(fmt.Sprintf("the zrok service returned an error: %v\n", err))
|
||||
prg.Quit()
|
||||
} else {
|
||||
logrus.Errorf("the zrok service returned an error: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
cmd.endpointError(zrd.ApiEndpoint())
|
||||
os.Exit(1)
|
||||
}
|
||||
prg.Send("writing the environment details...")
|
||||
if err != nil {
|
||||
prg.Send("writing the environment details...")
|
||||
}
|
||||
apiEndpoint, _ := zrd.ApiEndpoint()
|
||||
zrd.Env = &zrokdir.Environment{Token: token, ZId: resp.Payload.Identity, ApiEndpoint: apiEndpoint}
|
||||
if err := zrd.Save(); err != nil {
|
||||
prg.Send(fmt.Sprintf("there was an error saving the new environment: %v", err))
|
||||
prg.Quit()
|
||||
<-done
|
||||
if !cmd.headless && prg != nil {
|
||||
prg.Send(fmt.Sprintf("there was an error saving the new environment: %v", err))
|
||||
prg.Quit()
|
||||
} else {
|
||||
logrus.Errorf("there was an error saving the new environment: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := zrokdir.SaveZitiIdentity("backend", resp.Payload.Cfg); err != nil {
|
||||
prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err))
|
||||
prg.Quit()
|
||||
<-done
|
||||
if !cmd.headless && prg != nil {
|
||||
prg.Send(fmt.Sprintf("there was an error writing the environment: %v", err))
|
||||
prg.Quit()
|
||||
} else {
|
||||
logrus.Errorf("there was an error writing the environment: %v", err)
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
prg.Send(fmt.Sprintf("the zrok environment was successfully enabled..."))
|
||||
prg.Quit()
|
||||
<-done
|
||||
if !cmd.headless && prg != nil {
|
||||
prg.Send(fmt.Sprintf("the zrok environment was successfully enabled..."))
|
||||
prg.Quit()
|
||||
} else {
|
||||
logrus.Infof("the zrok environment was successfully enabled...")
|
||||
}
|
||||
select {
|
||||
case <-done:
|
||||
case <-time.After(1 * time.Second):
|
||||
}
|
||||
}
|
||||
|
||||
func (cmd *enableCommand) endpointError(apiEndpoint, _ string) {
|
||||
|
Loading…
Reference in New Issue
Block a user