TUN-4094: Don't read configuration file for access commands

This commit is contained in:
Igor Postelnik 2021-03-16 17:36:46 -05:00
parent 8c5498fad1
commit a34099724e
12 changed files with 35 additions and 44 deletions

View File

@ -91,12 +91,6 @@ func Commands() []*cli.Command {
Once authenticated with your identity provider, the login command will generate a JSON Web Token (JWT) Once authenticated with your identity provider, the login command will generate a JSON Web Token (JWT)
scoped to your identity, the application you intend to reach, and valid for a session duration set by your scoped to your identity, the application you intend to reach, and valid for a session duration set by your
administrator. cloudflared stores the token in local storage.`, administrator. cloudflared stores the token in local storage.`,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "url",
Hidden: true,
},
},
}, },
{ {
Name: "curl", Name: "curl",

View File

@ -9,6 +9,10 @@ import (
) )
func Action(actionFunc cli.ActionFunc) cli.ActionFunc { func Action(actionFunc cli.ActionFunc) cli.ActionFunc {
return WithErrorHandler(actionFunc)
}
func ConfiguredAction(actionFunc cli.ActionFunc) cli.ActionFunc {
return WithErrorHandler(func(c *cli.Context) error { return WithErrorHandler(func(c *cli.Context) error {
if err := setFlagsFromConfigFile(c); err != nil { if err := setFlagsFromConfigFile(c); err != nil {
return err return err

View File

@ -24,7 +24,7 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
{ {
Name: "install", Name: "install",
Usage: "Install Argo Tunnel as a system service", Usage: "Install Argo Tunnel as a system service",
Action: cliutil.Action(installLinuxService), Action: cliutil.ConfiguredAction(installLinuxService),
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
Name: "legacy", Name: "legacy",
@ -35,7 +35,7 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
{ {
Name: "uninstall", Name: "uninstall",
Usage: "Uninstall the Argo Tunnel service", Usage: "Uninstall the Argo Tunnel service",
Action: cliutil.Action(uninstallLinuxService), Action: cliutil.ConfiguredAction(uninstallLinuxService),
}, },
}, },
}) })

View File

@ -25,12 +25,12 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
{ {
Name: "install", Name: "install",
Usage: "Install Argo Tunnel as an user launch agent", Usage: "Install Argo Tunnel as an user launch agent",
Action: cliutil.Action(installLaunchd), Action: cliutil.ConfiguredAction(installLaunchd),
}, },
{ {
Name: "uninstall", Name: "uninstall",
Usage: "Uninstall the Argo Tunnel launch agent", Usage: "Uninstall the Argo Tunnel launch agent",
Action: cliutil.Action(uninstallLaunchd), Action: cliutil.ConfiguredAction(uninstallLaunchd),
}, },
}, },
}) })

View File

