forked from cloudfoundry/cli
/
service_credential_binding.go
60 lines (50 loc) · 2.21 KB
/
service_credential_binding.go
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ccv3
import (
"github.com/LukasHeimann/cloudfoundrycli/v8/api/cloudcontroller/ccv3/internal"
"github.com/LukasHeimann/cloudfoundrycli/v8/resources"
"github.com/LukasHeimann/cloudfoundrycli/v8/util/lookuptable"
)
func (client *Client) CreateServiceCredentialBinding(binding resources.ServiceCredentialBinding) (JobURL, Warnings, error) {
return client.MakeRequest(RequestParams{
RequestName: internal.PostServiceCredentialBindingRequest,
RequestBody: binding,
})
}
// GetServiceCredentialBindings queries the CC API with the specified query
// and returns a slice of ServiceCredentialBindings. Additionally if Apps are
// included in the API response (by having `include=app` in the query) then the
// App names will be added into each ServiceCredentialBinding for app bindings
func (client *Client) GetServiceCredentialBindings(query ...Query) ([]resources.ServiceCredentialBinding, Warnings, error) {
var result []resources.ServiceCredentialBinding
included, warnings, err := client.MakeListRequest(RequestParams{
RequestName: internal.GetServiceCredentialBindingsRequest,
Query: query,
ResponseBody: resources.ServiceCredentialBinding{},
AppendToList: func(item interface{}) error {
result = append(result, item.(resources.ServiceCredentialBinding))
return nil
},
})
if len(included.Apps) > 0 {
appLookup := lookuptable.AppFromGUID(included.Apps)
for i := range result {
result[i].AppName = appLookup[result[i].AppGUID].Name
result[i].AppSpaceGUID = appLookup[result[i].AppGUID].SpaceGUID
}
}
return result, warnings, err
}
func (client *Client) DeleteServiceCredentialBinding(guid string) (JobURL, Warnings, error) {
return client.MakeRequest(RequestParams{
RequestName: internal.DeleteServiceCredentialBindingRequest,
URIParams: internal.Params{"service_credential_binding_guid": guid},
})
}
func (client *Client) GetServiceCredentialBindingDetails(guid string) (details resources.ServiceCredentialBindingDetails, warnings Warnings, err error) {
_, warnings, err = client.MakeRequest(RequestParams{
RequestName: internal.GetServiceCredentialBindingDetailsRequest,
URIParams: internal.Params{"service_credential_binding_guid": guid},
ResponseBody: &details,
})
return
}