Skip to content

CLI v7.1.0 "env" command panics if a variable contains values in "{{ }}" #2116

@jochenehret

Description

@jochenehret
  • I reviewed open and closed github issues that may be related to my problem.
  • I tried updating to the latest version of the CF CLI to see if it fixed my problem.
  • I attempted to run the command with CF_TRACE=1 to help debug the issue.
  • I am reporting a bug that others will be able to reproduce.

Describe the bug and the command you saw an issue with
We've run cf7 env <appname> and the command paniced with:

		Something unexpected happened. This is a bug in cf.

		Please re-run the command that caused this exception with the environment
		variable CF_TRACE set to true.

		Also, please update to the latest cli and try the command again:
		https://code.cloudfoundry.org/cli/releases

		Please create an issue at: https://code.cloudfoundry.org/cli/issues

		Include the below information when creating the issue:

		Command
		cf env service-broker-blue

		CLI Version
		7.1.0+4c3168f9a.2020-09-09

		Error
		template: Display Text:1: function "app_router_url" not defined

		Stack Trace
			goroutine 1 [running]:
	code.cloudfoundry.org/cli/util/panichandler.HandlePanic()
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/panichandler/handler.go:19 +0x81
	panic(0xfeec80, 0xc0005b8840)
		/usr/local/go/src/runtime/panic.go:679 +0x1b2
	text/template.Must(...)
		/usr/local/go/src/text/template/helper.go:23
	code.cloudfoundry.org/cli/util/ui.generateTranslationFunc.func1(0xc000568000, 0x6143, 0xc0005b87d0, 0x1, 0x1, 0x4d7ab1, 0x1bf9e40)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/ui/i18n.go:119 +0x40a
	code.cloudfoundry.org/cli/util/ui.(*UI).TranslateText(...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/ui/ui.go:308
	code.cloudfoundry.org/cli/util/ui.(*UI).DisplayText(0xc0000e5810, 0xc000568000, 0x6143, 0x0, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/ui/ui.go:246 +0x124
	code.cloudfoundry.org/cli/command/v7.EnvCommand.displayEnvGroup(0x13b0300, 0xc0000e5810, 0x13b9a40, 0xc00001c300, 0x1393360, 0xc0003b2d40, 0x13bd660, 0xc00083f680, 0xc00003d8c0, 0xc00052aa80, ...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/command/v7/env_command.go:97 +0x175
	code.cloudfoundry.org/cli/command/v7.EnvCommand.Execute(0x13b0300, 0xc0000e5810, 0x13b9a40, 0xc00001c300, 0x1393360, 0xc0003b2d40, 0x13bd660, 0xc00083f680, 0xc00003d8c0, 0xc00052aa80, ...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/command/v7/env_command.go:68 +0x6bf
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).executionWrapper(0xc00017b840, 0x7f93acaf8340, 0x1c23b18, 0xc00019d380, 0x0, 0x2, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:93 +0x270
	code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc000164af0, 0xc00003a040, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/vendor/github.com/jessevdk/go-flags/parser.go:331 +0x89c
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).parse(0xc00017b840, 0xc00003a040, 0x2, 0x2, 0x100e680, 0x1c21340, 0xc000000120, 0xed, 0xc000527e70)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:221 +0xe0
	code.cloudfoundry.org/cli/util/command_parser.(*CommandParser).ParseCommandFromArgs(...)
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/util/command_parser/command_parser.go:57
	main.main()
		/tmp/build/80754af9/gopath/src/code.cloudfoundry.org/cli/main.go:40 +0x19e

Calling cf6 env <appname> worked. The problematic environment variable seems to be this one:

SERVICEBROKER_CATALOG: {"services":
(... huge json ...)
 "endPointAddress": "{{app_router_url}}/SampleServices/ESPM.svc/v2"}

The app_router_url is interpreted as function call by the GoLang template package. As it is nowhere defined, this call panics:

formattedTemplate := template.Must(template.New("Display Text").Parse(translated))

What happened
(see description)

Expected behavior
We expected the application's environment variables to be printed.

Exact Steps To Reproduce
With CF CLI v7.1.0,

  1. Push a test app
  2. cf set-env testapp ENV_VAR "{'{{key}}': 'value'}"
  3. cf env testapp

Provide more context
Platform:

Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.5 LTS
Release:	18.04
Codename:	bionic

CF CLI versions:
cf7 version 7.1.0+4c3168f9a.2020-09-09 (doesn't work)
cf6 version 6.53.0+8e2b70a4a.2020-10-01 (works)

capi-release: 1.98.0

Notes regarding V6 and V7 CLI support:

  • V6:
    • Minimum supported version of CF Deployment: v7.0.0 (CAPI Release: 1.74.0 (APIs 2.128.0 and 3.63.0))
    • Maximum supported version of CF Deployment: v13.4.0 (CAPI Release: 1.94.0 (APIs 2.149.0 and 3.84.0))
  • V7:
    • Minimum supported version of CF Deployment: v13.5.0 (CAPI Release: 1.95.0 (APIs 2.150.0 and 3.85.0))

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions