MCPcopy
hub / github.com/cloudflare/cloudflared / TunnelCommand

Function TunnelCommand

cmd/cloudflared/tunnel/cmd.go:232–274  ·  view source on GitHub ↗
(c *cli.Context)

Source from the content-addressed store, hash-verified

230}
231
232func TunnelCommand(c *cli.Context) error {
233 sc, err := newSubcommandContext(c)
234 if err != nil {
235 return err
236 }
237
238 // Run an adhoc named tunnel
239 // Allows for the creation, routing (optional), and startup of a tunnel in one command
240 // --name required
241 // --url or --hello-world required
242 // --hostname optional
243 if name := c.String(cfdflags.Name); name != "" {
244 hostname, err := validation.ValidateHostname(c.String("hostname"))
245 if err != nil {
246 return errors.Wrap(err, "Invalid hostname provided")
247 }
248 tunnelURL := c.String("url")
249 if tunnelURL == hostname && tunnelURL != "" && hostname != "" {
250 return fmt.Errorf("hostname and url shouldn't match. See --help for more information")
251 }
252
253 return runAdhocNamedTunnel(sc, name, c.String(CredFileFlag))
254 }
255
256 // Run a quick tunnel
257 // A unauthenticated named tunnel hosted on <random>.<quick-tunnels-service>.com
258 shouldRunQuickTunnel := c.IsSet("url") || c.IsSet(ingress.HelloWorldFlag)
259 if c.String("quick-service") != "" && shouldRunQuickTunnel {
260 return RunQuickTunnel(sc)
261 }
262
263 // If user provides a config, check to see if they meant to use `tunnel run` instead
264 if ref := config.GetConfiguration().TunnelID; ref != "" {
265 return fmt.Errorf("use `cloudflared tunnel run` to start tunnel %s", ref)
266 }
267
268 // Classic tunnel usage is no longer supported
269 if c.String("hostname") != "" {
270 return errDeprecatedClassicTunnel
271 }
272
273 return errors.New(tunnelCmdErrorMessage)
274}
275
276func Init(info *cliutil.BuildInfo, gracefulShutdown chan struct{}) {
277 buildInfo, graceShutdownC = info, gracefulShutdown

Callers 1

actionFunction · 0.92

Calls 7

ValidateHostnameFunction · 0.92
GetConfigurationFunction · 0.92
newSubcommandContextFunction · 0.85
runAdhocNamedTunnelFunction · 0.85
RunQuickTunnelFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected