-
Notifications
You must be signed in to change notification settings - Fork 0
/
unbind.go
39 lines (32 loc) · 1.44 KB
/
unbind.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
package broker
import (
"context"
"code.cloudfoundry.org/lager"
"github.com/pivotal-cf/brokerapi"
)
func (bkr *MarketplaceBrokerImpl) Unbind(ctx context.Context, instanceID, bindingID string, details brokerapi.UnbindDetails, asyncAllowed bool) (unbindSpec brokerapi.UnbindSpec, err error) {
bkr.Logger.Info("unbind.start", lager.Data{"instanceID": instanceID, "bindID": bindingID})
cfclient, err := bkr.CF.Client()
if err != nil {
return unbindSpec, brokerapi.NewFailureResponse(err, 400, "cf-client")
}
cfSvcInstance, err := bkr.lookupServiceInstance(cfclient, instanceID)
if err != nil {
// Whilst it is an internal error, if the backend service doesn't exist anymore then allow Unbind to succeed.
bkr.Logger.Error("lookup-service-instance", err, lager.Data{"instanceID": instanceID, "bindID": bindingID})
return unbindSpec, nil
}
cfSvcKey, err := bkr.lookupServiceKey(cfclient, cfSvcInstance, bindingID)
if err != nil {
// Whilst it is an internal error, if the backend service key doesn't exist anymore then allow Unbind to succeed.
bkr.Logger.Error("lookup-service-key", err, lager.Data{"instanceID": instanceID, "bindID": bindingID})
return unbindSpec, nil
}
err = cfclient.DeleteServiceKey(cfSvcKey.Guid)
if err != nil {
return unbindSpec, brokerapi.NewFailureResponse(err, 400, "delete-service-key")
}
unbindSpec.IsAsync = false
bkr.Logger.Info("unbind.end", lager.Data{"instanceID": instanceID, "bindID": bindingID})
return
}