mirror of
https://github.com/openziti/zrok.git
synced 2025-02-03 03:50:08 +01:00
error handing for '--subordinate' in 'zrok access private' (#789)
This commit is contained in:
parent
f00835d68b
commit
1face3bb86
@ -44,6 +44,7 @@ func (i *agentGrpcImpl) AccessPrivate(_ context.Context, req *agentGrpc.AccessPr
|
|||||||
|
|
||||||
acc.process, err = proctree.StartChild(acc.tail, accCmd...)
|
acc.process, err = proctree.StartChild(acc.tail, accCmd...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logrus.Errorf("child start '%v': %v", accCmd, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,6 +79,9 @@ func newAccessPrivateCommand() *accessPrivateCommand {
|
|||||||
func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
||||||
root, err := environment.LoadRoot()
|
root, err := environment.LoadRoot()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("error loading environment", err)
|
tui.Error("error loading environment", err)
|
||||||
}
|
}
|
||||||
@ -126,6 +129,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
accessResp, err := zrok.Share.Access(req, auth)
|
accessResp, err := zrok.Share.Access(req, auth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to access", err)
|
tui.Error("unable to access", err)
|
||||||
}
|
}
|
||||||
@ -136,6 +142,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
if cmd.autoMode {
|
if cmd.autoMode {
|
||||||
if accessResp.Payload.BackendMode == "udpTunnel" {
|
if accessResp.Payload.BackendMode == "udpTunnel" {
|
||||||
cmd.destroy(accessResp.Payload.FrontendToken, root.Environment().ZitiIdentity, shrToken, zrok, auth)
|
cmd.destroy(accessResp.Payload.FrontendToken, root.Environment().ZitiIdentity, shrToken, zrok, auth)
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(errors.New("auto-addressing is not compatible with the 'udpTunnel' backend mode"))
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("auto-addressing is not compatible with the 'udpTunnel' backend mode", nil)
|
tui.Error("auto-addressing is not compatible with the 'udpTunnel' backend mode", nil)
|
||||||
}
|
}
|
||||||
@ -143,24 +152,15 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
autoAddress, err := util.AutoListenerAddress("tcp", cmd.autoAddress, cmd.autoStartPort, cmd.autoEndPort)
|
autoAddress, err := util.AutoListenerAddress("tcp", cmd.autoAddress, cmd.autoStartPort, cmd.autoEndPort)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to automatically find a listener address: %v", err)
|
tui.Error("unable to automatically find a listener address: %v", err)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
bindAddress = autoAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmd.subordinate {
|
|
||||||
data := make(map[string]interface{})
|
|
||||||
data["frontend_token"] = accessResp.Payload.FrontendToken
|
|
||||||
data["bind_address"] = bindAddress
|
|
||||||
jsonData, err := json.Marshal(data)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
fmt.Println(string(jsonData))
|
bindAddress = autoAddress
|
||||||
} else {
|
|
||||||
logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol := "http://"
|
protocol := "http://"
|
||||||
@ -173,6 +173,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
|
|
||||||
endpointUrl, err := url.Parse(protocol + bindAddress)
|
endpointUrl, err := url.Parse(protocol + bindAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("invalid endpoint address", err)
|
tui.Error("invalid endpoint address", err)
|
||||||
}
|
}
|
||||||
@ -189,6 +192,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
RequestsChan: requests,
|
RequestsChan: requests,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create private access", err)
|
tui.Error("unable to create private access", err)
|
||||||
}
|
}
|
||||||
@ -196,6 +202,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("error starting access", err)
|
tui.Error("error starting access", err)
|
||||||
}
|
}
|
||||||
@ -212,6 +221,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
IdleTime: time.Minute,
|
IdleTime: time.Minute,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create private frontend", err)
|
tui.Error("unable to create private frontend", err)
|
||||||
}
|
}
|
||||||
@ -219,6 +231,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("error starting frontend", err)
|
tui.Error("error starting frontend", err)
|
||||||
}
|
}
|
||||||
@ -234,6 +249,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
RequestsChan: requests,
|
RequestsChan: requests,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create private access", err)
|
tui.Error("unable to create private access", err)
|
||||||
}
|
}
|
||||||
@ -241,6 +259,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("error starting access", err)
|
tui.Error("error starting access", err)
|
||||||
}
|
}
|
||||||
@ -258,6 +279,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
RequestsChan: requests,
|
RequestsChan: requests,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create private access", err)
|
tui.Error("unable to create private access", err)
|
||||||
}
|
}
|
||||||
@ -265,6 +289,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("error starting access", err)
|
tui.Error("error starting access", err)
|
||||||
}
|
}
|
||||||
@ -280,6 +307,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
cfg.RequestsChan = requests
|
cfg.RequestsChan = requests
|
||||||
fe, err := proxy.NewFrontend(cfg)
|
fe, err := proxy.NewFrontend(cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to create private frontend", err)
|
tui.Error("unable to create private frontend", err)
|
||||||
}
|
}
|
||||||
@ -287,6 +317,9 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
}
|
}
|
||||||
go func() {
|
go func() {
|
||||||
if err := fe.Run(); err != nil {
|
if err := fe.Run(); err != nil {
|
||||||
|
if cmd.subordinate {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
if !panicInstead {
|
if !panicInstead {
|
||||||
tui.Error("unable to run frontend", err)
|
tui.Error("unable to run frontend", err)
|
||||||
}
|
}
|
||||||
@ -302,6 +335,17 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if cmd.subordinate {
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
data["frontend_token"] = accessResp.Payload.FrontendToken
|
||||||
|
data["bind_address"] = bindAddress
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
subordinateError(err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(jsonData))
|
||||||
|
}
|
||||||
|
|
||||||
if cmd.headless {
|
if cmd.headless {
|
||||||
logrus.Infof("access the zrok share at the following endpoint: %v", endpointUrl.String())
|
logrus.Infof("access the zrok share at the following endpoint: %v", endpointUrl.String())
|
||||||
for {
|
for {
|
||||||
@ -310,7 +354,6 @@ func (cmd *accessPrivateCommand) accessLocal(args []string, root env_core.Root)
|
|||||||
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
|
logrus.Infof("%v -> %v %v", req.RemoteAddr, req.Method, req.Path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if cmd.subordinate {
|
} else if cmd.subordinate {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -30,8 +30,8 @@ func newAgentStartCommand() *agentStartCommand {
|
|||||||
command := &agentStartCommand{cmd: cmd}
|
command := &agentStartCommand{cmd: cmd}
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
cmd.Flags().StringVar(&command.consoleAddress, "console-address", "127.0.0.1", "gRPC gateway address")
|
cmd.Flags().StringVar(&command.consoleAddress, "console-address", "127.0.0.1", "gRPC gateway address")
|
||||||
cmd.Flags().Uint16Var(&command.consoleStartPort, "console-start-port", 8080, "gRPC gateway starting port")
|
cmd.Flags().Uint16Var(&command.consoleStartPort, "console-start-port", 8888, "gRPC gateway starting port")
|
||||||
cmd.Flags().Uint16Var(&command.consoleEndPort, "console-end-port", 8181, "gRPC gateway ending port")
|
cmd.Flags().Uint16Var(&command.consoleEndPort, "console-end-port", 8988, "gRPC gateway ending port")
|
||||||
return command
|
return command
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,3 +45,8 @@ func parseUrl(in string) (string, error) {
|
|||||||
|
|
||||||
return targetEndpoint.String(), nil
|
return targetEndpoint.String(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func subordinateError(err error) {
|
||||||
|
fmt.Printf("{ \"error\": \"%v\" }\n", err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user