@ -8,10 +8,10 @@ import (
"github.com/cloudflare/cloudflared/cmd/cloudflared/access" "github.com/cloudflare/cloudflared/cmd/cloudflared/access"
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil" "github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
"github.com/cloudflare/cloudflared/config"
"github.com/cloudflare/cloudflared/cmd/cloudflared/proxydns" "github.com/cloudflare/cloudflared/cmd/cloudflared/proxydns"
"github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel" "github.com/cloudflare/cloudflared/cmd/cloudflared/tunnel"
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater" "github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
"github.com/cloudflare/cloudflared/config"
"github.com/cloudflare/cloudflared/logger" "github.com/cloudflare/cloudflared/logger"
"github.com/cloudflare/cloudflared/metrics" "github.com/cloudflare/cloudflared/metrics"
"github.com/cloudflare/cloudflared/overwatch" "github.com/cloudflare/cloudflared/overwatch"
@ -89,7 +89,7 @@ func commands(version func(c *cli.Context)) []*cli.Command {
cmds := []*cli.Command{ cmds := []*cli.Command{
{ {
Name: "update", Name: "update",
Action: cliutil.Action(updater.Update), Action: cliutil.ConfiguredAction(updater.Update),
Usage: "Update the agent if a new version exists", Usage: "Update the agent if a new version exists",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.BoolFlag{ &cli.BoolFlag{
@ -144,7 +144,7 @@ func isEmptyInvocation(c *cli.Context) bool {
} }
func action(graceShutdownC chan struct{}) cli.ActionFunc { func action(graceShutdownC chan struct{}) cli.ActionFunc {
return cliutil.Action(func(c *cli.Context) (err error) { return cliutil.ConfiguredAction(func(c *cli.Context) (err error) {
if isEmptyInvocation(c) { if isEmptyInvocation(c) {
return handleServiceMode(c, graceShutdownC) return handleServiceMode(c, graceShutdownC)
} }

View File

@ -17,9 +17,9 @@ import (
func Command(hidden bool) *cli.Command { func Command(hidden bool) *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "proxy-dns", Name: "proxy-dns",
Action: cliutil.Action(Run), Action: cliutil.ConfiguredAction(Run),
Usage: "Run a DNS over HTTPS proxy server.", Usage: "Run a DNS over HTTPS proxy server.",
Flags: []cli.Flag{ Flags: []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
Name: "metrics", Name: "metrics",
@ -112,5 +112,3 @@ func Run(c *cli.Context) error {
} }
return err return err
} }

View File

@ -119,7 +119,7 @@ func Commands() []*cli.Command {
func buildTunnelCommand(subcommands []*cli.Command) *cli.Command { func buildTunnelCommand(subcommands []*cli.Command) *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "tunnel", Name: "tunnel",
Action: cliutil.Action(TunnelCommand), Action: cliutil.ConfiguredAction(TunnelCommand),
Category: "Tunnel", Category: "Tunnel",
Usage: "Make a locally-running web service accessible over the internet using Argo Tunnel.", Usage: "Make a locally-running web service accessible over the internet using Argo Tunnel.",
ArgsUsage: " ", ArgsUsage: " ",

View File

@ -45,7 +45,7 @@ func buildIngressSubcommand() *cli.Command {
func buildValidateIngressCommand() *cli.Command { func buildValidateIngressCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "validate", Name: "validate",
Action: cliutil.Action(validateIngressCommand), Action: cliutil.ConfiguredAction(validateIngressCommand),
Usage: "Validate the ingress configuration ", Usage: "Validate the ingress configuration ",
UsageText: "cloudflared tunnel [--config FILEPATH] ingress validate", UsageText: "cloudflared tunnel [--config FILEPATH] ingress validate",
Description: "Validates the configuration file, ensuring your ingress rules are OK.", Description: "Validates the configuration file, ensuring your ingress rules are OK.",
@ -55,7 +55,7 @@ func buildValidateIngressCommand() *cli.Command {
func buildTestURLCommand() *cli.Command { func buildTestURLCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "rule", Name: "rule",
Action: cliutil.Action(testURLCommand), Action: cliutil.ConfiguredAction(testURLCommand),
Usage: "Check which ingress rule matches a given request URL", Usage: "Check which ingress rule matches a given request URL",
UsageText: "cloudflared tunnel [--config FILEPATH] ingress rule URL", UsageText: "cloudflared tunnel [--config FILEPATH] ingress rule URL",
ArgsUsage: "URL", ArgsUsage: "URL",

View File

@ -26,16 +26,10 @@ const (
func buildLoginSubcommand(hidden bool) *cli.Command { func buildLoginSubcommand(hidden bool) *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "login", Name: "login",
Action: cliutil.Action(login), Action: cliutil.ConfiguredAction(login),
Usage: "Generate a configuration file with your login details", Usage: "Generate a configuration file with your login details",
ArgsUsage: " ", ArgsUsage: " ",
Flags: []cli.Flag{ Hidden: hidden,
&cli.StringFlag{
Name: "url",
Hidden: true,
},
},
Hidden: hidden,
} }
} }

View File

@ -119,7 +119,7 @@ var (
func buildCreateCommand() *cli.Command { func buildCreateCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "create", Name: "create",
Action: cliutil.Action(createCommand), Action: cliutil.ConfiguredAction(createCommand),
Usage: "Create a new tunnel with given name", Usage: "Create a new tunnel with given name",
UsageText: "cloudflared tunnel [tunnel command options] create [subcommand options] NAME", UsageText: "cloudflared tunnel [tunnel command options] create [subcommand options] NAME",
Description: `Creates a tunnel, registers it with Cloudflare edge and generates credential file used to run this tunnel. Description: `Creates a tunnel, registers it with Cloudflare edge and generates credential file used to run this tunnel.
@ -190,7 +190,7 @@ func writeTunnelCredentials(
func buildListCommand() *cli.Command { func buildListCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "list", Name: "list",
Action: cliutil.Action(listCommand), Action: cliutil.ConfiguredAction(listCommand),
Usage: "List existing tunnels", Usage: "List existing tunnels",
UsageText: "cloudflared tunnel [tunnel command options] list [subcommand options]", UsageText: "cloudflared tunnel [tunnel command options] list [subcommand options]",
Description: "cloudflared tunnel list will display all active tunnels, their created time and associated connections. Use -d flag to include deleted tunnels. See the list of options to filter the list", Description: "cloudflared tunnel list will display all active tunnels, their created time and associated connections. Use -d flag to include deleted tunnels. See the list of options to filter the list",
@ -339,7 +339,7 @@ func fmtConnections(connections []tunnelstore.Connection, showRecentlyDisconnect
func buildDeleteCommand() *cli.Command { func buildDeleteCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "delete", Name: "delete",
Action: cliutil.Action(deleteCommand), Action: cliutil.ConfiguredAction(deleteCommand),
Usage: "Delete existing tunnel by UUID or name", Usage: "Delete existing tunnel by UUID or name",
UsageText: "cloudflared tunnel [tunnel command options] delete [subcommand options] TUNNEL", UsageText: "cloudflared tunnel [tunnel command options] delete [subcommand options] TUNNEL",
Description: "cloudflared tunnel delete will delete tunnels with the given tunnel UUIDs or names. A tunnel cannot be deleted if it has active connections. To delete the tunnel unconditionally, use -f flag.", Description: "cloudflared tunnel delete will delete tunnels with the given tunnel UUIDs or names. A tunnel cannot be deleted if it has active connections. To delete the tunnel unconditionally, use -f flag.",
@ -392,7 +392,7 @@ func buildRunCommand() *cli.Command {
flags = append(flags, configureProxyFlags(false)...) flags = append(flags, configureProxyFlags(false)...)
return &cli.Command{ return &cli.Command{
Name: "run", Name: "run",
Action: cliutil.Action(runCommand), Action: cliutil.ConfiguredAction(runCommand),
Usage: "Proxy a local web server by running the given tunnel", Usage: "Proxy a local web server by running the given tunnel",
UsageText: "cloudflared tunnel [tunnel command options] run [subcommand options] [TUNNEL]", UsageText: "cloudflared tunnel [tunnel command options] run [subcommand options] [TUNNEL]",
Description: `Runs the tunnel identified by name or UUUD, creating highly available connections Description: `Runs the tunnel identified by name or UUUD, creating highly available connections
@ -444,7 +444,7 @@ func runNamedTunnel(sc *subcommandContext, tunnelRef string) error {
func buildCleanupCommand() *cli.Command { func buildCleanupCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "cleanup", Name: "cleanup",
Action: cliutil.Action(cleanupCommand), Action: cliutil.ConfiguredAction(cleanupCommand),
Usage: "Cleanup tunnel connections", Usage: "Cleanup tunnel connections",
UsageText: "cloudflared tunnel [tunnel command options] cleanup [subcommand options] TUNNEL", UsageText: "cloudflared tunnel [tunnel command options] cleanup [subcommand options] TUNNEL",
Description: "Delete connections for tunnels with the given UUIDs or names.", Description: "Delete connections for tunnels with the given UUIDs or names.",
@ -473,7 +473,7 @@ func cleanupCommand(c *cli.Context) error {
func buildRouteCommand() *cli.Command { func buildRouteCommand() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "route", Name: "route",
Action: cliutil.Action(routeCommand), Action: cliutil.ConfiguredAction(routeCommand),
Usage: "Define which traffic routed from Cloudflare edge to this tunnel: requests to a DNS hostname, to a Cloudflare Load Balancer, or traffic originating from Cloudflare WARP clients", Usage: "Define which traffic routed from Cloudflare edge to this tunnel: requests to a DNS hostname, to a Cloudflare Load Balancer, or traffic originating from Cloudflare WARP clients",
UsageText: "cloudflared tunnel [tunnel command options] route [subcommand options] [dns TUNNEL HOSTNAME]|[lb TUNNEL HOSTNAME LB-POOL]|[ip NETWORK TUNNEL]", UsageText: "cloudflared tunnel [tunnel command options] route [subcommand options] [dns TUNNEL HOSTNAME]|[lb TUNNEL HOSTNAME LB-POOL]|[ip NETWORK TUNNEL]",
Description: `The route command defines how Cloudflare will proxy requests to this tunnel. Description: `The route command defines how Cloudflare will proxy requests to this tunnel.

View File

@ -6,10 +6,11 @@ import (
"os" "os"
"text/tabwriter" "text/tabwriter"
"github.com/pkg/errors"
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil" "github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater" "github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
"github.com/cloudflare/cloudflared/teamnet" "github.com/cloudflare/cloudflared/teamnet"
"github.com/pkg/errors"
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
@ -25,7 +26,7 @@ Cloudflare WARP client. You can also build rules to determine who can reach cert
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{
{ {
Name: "add", Name: "add",
Action: cliutil.Action(addRouteCommand), Action: cliutil.ConfiguredAction(addRouteCommand),
Usage: "Add any new network to the routing table reachable via the tunnel", Usage: "Add any new network to the routing table reachable via the tunnel",
UsageText: "cloudflared tunnel [--config FILEPATH] route ip add [CIDR] [TUNNEL] [COMMENT?]", UsageText: "cloudflared tunnel [--config FILEPATH] route ip add [CIDR] [TUNNEL] [COMMENT?]",
Description: `Adds any network route space (represented as a CIDR) to your routing table. Description: `Adds any network route space (represented as a CIDR) to your routing table.
@ -38,23 +39,23 @@ reachable from the tunnel.`,
{ {
Name: "show", Name: "show",
Aliases: []string{"list"}, Aliases: []string{"list"},
Action: cliutil.Action(showRoutesCommand), Action: cliutil.ConfiguredAction(showRoutesCommand),
Usage: "Show the routing table", Usage: "Show the routing table",
UsageText: "cloudflared tunnel [--config FILEPATH] route ip show [flags]", UsageText: "cloudflared tunnel [--config FILEPATH] route ip show [flags]",
Description: `Shows your organization private routing table. You can use flags to filter the results.`, Description: `Shows your organization private routing table. You can use flags to filter the results.`,
Flags: showRoutesFlags(), Flags: showRoutesFlags(),
}, },
{ {
Name: "delete", Name: "delete",
Action: cliutil.Action(deleteRouteCommand), Action: cliutil.ConfiguredAction(deleteRouteCommand),
Usage: "Delete a row from your organization's private routing table", Usage: "Delete a row from your organization's private routing table",
UsageText: "cloudflared tunnel [--config FILEPATH] route ip delete [CIDR]", UsageText: "cloudflared tunnel [--config FILEPATH] route ip delete [CIDR]",
Description: `Deletes the row for a given CIDR from your routing table. That portion Description: `Deletes the row for a given CIDR from your routing table. That portion
of your network will no longer be reachable by the WARP clients.`, of your network will no longer be reachable by the WARP clients.`,
}, },
{ {
Name: "get", Name: "get",
Action: cliutil.Action(getRouteByIPCommand), Action: cliutil.ConfiguredAction(getRouteByIPCommand),
Usage: "Check which row of the routing table matches a given IP.", Usage: "Check which row of the routing table matches a given IP.",
UsageText: "cloudflared tunnel [--config FILEPATH] route ip get [IP]", UsageText: "cloudflared tunnel [--config FILEPATH] route ip get [IP]",
Description: `Checks which row of the routing table will be used to proxy a given IP. Description: `Checks which row of the routing table will be used to proxy a given IP.

View File

@ -51,12 +51,12 @@ func runApp(app *cli.App, graceShutdownC chan struct{}) {
{ {
Name: "install", Name: "install",
Usage: "Install Argo Tunnel as a Windows service", Usage: "Install Argo Tunnel as a Windows service",
Action: cliutil.Action(installWindowsService), Action: cliutil.ConfiguredAction(installWindowsService),
}, },
{ {
Name: "uninstall", Name: "uninstall",
Usage: "Uninstall the Argo Tunnel service", Usage: "Uninstall the Argo Tunnel service",
Action: cliutil.Action(uninstallWindowsService), Action: cliutil.ConfiguredAction(uninstallWindowsService),
}, },
}, },
}) })