From e9e7c7fe4aad5f2207a0395f263a3c3a67914ab7 Mon Sep 17 00:00:00 2001 From: Ricardo Pacheco <3099433+rjgpacheco@users.noreply.github.com> Date: Mon, 20 May 2024 19:27:02 +0100 Subject: [PATCH] feat: option for cloudflared access login to only output jwt (#1249) Adds a -no-pretty flag to cloudflared access login: ```shell $ cloudflared access login -no-pretty $url ``` This removes the need to parse the token from the output message, making it easier for external applications. --- cmd/cloudflared/access/cmd.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/cloudflared/access/cmd.go b/cmd/cloudflared/access/cmd.go index b1770f1b..20831d22 100644 --- a/cmd/cloudflared/access/cmd.go +++ b/cmd/cloudflared/access/cmd.go @@ -27,6 +27,7 @@ import ( const ( loginQuietFlag = "quiet" + noPrettyFlag = "no-pretty" sshHostnameFlag = "hostname" sshDestinationFlag = "destination" sshURLFlag = "url" @@ -97,6 +98,10 @@ func Commands() []*cli.Command { Aliases: []string{"q"}, Usage: "do not print the jwt to the command line", }, + &cli.BoolFlag{ + Name: noPrettyFlag, + Usage: "only print the jwt to the command line", + }, }, }, { @@ -261,7 +266,12 @@ func login(c *cli.Context) error { if c.Bool(loginQuietFlag) { return nil } - fmt.Fprintf(os.Stdout, "Successfully fetched your token:\n\n%s\n\n", cfdToken) + + if c.Bool(noPrettyFlag) { + fmt.Fprintf(os.Stdout, cfdToken) + } else { + fmt.Fprintf(os.Stdout, "Successfully fetched your token:\n\n%s\n\n", cfdToken) + } return nil }