MCPcopy Create free account
hub / github.com/cloudfoundry/credhub-cli / InterpolateString

Method InterpolateString

credhub/interpolate.go:11–38  ·  view source on GitHub ↗

InterpolateString translates credhub refs in a VCAP_SERVICES object into actual credentials

(vcapServicesBody string)

Source from the content-addressed store, hash-verified

9
10// InterpolateString translates credhub refs in a VCAP_SERVICES object into actual credentials
11func (ch *CredHub) InterpolateString(vcapServicesBody string) (string, error) {
12 if !strings.Contains(vcapServicesBody, `"credhub-ref"`) {
13 return vcapServicesBody, nil
14 }
15
16 requestBody := map[string]interface{}{}
17 if err := json.Unmarshal([]byte(vcapServicesBody), &requestBody); err != nil {
18 return "", err
19 }
20
21 resp, err := ch.Request(http.MethodPost, "/api/v1/interpolate", nil, requestBody, true)
22 if err != nil {
23 return "", err
24 }
25
26 defer resp.Body.Close()
27
28 if err := ch.checkForServerError(resp); err != nil {
29 return "", err
30 }
31
32 body, err := io.ReadAll(resp.Body)
33 if err != nil {
34 return "", err
35 }
36
37 return string(body), nil
38}

Callers 1

Calls 2

RequestMethod · 0.95
checkForServerErrorMethod · 0.95

Tested by

no test coverage detected