File
Blob: cmd/client/client.go
| 1 | package client |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "fmt" |
| 6 | |
| 7 | "go.miragespace.co/specter/util" |
| 8 | |
| 9 | "github.com/urfave/cli/v3" |
| 10 | ) |
| 11 | |
| 12 | var ( |
| 13 | // used in dev-client docker image |
| 14 | devApexOverride = "" |
| 15 | ) |
| 16 | |
| 17 | func Generate() *cli.Command { |
| 18 | return &cli.Command{ |
| 19 | Name: "client", |
| 20 | ArgsUsage: " ", |
| 21 | Usage: "start an specter client on this machine", |
| 22 | Description: "Run a Specter client to publish and manage reverse tunnels over QUIC, fetch hostnames and TLS certs via ACME, and connect or listen to your endpoints", |
| 23 | Flags: []cli.Flag{ |
| 24 | &cli.BoolFlag{ |
| 25 | Name: "insecure", |
| 26 | Value: false, |
| 27 | Usage: "disable TLS verification, useful for debugging and local development", |
| 28 | }, |
| 29 | }, |
| 30 | Commands: []*cli.Command{ |
| 31 | exposeCommand(), serveCommand(), tokenCommand(), |
| 32 | { |
| 33 | Name: "tunnel", |
| 34 | ArgsUsage: " ", |
| 35 | Usage: "Create highly available reverse tunnels to this machine", |
| 36 | Flags: []cli.Flag{ |
| 37 | &cli.StringFlag{ |
| 38 | Name: "config", |
| 39 | Aliases: []string{"c"}, |
| 40 | Usage: "path to config yaml file.", |
| 41 | Required: true, |
| 42 | }, |
| 43 | &cli.StringFlag{ |
| 44 | Name: "server", |
| 45 | Usage: "start local server to handle client commands while the client is running", |
| 46 | }, |
| 47 | &cli.StringFlag{ |
| 48 | Name: "keyless", |
| 49 | Usage: `start a keyless TLS proxy while the client is running. This is useful for local access with split DNS, without going to the edge specter node for proxying. |
| 50 | Note that if keyless proxy is listening on port 443, it will also listen on port 80 to handle http connect proxy, and redirect other http requests to https`, |
| 51 | }, |
| 52 | }, |
| 53 | Action: cmdTunnel, |
| 54 | }, |
| 55 | { |
| 56 | Name: "config-example", |
| 57 | ArgsUsage: " ", |
| 58 | Usage: "Print an example client configuration in YAML format", |
| 59 | Action: cmdConfigExample, |
| 60 | }, |
| 61 | { |
| 62 | Name: "connect", |
| 63 | ArgsUsage: "[hostname of the tunnel]", |
| 64 | Usage: "Connect to target via stdin/stdout, usually for connecting to TCP endpoint", |
| 65 | Flags: []cli.Flag{ |
| 66 | &cli.BoolFlag{ |
| 67 | Name: "tcp", |
| 68 | Usage: "fallback to connect to gateway via TLS/TCP instead of QUIC", |
| 69 | }, |
| 70 | }, |
| 71 | Action: cmdConnect, |
| 72 | }, |
| 73 | { |
| 74 | Name: "listen", |
| 75 | ArgsUsage: "[hostname of the tunnel]", |
| 76 | Usage: "Listen for connections locally and forward them to target", |
| 77 | Flags: []cli.Flag{ |
| 78 | &cli.BoolFlag{ |
| 79 | Name: "tcp", |
| 80 | Usage: "fallback to connect to gateway via TLS/TCP instead of QUIC.", |
| 81 | }, |
| 82 | &cli.StringFlag{ |
| 83 | Name: "listen", |
| 84 | Aliases: []string{"l"}, |
| 85 | DefaultText: fmt.Sprintf("%s:1337", util.GetOutboundIP().String()), |
| 86 | Usage: "address and port to listen for incoming TCP connections", |
| 87 | Required: true, |
| 88 | }, |
| 89 | }, |
| 90 | Action: cmdListen, |
| 91 | }, |
| 92 | { |
| 93 | Name: "ls", |
| 94 | ArgsUsage: " ", |
| 95 | Usage: "Query registered hostnames associated with this client", |
| 96 | Flags: []cli.Flag{ |
| 97 | &cli.StringFlag{ |
| 98 | Name: "config", |
| 99 | Aliases: []string{"c"}, |
| 100 | Usage: "path to config yaml file.", |
| 101 | Required: true, |
| 102 | }, |
| 103 | }, |
| 104 | Action: cmdLs, |
| 105 | }, |
| 106 | { |
| 107 | Name: "acme", |
| 108 | ArgsUsage: "[custom hostname to be used]", |
| 109 | Usage: "Obtain instructions to setup custom hostname to be used with specter", |
| 110 | Flags: []cli.Flag{ |
| 111 | &cli.StringFlag{ |
| 112 | Name: "config", |
| 113 | Aliases: []string{"c"}, |
| 114 | Usage: "path to config yaml file.", |
| 115 | Required: true, |
| 116 | }, |
| 117 | }, |
| 118 | Action: cmdAcme, |
| 119 | }, |
| 120 | { |
| 121 | Name: "validate", |
| 122 | ArgsUsage: "[custom hostname to be used]", |
| 123 | Usage: "Validate hostname DNS setup to be used as custom hostname", |
| 124 | Flags: []cli.Flag{ |
| 125 | &cli.StringFlag{ |
| 126 | Name: "config", |
| 127 | Aliases: []string{"c"}, |
| 128 | Usage: "path to config yaml file.", |
| 129 | Required: true, |
| 130 | }, |
| 131 | }, |
| 132 | Action: cmdValidate, |
| 133 | }, |
| 134 | }, |
| 135 | Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) { |
| 136 | if devApexOverride != "" { |
| 137 | cmd.Root().Metadata["apexOverride"] = devApexOverride |
| 138 | } |
| 139 | return ctx, nil |
| 140 | }, |
| 141 | } |
| 142 | } |