From 619d1ccff544648cc5047c02b6d8f51fdc1a60c7 Mon Sep 17 00:00:00 2001 From: Benjamin Ihrig Date: Wed, 20 Jun 2018 09:48:02 -0700 Subject: [PATCH] Add alternative credentials claim for host. Adresses #167 --- exporter/discovery.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/exporter/discovery.go b/exporter/discovery.go index 60816470..962776c6 100644 --- a/exporter/discovery.go +++ b/exporter/discovery.go @@ -86,8 +86,11 @@ func GetCloudFoundryRedisBindings() (addrs, passwords, aliases []string) { for _, redisService := range redisServices { credentials := redisService.Credentials - addr := credentials["hostname"].(string) + ":" + credentials["port"].(string) - password := credentials["password"].(string) + host := getAlternative(credentials, "host", "hostname") + port := getAlternative(credentials, "port") + password := getAlternative(credentials, "password") + + addr := host + ":" + port alias := redisService.Name addrs = append(addrs, addr) @@ -97,3 +100,12 @@ func GetCloudFoundryRedisBindings() (addrs, passwords, aliases []string) { return } + +func getAlternative(credentials map[string]interface{}, alternatives ...string) string { + for _, key := range alternatives { + if value, ok := credentials[key]; ok { + return value.(string) + } + } + return "" +}