-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcftools.go
More file actions
36 lines (29 loc) · 916 Bytes
/
cftools.go
File metadata and controls
36 lines (29 loc) · 916 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package cftools
import (
"fmt"
"github.com/cloudfoundry-community/go-cfenv"
)
//GetVCAPServiceProperty retrieves a property from bound service credentials.
func GetVCAPServiceProperty(serviceName string, propertyName string, appEnv *cfenv.App) (propertyValue string, err error) {
if propertyName == "" {
return "", fmt.Errorf("Must supply a property name value.")
}
service, err := getVCAPService(serviceName, appEnv)
if err != nil {
return "", err
}
propertyValue = service.Credentials[propertyName].(string)
if propertyValue == "" {
return "", fmt.Errorf("Error retrieving property %v", propertyName)
}
return
}
func getVCAPService(serviceName string, appEnv *cfenv.App) (service *cfenv.Service, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("Error retrieving VCAP Service: %v", r)
}
}()
service, err = appEnv.Services.WithName(serviceName)
return
}