mirror of
https://github.com/openziti/zrok.git
synced 2024-11-21 23:53:19 +01:00
add new 'headless' config option (#224)
This commit is contained in:
parent
73b32031ce
commit
b1daabfab8
@ -50,7 +50,11 @@ func newAccessPrivateCommand() *accessPrivateCommand {
|
|||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
command := &accessPrivateCommand{cmd: cmd}
|
command := &accessPrivateCommand{cmd: cmd}
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
headless := false
|
||||||
|
if root, err := environment.LoadRoot(); err == nil {
|
||||||
|
headless, _ = root.Headless()
|
||||||
|
}
|
||||||
|
cmd.Flags().BoolVar(&command.headless, "headless", headless, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable subordinate mode")
|
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable subordinate mode")
|
||||||
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
||||||
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
||||||
|
@ -46,6 +46,12 @@ func (cmd *configGetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
} else {
|
} else {
|
||||||
fmt.Println("defaultFrontend = <unset>")
|
fmt.Println("defaultFrontend = <unset>")
|
||||||
}
|
}
|
||||||
|
case "headless":
|
||||||
|
if env.Config() != nil {
|
||||||
|
fmt.Printf("headless = %v\n", env.Config().Headless)
|
||||||
|
} else {
|
||||||
|
fmt.Println("headless = <unset>")
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
fmt.Printf("unknown config name '%v'\n", configName)
|
fmt.Printf("unknown config name '%v'\n", configName)
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -77,6 +78,24 @@ func (cmd *configSetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
fmt.Println("zrok configuration updated")
|
fmt.Println("zrok configuration updated")
|
||||||
|
|
||||||
|
case "headless":
|
||||||
|
headless, err := strconv.ParseBool(value)
|
||||||
|
if err != nil {
|
||||||
|
tui.Error("unable to parse value for 'headless': %v", err)
|
||||||
|
}
|
||||||
|
if env.Config() == nil {
|
||||||
|
if err := env.SetConfig(&env_core.Config{Headless: headless}); err != nil {
|
||||||
|
tui.Error("unable to save config", err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
cfg := env.Config()
|
||||||
|
cfg.Headless = headless
|
||||||
|
if err := env.SetConfig(cfg); err != nil {
|
||||||
|
tui.Error("unable to save config", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Println("zrok configuration updated")
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Printf("unknown config name '%v'\n", configName)
|
fmt.Printf("unknown config name '%v'\n", configName)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -47,6 +47,9 @@ func (cmd *configUnsetCommand) run(_ *cobra.Command, args []string) {
|
|||||||
case "defaultFrontend":
|
case "defaultFrontend":
|
||||||
cfg.DefaultFrontend = ""
|
cfg.DefaultFrontend = ""
|
||||||
|
|
||||||
|
case "headless":
|
||||||
|
cfg.Headless = false
|
||||||
|
|
||||||
default:
|
default:
|
||||||
fmt.Printf("unknown config name '%v'\n", configName)
|
fmt.Printf("unknown config name '%v'\n", configName)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
@ -50,8 +50,12 @@ func newSharePrivateCommand() *sharePrivateCommand {
|
|||||||
Args: cobra.RangeArgs(0, 1),
|
Args: cobra.RangeArgs(0, 1),
|
||||||
}
|
}
|
||||||
command := &sharePrivateCommand{cmd: cmd}
|
command := &sharePrivateCommand{cmd: cmd}
|
||||||
|
headless := false
|
||||||
|
if root, err := environment.LoadRoot(); err == nil {
|
||||||
|
headless, _ = root.Headless()
|
||||||
|
}
|
||||||
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, tcpTunnel, udpTunnel, caddy, drive, socks, vpn}")
|
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, tcpTunnel, udpTunnel, caddy, drive, socks, vpn}")
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
cmd.Flags().BoolVar(&command.headless, "headless", headless, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
||||||
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
||||||
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
||||||
|
@ -58,9 +58,13 @@ func newSharePublicCommand() *sharePublicCommand {
|
|||||||
defaultFrontend, _ := root.DefaultFrontend()
|
defaultFrontend, _ := root.DefaultFrontend()
|
||||||
defaultFrontends = []string{defaultFrontend}
|
defaultFrontends = []string{defaultFrontend}
|
||||||
}
|
}
|
||||||
|
headless := false
|
||||||
|
if root, err := environment.LoadRoot(); err == nil {
|
||||||
|
headless, _ = root.Headless()
|
||||||
|
}
|
||||||
cmd.Flags().StringArrayVar(&command.frontendSelection, "frontend", defaultFrontends, "Selected frontends to use for the share")
|
cmd.Flags().StringArrayVar(&command.frontendSelection, "frontend", defaultFrontends, "Selected frontends to use for the share")
|
||||||
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, caddy, drive}")
|
cmd.Flags().StringVarP(&command.backendMode, "backend-mode", "b", "proxy", "The backend mode {proxy, web, caddy, drive}")
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
cmd.Flags().BoolVar(&command.headless, "headless", headless, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
||||||
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
||||||
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
||||||
|
@ -47,8 +47,12 @@ func newShareReservedCommand() *shareReservedCommand {
|
|||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
}
|
}
|
||||||
command := &shareReservedCommand{cmd: cmd}
|
command := &shareReservedCommand{cmd: cmd}
|
||||||
|
headless := false
|
||||||
|
if root, err := environment.LoadRoot(); err == nil {
|
||||||
|
headless, _ = root.Headless()
|
||||||
|
}
|
||||||
cmd.Flags().StringVar(&command.overrideEndpoint, "override-endpoint", "", "Override the stored target endpoint with a replacement")
|
cmd.Flags().StringVar(&command.overrideEndpoint, "override-endpoint", "", "Override the stored target endpoint with a replacement")
|
||||||
cmd.Flags().BoolVar(&command.headless, "headless", false, "Disable TUI and run headless")
|
cmd.Flags().BoolVar(&command.headless, "headless", headless, "Disable TUI and run headless")
|
||||||
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
cmd.Flags().BoolVar(&command.subordinate, "subordinate", false, "Enable agent mode")
|
||||||
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
cmd.MarkFlagsMutuallyExclusive("headless", "subordinate")
|
||||||
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
cmd.Flags().BoolVar(&command.forceLocal, "force-local", false, "Skip agent detection and force local mode")
|
||||||
|
@ -52,6 +52,8 @@ func (cmd *statusCommand) run(_ *cobra.Command, _ []string) {
|
|||||||
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, apiEndpointFrom})
|
t.AppendRow(table.Row{"apiEndpoint", apiEndpoint, apiEndpointFrom})
|
||||||
defaultFrontend, defaultFrontendFrom := env.DefaultFrontend()
|
defaultFrontend, defaultFrontendFrom := env.DefaultFrontend()
|
||||||
t.AppendRow(table.Row{"defaultFrontend", defaultFrontend, defaultFrontendFrom})
|
t.AppendRow(table.Row{"defaultFrontend", defaultFrontend, defaultFrontendFrom})
|
||||||
|
headless, headlessFrom := env.Headless()
|
||||||
|
t.AppendRow(table.Row{"headless", headless, headlessFrom})
|
||||||
t.Render()
|
t.Render()
|
||||||
_, _ = fmt.Fprintf(os.Stderr, "\n")
|
_, _ = fmt.Fprintf(os.Stderr, "\n")
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ type Root interface {
|
|||||||
Client() (*rest_client_zrok.Zrok, error)
|
Client() (*rest_client_zrok.Zrok, error)
|
||||||
ApiEndpoint() (string, string)
|
ApiEndpoint() (string, string)
|
||||||
DefaultFrontend() (string, string)
|
DefaultFrontend() (string, string)
|
||||||
|
Headless() (bool, string)
|
||||||
|
|
||||||
IsEnabled() bool
|
IsEnabled() bool
|
||||||
Environment() *Environment
|
Environment() *Environment
|
||||||
@ -39,6 +40,7 @@ type Environment struct {
|
|||||||
type Config struct {
|
type Config struct {
|
||||||
ApiEndpoint string
|
ApiEndpoint string
|
||||||
DefaultFrontend string
|
DefaultFrontend string
|
||||||
|
Headless bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type Metadata struct {
|
type Metadata struct {
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Root) Metadata() *env_core.Metadata {
|
func (r *Root) Metadata() *env_core.Metadata {
|
||||||
@ -103,6 +104,26 @@ func (r *Root) DefaultFrontend() (string, string) {
|
|||||||
return defaultFrontend, from
|
return defaultFrontend, from
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Root) Headless() (bool, string) {
|
||||||
|
headless := false
|
||||||
|
from := "binary"
|
||||||
|
|
||||||
|
if r.Config() != nil {
|
||||||
|
headless = r.Config().Headless
|
||||||
|
from = "config"
|
||||||
|
}
|
||||||
|
|
||||||
|
env := os.Getenv("ZROK_HEADLESS")
|
||||||
|
if env != "" {
|
||||||
|
if v, err := strconv.ParseBool(env); err == nil {
|
||||||
|
headless = v
|
||||||
|
from = "ZROK_HEADLESS"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return headless, from
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Root) Environment() *env_core.Environment {
|
func (r *Root) Environment() *env_core.Environment {
|
||||||
return r.env
|
return r.env
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (r *Root) Metadata() *env_core.Metadata {
|
func (r *Root) Metadata() *env_core.Metadata {
|
||||||
@ -103,6 +104,26 @@ func (r *Root) DefaultFrontend() (string, string) {
|
|||||||
return defaultFrontend, from
|
return defaultFrontend, from
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *Root) Headless() (bool, string) {
|
||||||
|
headless := false
|
||||||
|
from := "binary"
|
||||||
|
|
||||||
|
if r.Config() != nil {
|
||||||
|
headless = r.Config().Headless
|
||||||
|
from = "config"
|
||||||
|
}
|
||||||
|
|
||||||
|
env := os.Getenv("ZROK_HEADLESS")
|
||||||
|
if env != "" {
|
||||||
|
if v, err := strconv.ParseBool(env); err == nil {
|
||||||
|
headless = v
|
||||||
|
from = "ZROK_HEADLESS"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return headless, from
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Root) Environment() *env_core.Environment {
|
func (r *Root) Environment() *env_core.Environment {
|
||||||
return r.env
|
return r.env
|
||||||
}
|
}
|
||||||
|
@ -225,12 +225,17 @@ func loadConfig() (*env_core.Config, error) {
|
|||||||
out := &env_core.Config{
|
out := &env_core.Config{
|
||||||
ApiEndpoint: cfg.ApiEndpoint,
|
ApiEndpoint: cfg.ApiEndpoint,
|
||||||
DefaultFrontend: cfg.DefaultFrontend,
|
DefaultFrontend: cfg.DefaultFrontend,
|
||||||
|
Headless: cfg.Headless,
|
||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveConfig(cfg *env_core.Config) error {
|
func saveConfig(cfg *env_core.Config) error {
|
||||||
in := &config{ApiEndpoint: cfg.ApiEndpoint, DefaultFrontend: cfg.DefaultFrontend}
|
in := &config{
|
||||||
|
ApiEndpoint: cfg.ApiEndpoint,
|
||||||
|
DefaultFrontend: cfg.DefaultFrontend,
|
||||||
|
Headless: cfg.Headless,
|
||||||
|
}
|
||||||
data, err := json.MarshalIndent(in, "", " ")
|
data, err := json.MarshalIndent(in, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error marshaling config")
|
return errors.Wrap(err, "error marshaling config")
|
||||||
@ -326,6 +331,7 @@ type metadata struct {
|
|||||||
type config struct {
|
type config struct {
|
||||||
ApiEndpoint string `json:"api_endpoint"`
|
ApiEndpoint string `json:"api_endpoint"`
|
||||||
DefaultFrontend string `json:"default_frontend"`
|
DefaultFrontend string `json:"default_frontend"`
|
||||||
|
Headless bool `json:"headless"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type environment struct {
|
type environment struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user