-
Notifications
You must be signed in to change notification settings - Fork 5
/
delete_service_instance.go
54 lines (47 loc) · 1.44 KB
/
delete_service_instance.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
package clients
import (
models "cf-html5-apps-repo-cli-plugin/clients/models"
"cf-html5-apps-repo-cli-plugin/log"
"encoding/json"
"errors"
"strings"
"github.com/cloudfoundry/cli/plugin"
)
// DeleteServiceInstance delete Cloud Foundry service instance
func DeleteServiceInstance(cliConnection plugin.CliConnection, serviceInstanceGUID string, maxRetryCount int) error {
var err error
var url string
var responseStrings []string
var responseBytes []byte
var errorResponseObject models.CFErrorResponse
var currentTry = 1
url = "/v2/service_instances/" + serviceInstanceGUID + "?recursive=true"
for currentTry <= maxRetryCount {
log.Tracef("Making request to (try %d/%d): %s\n", currentTry, maxRetryCount, url)
responseStrings, err = cliConnection.CliCommandWithoutTerminalOutput("curl", url, "-X", "DELETE")
if err != nil {
return err
}
responseBytes = []byte(strings.Join(responseStrings, ""))
if len(responseBytes) > 0 {
log.Tracef("Response is not empty, maybe error: %+v\n", responseStrings)
err = json.Unmarshal(responseBytes, &errorResponseObject)
if err != nil {
return err
}
if errorResponseObject.ErrorCode != nil {
if currentTry == maxRetryCount {
if errorResponseObject.Description != nil {
return errors.New(*errorResponseObject.Description)
}
return errors.New(strings.Join(responseStrings, "\n"))
}
currentTry++
continue
}
} else {
return nil
}
}
return err
}