InterpolateString translates credhub refs in a VCAP_SERVICES object into actual credentials
(vcapServicesBody string)
| 9 | |
| 10 | // InterpolateString translates credhub refs in a VCAP_SERVICES object into actual credentials |
| 11 | func (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 | } |
no test coverage detected