-
Notifications
You must be signed in to change notification settings - Fork 0
/
bind.go
49 lines (40 loc) · 1.84 KB
/
bind.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
package broker
import (
"context"
"code.cloudfoundry.org/lager"
cf "github.com/cloudfoundry-community/go-cfclient"
"github.com/pivotal-cf/brokerapi"
)
// Bind forwards on a service instance bind request to the backend Cloud Foundry API
// Bind is implemented with CF Service Keys. Currently these do not support asynchronous bindings https://github.com/cloudfoundry/cloud_controller_ng/issues/1246
func (bkr *MarketplaceBrokerImpl) Bind(ctx context.Context, instanceID, bindingID string, details brokerapi.BindDetails, asyncAllowed bool) (svcBinding brokerapi.Binding, err error) {
bkr.Logger.Info("bind.start", lager.Data{"instanceID": instanceID, "bindID": bindingID})
cfclient, err := bkr.CF.Client()
if err != nil {
return svcBinding, brokerapi.NewFailureResponse(err, 400, "cf-client")
}
cfSvcInstance, err := bkr.lookupServiceInstance(cfclient, instanceID)
if err != nil {
return svcBinding, brokerapi.NewFailureResponse(err, 400, "lookup-service")
}
// TODO: The services that do not support service keys also don't support any binding
// TODO: Test more services until we find at least 1 that supports binding but not service keys
// TODO: else delete this code
// cfBindResp, err := cfclient.CreateServiceBinding(bkr.CF.BindingAppGUID, cfSvcInstance.Guid)
// if err != nil {
// return svcBinding, brokerapi.NewFailureResponse(err, 400, "create-binding")
// }
// svcBinding.Credentials = cfBindResp.Credentials
svcKeyReq := cf.CreateServiceKeyRequest{
ServiceInstanceGuid: cfSvcInstance.Guid,
Name: bindingID,
// Parameters:
}
svcKey, err := cfclient.CreateServiceKey(svcKeyReq)
if err != nil {
return svcBinding, brokerapi.NewFailureResponse(err, 400, "create-service-key")
}
svcBinding.Credentials = svcKey.Credentials
bkr.Logger.Info("bind.end", lager.Data{"instanceID": instanceID, "bindID": bindingID})
return
}