-
Notifications
You must be signed in to change notification settings - Fork 0
/
deprovision.go
executable file
·51 lines (43 loc) · 1.26 KB
/
deprovision.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
package broker
import (
"context"
"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
brokerapi "github.com/pivotal-cf/brokerapi/domain"
"github.com/starkandwayne/scs-broker/broker/utilities"
)
func (broker *SCSBroker) Deprovision(ctx context.Context, instanceID string, details brokerapi.DeprovisionDetails, asyncAllowed bool) (brokerapi.DeprovisionServiceSpec, error) {
spec := brokerapi.DeprovisionServiceSpec{}
cfClient, err := broker.GetClient()
if err != nil {
return spec, err
}
appName := utilities.MakeAppName(details.ServiceID, instanceID)
app, _, err := cfClient.GetApplicationByNameAndSpace(appName, broker.Config.InstanceSpaceGUID)
appNotFound := ccerror.ApplicationNotFoundError{Name: appName}
if err == appNotFound {
broker.Logger.Info("app-not-found")
return spec, nil
}
if err != nil {
return spec, err
}
routes, _, err := cfClient.GetApplicationRoutes(app.GUID)
if err != nil {
return spec, err
}
_, _, err = cfClient.UpdateApplicationStop(app.GUID)
if err != nil {
return spec, err
}
for route := range routes {
_, _, err := cfClient.DeleteRoute(routes[route].GUID)
if err != nil {
return spec, err
}
}
_, _, err = cfClient.DeleteApplication(app.GUID)
if err != nil {
return spec, err
}
return spec, nil
}