Skip to content

Commit 42750e9

Browse files
authored
feat: support TANKA_DANGEROUS_ALLOW_REDIRECT env variable (#1582)
Read TANKA_DANGEROUS_ALLOW_REDIRECT to as an alternative to --dangerous-allow-redirect I use 'tk show' quite frequently from the cli, I (think I) know what I'm doing, I'd like to permanently allow the dangerous redirects. Signed-off-by: Oleg Zaytsev <[email protected]>
1 parent d8757cd commit 42750e9

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

cmd/tk/workflow.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,23 @@ func showCmd() *cli.Command {
275275
Args: workflowArgs,
276276
}
277277

278-
allowRedirect := cmd.Flags().Bool("dangerous-allow-redirect", false, "allow redirecting output to a file or a pipe.")
278+
allowRedirectFlag := cmd.Flags().Bool("dangerous-allow-redirect", false, "allow redirecting output to a file or a pipe.")
279279

280280
vars := workflowFlags(cmd.Flags())
281281
getJsonnetOpts := jsonnetFlags(cmd.Flags())
282282

283283
cmd.Run = func(_ *cli.Command, args []string) error {
284-
if !interactive && !*allowRedirect {
284+
allowRedirectEnv := os.Getenv("TANKA_DANGEROUS_ALLOW_REDIRECT") == "true"
285+
allowRedirect := allowRedirectEnv || *allowRedirectFlag
286+
287+
if !interactive && !allowRedirect {
285288
fmt.Fprintln(os.Stderr, `Redirection of the output of tk show is discouraged and disabled by default.
286289
If you want to export .yaml files for use with other tools, try 'tk export'.
287-
Otherwise run tk show --dangerous-allow-redirect to bypass this check.`)
290+
Otherwise run:
291+
tk show --dangerous-allow-redirect
292+
or set the environment variable
293+
TANKA_DANGEROUS_ALLOW_REDIRECT=true
294+
to bypass this check.`)
288295
return nil
289296
}
290297

docs/src/content/docs/env-vars.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ sidebar:
3838

3939
**Description**: Pager to use when displaying output. Only used if TANKA_PAGER is not set. Set to an empty string to disable paging.
4040
**Default**: `less --RAW-CONTROL-CHARS --quit-if-one-screen --no-init`
41+
42+
## TANKA_DANGEROUS_ALLOW_REDIRECT
43+
44+
**Description**: Allow redirection of the output of `tk show` to other commands when set to `true`, same as the `--dangerous-allow-redirect ` flag. Redirection of the output of `tk show` is discouraged and disabled by default. If you want to export `.yaml` files for use with other tools, try `tk export`.
45+
**Default**: `false`

0 commit comments

Comments
 (0)