1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-04 04:07:16 +02:00
sap-jenkins-library/cmd/cloudFoundryCreateServiceKey.go
dominiklendle 66636d68f9
Hotfix for ServiceKey config parameter (#1377)
Changed from passing config as an array that was implemented badly to correct implementation that JSON config gets passed with ' '

Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
2020-04-09 16:57:50 +02:00

76 lines
2.0 KiB
Go

package cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func cloudFoundryCreateServiceKey(options cloudFoundryCreateServiceKeyOptions, telemetryData *telemetry.CustomData) {
// for command execution use Command
c := command.Command{}
// reroute command output to logging framework
c.Stdout(log.Entry().Writer())
c.Stderr(log.Entry().Writer())
config := cloudFoundryDeleteServiceOptions{
CfAPIEndpoint: options.CfAPIEndpoint,
CfOrg: options.CfOrg,
CfSpace: options.CfSpace,
Username: options.Username,
Password: options.Password,
}
var err error
err = cloudFoundryLogin(config, &c)
if err == nil {
err = runCloudFoundryCreateServiceKey(&options, telemetryData, &c)
}
var logoutErr error
if err == nil {
logoutErr = cloudFoundryLogout(&c)
if logoutErr != nil {
log.Entry().
WithError(logoutErr).
Fatal("Error while logging out occured.")
}
} else if err != nil {
logoutErr = cloudFoundryLogout(&c)
if logoutErr != nil {
log.Entry().
WithError(logoutErr).
Fatal("Error while logging out occured.")
}
log.Entry().
WithError(err).
Fatal("Error occured during step.")
}
}
func runCloudFoundryCreateServiceKey(config *cloudFoundryCreateServiceKeyOptions, telemetryData *telemetry.CustomData, c execRunner) error {
log.Entry().Info("Creating Service Key")
var cfCreateServiceKeyScript []string
if config.CfServiceKeyConfig == "" {
cfCreateServiceKeyScript = []string{"create-service-key", config.CfServiceInstance, config.CfServiceKeyName}
} else {
cfCreateServiceKeyScript = []string{"create-service-key", config.CfServiceInstance, config.CfServiceKeyName, "-c '", config.CfServiceKeyConfig, "'"}
fmt.Println(cfCreateServiceKeyScript)
}
err := c.RunExecutable("cf", cfCreateServiceKeyScript...)
if err != nil {
return fmt.Errorf("Failed to Create Service Key: %w", err)
}
return nil
}