-
Notifications
You must be signed in to change notification settings - Fork 594
/
cloudFoundryDeleteSpace.go
60 lines (42 loc) · 1.58 KB
/
cloudFoundryDeleteSpace.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 cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/cloudfoundry"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func cloudFoundryDeleteSpace(config cloudFoundryDeleteSpaceOptions, telemetryData *telemetry.CustomData) {
c := command.Command{}
// reroute command output to logging framework
c.Stdout(log.Writer())
c.Stderr(log.Writer())
cf := cloudfoundry.CFUtils{
Exec: &c,
}
err := runCloudFoundryDeleteSpace(&config, telemetryData, cf, &c)
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runCloudFoundryDeleteSpace(config *cloudFoundryDeleteSpaceOptions, telemetryData *telemetry.CustomData, cf cloudfoundry.CFUtils, s command.ShellRunner) (err error) {
var c = cf.Exec
cfLoginError := s.RunShell("/bin/sh", fmt.Sprintf("yes '' | cf login -a %s -u %s -p %s", config.CfAPIEndpoint, config.Username, config.Password))
if cfLoginError != nil {
return fmt.Errorf("Error while logging in occured: %w", cfLoginError)
}
defer func() {
logoutErr := cf.Logout()
if logoutErr != nil {
err = fmt.Errorf("Error while logging out occured: %w", logoutErr)
}
}()
log.Entry().Infof("Deleting Cloud Foundry Space: '%s'", config.CfSpace)
cfDeleteSpaceScript := []string{"delete-space", config.CfSpace, "-o", config.CfOrg, "-f"}
err = c.RunExecutable("cf", cfDeleteSpaceScript...)
if err != nil {
return fmt.Errorf("Deletion of cf space has failed: %w", err)
}
log.Entry().Info("Cloud foundry space has been deleted successfully")
return err
}