Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin does not handle vars injected as numbers. #124

Open
fussybeaver opened this issue Dec 4, 2020 · 0 comments
Open

Plugin does not handle vars injected as numbers. #124

fussybeaver opened this issue Dec 4, 2020 · 0 comments

Comments

@fussybeaver
Copy link

When using a legacy Drone YAML using this plugin, a number encoded as a string injected into the vars field will panic with

--
2 | panic: json: cannot unmarshal number into Go value of type string [recovered]
3 | panic: json: cannot unmarshal number into Go value of type string
4 |  
5 | goroutine 1 [running]:
6 | github.com/urfave/cli.HandleAction.func1(0xc0000e16c8)
7 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:478 +0x22d
8 | panic(0x840a40, 0xc000084780)
9 | /usr/local/go/src/runtime/panic.go:679 +0x1b2
10 | main.run(0xc0000a6780, 0x0, 0x0)
11 | /tmp/drone-terraform/main.go:136 +0xd27
12 | reflect.Value.call(0x82fce0, 0x8e07c8, 0x13, 0x8c1d6b, 0x4, 0xc000057688, 0x1, 0x1, 0xc0000d8170, 0x5, ...)
13 | /usr/local/go/src/reflect/value.go:460 +0x5f6
14 | reflect.Value.Call(0x82fce0, 0x8e07c8, 0x13, 0xc000057688, 0x1, 0x1, 0x1, 0x8c1680, 0x1)
15 | /usr/local/go/src/reflect/value.go:321 +0xb4
16 | github.com/urfave/cli.HandleAction(0x82fce0, 0x8e07c8, 0xc0000a6780, 0x0, 0x0)
17 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:487 +0x215
18 | github.com/urfave/cli.(*App).Run(0xc000001200, 0xc00001e1f0, 0x1, 0x1, 0x0, 0x0)
19 | /go/pkg/mod/github.com/urfave/cli@v0.0.0-20161006035353-55f715e28c46/app.go:245 +0x519
20 | main.main()
21 | /tmp/drone-terraform/main.go:119 +0xe5c

Example YAML:

pipeline:
  terraform:
    image: jmccann/drone-terraform:6.3-0.12.20
    root_dir: terraform/
    init_options:
      backend-config:
        - "config/backend.remote"
    vars:
      id: "11234567"

This gets transformed internally by Drone into:

---
kind: pipeline
name: default

platform:
  os: linux
  arch: amd64

steps:
- name: terraform
  pull: if-not-exists
  image: jmccann/drone-terraform:6.3-0.12.20
  settings:
    init_options:
      backend-config:
      - config/backend.remote
    root_dir: terraform/
    vars:
      id: 11234567

So, the string is coerced into a JNumber type (json type).

I think one could solve this by handling the deserialization as a map[string]interface{} rather than a map[string]string and then converting the type using fmt.Sprintf("%v", ...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant