Skip to content

JSON parsing fails for VCAP_SERVICES with complex credentials #11

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

Open
sklevenz opened this issue Jun 23, 2015 · 2 comments
Open

JSON parsing fails for VCAP_SERVICES with complex credentials #11

sklevenz opened this issue Jun 23, 2015 · 2 comments

Comments

@sklevenz
Copy link

Example env var provided by Redis service broker. Parser fails for "ports" key with

panic: 1 error(s) decoding:

* '[0].Credentials[ports]' expected type 'string', got unconvertible type 'map[string]interface {}' [recovered]
    panic: 1 error(s) decoding:
{
    "redis-lite": [
        {
            "credentials": {
                "hostname": "10.10.10.1",
                "password": "abc",
                "port": "32843",
                "ports": {
                    "6379/tcp": "32843"
                }
            },
            "label": "redis-lite",
            "name": "uptime-redis",
            "plan": "free",
            "tags": [
                "redis28",
                "redis",
                "key-value"
            ]
        }
    ]
}
@holgero
Copy link

holgero commented Sep 24, 2015

Seems to work just fine now.

package main

import (
    "github.com/cloudfoundry-community/go-cfenv"
    "log"
)

func main() {
    var envvars []string = []string{
        "VCAP_APPLICATION={}",
        `VCAP_SERVICES={
                          "redis": [
                            {
                              "name": "redis",
                              "label": "redis",
                              "tags": [
                                "redis"
                              ],
                              "plan": "free",
                              "credentials": {
                                "hostname": "1.2.3.4",
                                "port": "1234",
                                "password": "secret",
                                "ports": {
                                  "6379/tcp": "32843"
                                }
                              }
                            }
                          ]
                        }`,
    }
    env := cfenv.Env(envvars)
    app, err := cfenv.New(env)
    if err != nil {
        log.Println("Can not parse content of VCAP_SERVICES environment variable!", err)
        return
    }
    redisService, err := app.Services.WithName("redis")
    log.Println("Redis service: ", redisService)
}

Output of go run main.go is

2015/09/24 12:35:51 Redis service:  &{uptime-redis redis [redis] free map[hostname:1.2.3.4 port:1234 password:secret ports:map[6379/tcp:32843]]}

@joefitzgerald
Copy link
Member

Is this still an issue?

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

3 participants