Skip to content

Commit

Permalink
handle nested "credentials" in service key output
Browse files Browse the repository at this point in the history
[#184260867](https://www.pivotaltracker.com/story/show/184260867)

Co-authored-by: Andrew Garner <[email protected]>
Co-authored-by: Kim Bassett <[email protected]>
  • Loading branch information
abg and kimago committed Jul 24, 2023
1 parent cf9fdc3 commit 123dceb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion system_tests/test_helpers/cf_helpers/service_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/onsi/gomega/gexec"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

Expand All @@ -31,12 +32,25 @@ func CreateServiceKey(serviceName, serviceKeyName string) {
}

func GetServiceKey(serviceName, serviceKeyName string) string {
GinkgoHelper()

serviceKey := Cf("service-key", serviceName, serviceKeyName)
Expect(serviceKey).To(gexec.Exit(0))
serviceKeyContent := string(serviceKey.Buffer().Contents())

firstBracket := strings.Index(serviceKeyContent, "{")
return serviceKeyContent[firstBracket:]

var m map[string]any
Expect(json.Unmarshal([]byte(serviceKeyContent[firstBracket:]), &m)).To(Succeed())

if nested, ok := m["credentials"].(map[string]any); ok {
m = nested
}

serviceKeyRaw, err := json.Marshal(m)
Expect(err).NotTo(HaveOccurred())

return string(serviceKeyRaw)
}

func DeleteServiceKey(serviceName, serviceKeyName string) {
Expand Down

0 comments on commit 123dceb

Please sign in to comment.