From 835486cab5858b0dd003ec26906bac0473e68bbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=A9rence=20Chateign=C3=A9?= Date: Wed, 7 Aug 2024 22:06:07 +0200 Subject: [PATCH] feat: allow user to set base api url --- cmd/connect.go | 1 + cmd/create.go | 1 + cmd/init.go | 1 + cmd/status.go | 1 + cmd/stop.go | 1 + go.mod | 18 +++---- go.sum | 36 ++++++------- tailout/app.go | 6 --- tailout/config/config.go | 113 +-------------------------------------- tailout/connect.go | 2 +- tailout/create.go | 2 +- tailout/init.go | 2 +- tailout/status.go | 2 +- tailout/stop.go | 2 +- 14 files changed, 38 insertions(+), 150 deletions(-) diff --git a/cmd/connect.go b/cmd/connect.go index 4a72b1e..a51f128 100644 --- a/cmd/connect.go +++ b/cmd/connect.go @@ -23,6 +23,7 @@ func buildConnectCommand(app *tailout.App) *cobra.Command { cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations") + cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale") return cmd } diff --git a/cmd/create.go b/cmd/create.go index 28317b8..cb299f5 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -33,6 +33,7 @@ func buildCreateCommand(app *tailout.App) *cobra.Command { cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.AuthKey, "tailscale-auth-key", "", "Tailscale Auth Key to use for operations") + cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale") cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)") cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts") cmd.PersistentFlags().StringVarP(&app.Config.Region, "region", "r", "", "Cloud-provider region to use") diff --git a/cmd/init.go b/cmd/init.go index 52ba66f..3e7fba6 100644 --- a/cmd/init.go +++ b/cmd/init.go @@ -27,6 +27,7 @@ func buildInitCommand(app *tailout.App) *cobra.Command { cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations") + cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale") cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts") cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)") diff --git a/cmd/status.go b/cmd/status.go index 33e8182..8e0a3a1 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -26,6 +26,7 @@ func buildStatusCommand(app *tailout.App) *cobra.Command { cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations") + cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale") return cmd } diff --git a/cmd/stop.go b/cmd/stop.go index cb28ecb..a8379ed 100644 --- a/cmd/stop.go +++ b/cmd/stop.go @@ -26,6 +26,7 @@ func buildStopCommand(app *tailout.App) *cobra.Command { cmd.PersistentFlags().StringVar(&app.Config.Tailscale.APIKey, "tailscale-api-key", "", "Tailscale API key used to perform operations on your tailnet") cmd.PersistentFlags().StringVar(&app.Config.Tailscale.Tailnet, "tailscale-tailnet", "", "Tailscale Tailnet to use for operations") + cmd.PersistentFlags().StringVar(&app.Config.Tailscale.BaseURL, "tailscale-base-url", "https://api.tailscale.com", "Tailscale base API URL, change this if you are using Headscale") cmd.PersistentFlags().BoolVarP(&app.Config.NonInteractive, "non-interactive", "n", false, "Disable interactive prompts") cmd.PersistentFlags().BoolVarP(&app.Config.DryRun, "dry-run", "d", false, "Dry run mode (no changes will be made)") cmd.PersistentFlags().BoolVarP(&app.Config.Stop.All, "all", "a", false, "Terminate all instances created by tailout") diff --git a/go.mod b/go.mod index 5df7ea9..2946db1 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.4 // indirect github.com/aws/smithy-go v1.20.3 // indirect github.com/chzyer/readline v1.5.1 // indirect - github.com/dblohm7/wingoes v0.0.0-20240705145628-15336bf25109 // indirect + github.com/dblohm7/wingoes v0.0.0-20240801171404-fc12d7c70140 // indirect github.com/fsnotify/fsnotify v1.7.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/gdamore/encoding v1.0.1 // indirect @@ -63,7 +63,7 @@ require ( github.com/sagikazarmark/slog-shim v0.1.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/spf13/afero v1.11.0 // indirect - github.com/spf13/cast v1.6.0 // indirect + github.com/spf13/cast v1.7.0 // indirect github.com/subosito/gotenv v1.6.0 // indirect github.com/tailscale/go-winio v0.0.0-20231025203758-c4f33415bf55 // indirect github.com/tailscale/hujson v0.0.0-20221223112325-20486734a56a // indirect @@ -71,14 +71,14 @@ require ( go.uber.org/multierr v1.11.0 // indirect go4.org/mem v0.0.0-20240501181205-ae6ca9944745 // indirect go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect - golang.org/x/crypto v0.25.0 // indirect + golang.org/x/crypto v0.26.0 // indirect golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/net v0.27.0 // indirect - golang.org/x/oauth2 v0.21.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/sys v0.22.0 // indirect - golang.org/x/term v0.22.0 // indirect - golang.org/x/text v0.16.0 // indirect + golang.org/x/net v0.28.0 // indirect + golang.org/x/oauth2 v0.22.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/sys v0.23.0 // indirect + golang.org/x/term v0.23.0 // indirect + golang.org/x/text v0.17.0 // indirect golang.zx2c4.com/wireguard/windows v0.5.3 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index bf3a9bb..52e0dd8 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dblohm7/wingoes v0.0.0-20240705145628-15336bf25109 h1:48mQmwgqKcAkXWafKN1jI4nN7LKfK/EivFQSU/wKa0Q= -github.com/dblohm7/wingoes v0.0.0-20240705145628-15336bf25109/go.mod h1:Nx87SkVqTKd8UtT+xu7sM/l+LgXs6c0aHrlKusR+2EQ= +github.com/dblohm7/wingoes v0.0.0-20240801171404-fc12d7c70140 h1:g4XyYZ0ed3hBOZPvvGadyiVfVaRsAFEVBCQGCoQC/sE= +github.com/dblohm7/wingoes v0.0.0-20240801171404-fc12d7c70140/go.mod h1:SUxUaAK/0UG5lYyZR1L1nC4AaYYvSSYTWQSH3FPcxKU= github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA= @@ -133,8 +133,8 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8= github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY= -github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= -github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= +github.com/spf13/cast v1.7.0 h1:ntdiHjuueXFgm5nzDRdOS4yfT43P5Fnud6DH50rz/7w= +github.com/spf13/cast v1.7.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -169,8 +169,8 @@ go4.org/netipx v0.0.0-20231129151722-fdeea329fbba h1:0b9z3AuHCjxk0x/opv64kcgZLBs go4.org/netipx v0.0.0-20231129151722-fdeea329fbba/go.mod h1:PLyyIXexvUFg3Owu6p/WfdlivPbZJsZdgWZlrGope/Y= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30= -golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= @@ -181,15 +181,15 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.27.0 h1:5K3Njcw06/l2y9vpGCSdcxWOYHOUk3dVNGDXN+FvAys= -golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE= -golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs= -golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= +golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= +golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/oauth2 v0.22.0 h1:BzDx2FehcG7jJwgWLELCdmLuxk2i+x9UDpSiss2u0ZA= +golang.org/x/oauth2 v0.22.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -200,21 +200,21 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.4.1-0.20230131160137-e7d7f63158de/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI= -golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM= +golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk= -golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk= -golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4= +golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU= +golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= -golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/tailout/app.go b/tailout/app.go index 0938d2d..e9f9d1c 100644 --- a/tailout/app.go +++ b/tailout/app.go @@ -14,12 +14,6 @@ type App struct { Err io.Writer } -type Tailscale struct { - AuthKey string - APIKey string - Tailnet string -} - func New() (*App, error) { c := &config.Config{} app := &App{ diff --git a/tailout/config/config.go b/tailout/config/config.go index 15b7114..301c53b 100644 --- a/tailout/config/config.go +++ b/tailout/config/config.go @@ -25,6 +25,7 @@ type CreateConfig struct { } type TailscaleConfig struct { + BaseURL string `mapstructure:"base_url"` AuthKey string `mapstructure:"auth_key"` APIKey string `mapstructure:"api_key"` Tailnet string `mapstructure:"tailnet"` @@ -39,118 +40,6 @@ type UiConfig struct { Address string `mapstructure:"address"` } -type Policy struct { - ACLs []ACL `json:"acls,omitempty"` - Hosts map[string]string `json:"hosts,omitempty"` - Groups map[string][]string `json:"groups,omitempty"` - Tests []Test `json:"tests,omitempty"` - TagOwners map[string][]string `json:"tagOwners,omitempty"` - AutoApprovers AutoApprovers `json:"autoApprovers,omitempty"` - SSH []SSHConfiguration `json:"ssh,omitempty"` - DerpMap DerpMap `json:"derpMap,omitempty"` - DisableIPv4 bool `json:"disableIPv4,omitempty"` - RandomizeClientPort bool `json:"randomizeClientPort,omitempty"` -} - -type ACL struct { - Action string `json:"action,omitempty"` - Src []string `json:"src,omitempty"` - Dst []string `json:"dst,omitempty"` - Proto string `json:"proto,omitempty"` -} - -type Test struct { - Src string `json:"src,omitempty"` - Accept []string `json:"accept,omitempty"` - Deny []string `json:"deny,omitempty"` -} - -type AutoApprovers struct { - Routes map[string][]string `json:"routes,omitempty"` - ExitNode []string `json:"exitNode,omitempty"` -} - -type SSHConfiguration struct { - Action string `json:"action,omitempty"` - Src []string `json:"src,omitempty"` - Dst []string `json:"dst,omitempty"` - Users []string `json:"users,omitempty"` -} - -type DerpMap struct { - Regions map[string]DerpRegion `json:"regions,omitempty"` -} - -type DerpRegion struct { - RegionID int `json:"regionID,omitempty"` - HostName string `json:"hostName,omitempty"` -} - -type Node struct { - Addresses []string `json:"addresses"` - Authorized bool `json:"authorized"` - BlocksIncomingConnections bool `json:"blocksIncomingConnections"` - ClientVersion string `json:"clientVersion"` - Created string `json:"created"` - Expires string `json:"expires"` - Hostname string `json:"hostname"` - ID string `json:"id"` - IsExternal bool `json:"isExternal"` - KeyExpiryDisabled bool `json:"keyExpiryDisabled"` - LastSeen string `json:"lastSeen"` - MachineKey string `json:"NodeKey,omitempty"` - Name string `json:"name,omitempty"` - NodeID string `json:"nodeId"` - NodeKey string `json:"nodeKey"` - OS string `json:"os"` - TailnetLockError string `json:"tailnetLockError,omitempty"` - TailnetLockKey string `json:"tailnetLockKey,omitempty"` - UpdateAvailable bool `json:"updateAvailable"` - User string `json:"user,omitempty"` - Tags []string `json:"tags,omitempty"` -} - -type TailscaleStatus struct { - ControlURL string `json:"ControlURL"` - RouteAll bool `json:"RouteAll"` - AllowSingleHosts bool `json:"AllowSingleHosts"` - ExitNodeID string `json:"ExitNodeID"` - ExitNodeIP string `json:"ExitNodeIP"` - ExitNodeAllowLANAccess bool `json:"ExitNodeAllowLANAccess"` - CorpDNS bool `json:"CorpDNS"` - RunSSH bool `json:"RunSSH"` - WantRunning bool `json:"WantRunning"` - LoggedOut bool `json:"LoggedOut"` - ShieldsUp bool `json:"ShieldsUp"` - AdvertiseTags string `json:"AdvertiseTags"` - Hostname string `json:"Hostname"` - NotepadURLs bool `json:"NotepadURLs"` - AdvertiseRoutes string `json:"AdvertiseRoutes"` - NoSNAT bool `json:"NoSNAT"` - NetfilterMode int `json:"NetfilterMode"` - Config struct { - PrivateMachineKey string `json:"PrivateMachineKey"` - PrivateNodeKey string `json:"PrivateNodeKey"` - OldPrivateNodeKey string `json:"OldPrivateNodeKey"` - Provider string `json:"Provider"` - LoginName string `json:"LoginName"` - UserProfile struct { - ID int64 `json:"ID"` - LoginName string `json:"LoginName"` - DisplayName string `json:"DisplayName"` - ProfilePicURL string `json:"ProfilePicURL"` - Roles []string `json:"Roles"` - } `json:"UserProfile"` - NetworkLockKey string `json:"NetworkLockKey"` - NodeID string `json:"NodeID"` - } `json:"Config"` -} - -type UserNodes struct { - User string `json:"user"` - Nodes []Node `json:"devices"` -} - func (c *Config) Load(flags *pflag.FlagSet, cmdName string) error { v := viper.New() diff --git a/tailout/connect.go b/tailout/connect.go index 723d9f5..032e965 100644 --- a/tailout/connect.go +++ b/tailout/connect.go @@ -19,7 +19,7 @@ func (app *App) Connect(args []string) error { nonInteractive := app.Config.NonInteractive - apiClient, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet) + apiClient, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet, tsapi.WithBaseURL(app.Config.Tailscale.BaseURL)) if err != nil { return fmt.Errorf("failed to create tailscale client: %w", err) } diff --git a/tailout/create.go b/tailout/create.go index 771c0e0..fac1c7a 100644 --- a/tailout/create.go +++ b/tailout/create.go @@ -206,7 +206,7 @@ sudo echo "sudo shutdown" | at now + ` + fmt.Sprint(durationMinutes) + ` minutes timeout := time.Now().Add(3 * time.Minute) - client, err := tailscale.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet) + client, err := tailscale.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet, tailscale.WithBaseURL(app.Config.Tailscale.BaseURL)) if err != nil { return fmt.Errorf("failed to create tailscale client: %w", err) } diff --git a/tailout/init.go b/tailout/init.go index ed9d72f..28a3129 100644 --- a/tailout/init.go +++ b/tailout/init.go @@ -13,7 +13,7 @@ func (app *App) Init() error { dryRun := app.Config.DryRun nonInteractive := app.Config.NonInteractive - apiClient, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet) + apiClient, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet, tsapi.WithBaseURL(app.Config.Tailscale.BaseURL)) if err != nil { return fmt.Errorf("failed to create tailscale client: %w", err) } diff --git a/tailout/status.go b/tailout/status.go index 144ec6e..4f30ac2 100644 --- a/tailout/status.go +++ b/tailout/status.go @@ -14,7 +14,7 @@ import ( ) func (app *App) Status() error { - client, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet) + client, err := tsapi.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet, tsapi.WithBaseURL(app.Config.Tailscale.BaseURL)) if err != nil { return fmt.Errorf("failed to create tailscale client: %w", err) } diff --git a/tailout/stop.go b/tailout/stop.go index 03d07df..9a465a4 100644 --- a/tailout/stop.go +++ b/tailout/stop.go @@ -22,7 +22,7 @@ func (app *App) Stop(args []string) error { nodesToStop := []tailscale.Device{} - client, err := tailscale.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet) + client, err := tailscale.NewClient(app.Config.Tailscale.APIKey, app.Config.Tailscale.Tailnet, tailscale.WithBaseURL(app.Config.Tailscale.BaseURL)) if err != nil { return fmt.Errorf("failed to create tailscale client: %w", err) }