Skip to content

Commit

Permalink
feat: option for cloudflared access login to only output jwt (#1249)
Browse files Browse the repository at this point in the history
Adds a -no-pretty flag to cloudflared access login:

```shell
$ cloudflared access login -no-pretty $url
<TOKEN>
```

This removes the need to parse the token from the output message, making it
easier for external applications.
  • Loading branch information
rjgpacheco committed May 20, 2024
1 parent 2db0021 commit e9e7c7f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cmd/cloudflared/access/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

const (
loginQuietFlag = "quiet"
noPrettyFlag = "no-pretty"
sshHostnameFlag = "hostname"
sshDestinationFlag = "destination"
sshURLFlag = "url"
Expand Down Expand Up @@ -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",
},
},
},
{
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit e9e7c7f

Please sign in to comment.