mirror of
https://github.com/openziti/zrok.git
synced 2025-02-03 20:10:13 +01:00
'--agent' for 'zrok access private' (#748)
This commit is contained in:
parent
9d829c173a
commit
e6a74ad5f3
@ -1,6 +1,8 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
"github.com/go-openapi/runtime"
|
"github.com/go-openapi/runtime"
|
||||||
httptransport "github.com/go-openapi/runtime/client"
|
httptransport "github.com/go-openapi/runtime/client"
|
||||||
@ -30,6 +32,7 @@ func init() {
|
|||||||
type accessPrivateCommand struct {
|
type accessPrivateCommand struct {
|
||||||
bindAddress string
|
bindAddress string
|
||||||
headless bool
|
headless bool
|
||||||
|
agent bool
|
||||||
responseHeaders []string
|
responseHeaders []string
|
||||||
cmd *cobra.Command
|
cmd *cobra.Command
|
||||||
}
|
}
|
||||||
@ -42,6 +45,8 @@ func newAccessPrivateCommand() *accessPrivateCommand {
|
|||||||
}
|
}
|
||||||
command := &accessPrivateCommand{cmd: cmd}
|
command := &accessPrivateCommand{cmd: cmd}
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
||||||
|
cmd.Flags().BoolVar(&command.agent, "agent", false, "Enable agent mode")
|
||||||
|
cmd.MarkFlagsMutuallyExclusive("headless", "agent")
|
||||||
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
|
cmd.Flags().StringVarP(&command.bindAddress, "bind", "b", "127.0.0.1:9191", "The address to bind the private frontend")
|
||||||
cmd.Flags().StringArrayVar(&command.responseHeaders, "response-header", []string{}, "Add a response header ('key:value')")
|
cmd.Flags().StringArrayVar(&command.responseHeaders, "response-header", []string{}, "Add a response header ('key:value')")
|
||||||
cmd.Run = command.run
|
cmd.Run = command.run
|
||||||
@ -81,7 +86,19 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken)
|
|
||||||
|
if cmd.agent {
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
data["frontend-token"] = accessResp.Payload.FrontendToken
|
||||||
|
data["bind-address"] = cmd.bindAddress
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(jsonData))
|
||||||
|
} else {
|
||||||
|
logrus.Infof("allocated frontend '%v'", accessResp.Payload.FrontendToken)
|
||||||
|
}
|
||||||
|
|
||||||
protocol := "http://"
|
protocol := "http://"
|
||||||
switch accessResp.Payload.BackendMode {
|
switch accessResp.Payload.BackendMode {
|
||||||
@ -231,6 +248,21 @@ func (cmd *accessPrivateCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} else if cmd.agent {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case req := <-requests:
|
||||||
|
data := make(map[string]interface{})
|
||||||
|
data["remote-address"] = req.RemoteAddr
|
||||||
|
data["method"] = req.Method
|
||||||
|
data["path"] = req.Path
|
||||||
|
jsonData, err := json.Marshal(data)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
}
|
||||||
|
fmt.Println(string(jsonData))
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
mdl := newAccessModel(shrToken, endpointUrl.String())
|
mdl := newAccessModel(shrToken, endpointUrl.String())
|
||||||
logrus.SetOutput(mdl)
|
logrus.SetOutput(mdl)
|
||||||
|
Loading…
Reference in New Issue
Block a user