mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
ac732b3065
* Minor changes * Changed groovy file * Changed generated file * Changed yaml with container config * Changed groovy config * minor changes * minor changes * Changed yaml with aliases * minor changes * minor changes * minor changes * minor changes * minor changes * minor changes * minor changes * minor changes * minor changes * minor changes * Changed yaml aliases * Adapted naming conventions * Removed error code at the end * Adapted configuration * Minor changes * Minor changes * Minor changes * Removed spaces * Removed docker-related config from groovy file * Minor changes * Minor changes * Removed container config * Corrected testing function name * Deleted unnecessary parts * Changed service deletion message * Changed service deletion message * Logging out before throwing error service deletion step fails * Minor changes * Minor changes * Minor changes * Delete .DS_Store * Delete .DS_Store * Delete .DS_Store * Delete .DS_Store * Minor changes * Minor changes * Minor changes * Added newline at end of file * Added newline at end of file * Changes for Pull request optimization * added documentaion * Adapted documentation * Adapted documentation * Adapted documentation * Adapted documentation * Adapted documentation * Added CFDeleteServiceKeys * Added ServiceKey deletion tests * added cfServiceKeys flag explanation to documentation * removed trailing spaces from documentation * resolving conflicts * Changed deletion message an variable naming * Changed tests * Changed tests * Changed tests * Changed tests * Changed CloudFoundryDeleteServiceOptions to options * Changed CloudFoundryDeleteServiceOptions to options * Minor changes * Minor changes * Changed variable naming * Changed error handling * Changed error handling and logging * Changed documentation * Simplified code * Fixed CodeClimate issues * Changed from returning err to nil where no errur returned needed * Add cloudFoundryCreateServiceKey Go Step * Changed Groovy File * Changed aliases * Removed unneccessary parts * Minor changes * Minor changes * Adapted documentation * Adapted tests * Adapted Groovy File * Changed Groovy file * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Removed Groovy Tests for cfCreateServiceKey * Minor changes * Added ATC Check YAML * Added ATC Check generated files * Added test class * Added abapEnvironmentRunATCCheck * Minor changes * Minor changes * Changed groovy * Minor changes * Changed groovy * Changed groovy * Minor changes * Adapted Groovy imports * Adapted Groovy imports * Adapted Groovy imports * Adapted Groovy * Getting ATC results * Changed error message * changed groovy * removed trailing spaces * Added login check * Minor changes * Added step to whitelistScriptReference * Added ATC error message handling * Added groovy file * Added step to groovy tests * corrected metadata file * Debugging * Debugging * Added yaml config parameter for ATC run * Adapted file location of ATC run config to jenkins specific location * Implementing universal pipeline logic for finding yaml config regardless of pipeline * Changed error handling for reading config yaml file * Changed atcrunconfig alias * minor changes * Minor changes * Minor changes * Changed back to dynamic file reading * Minor changes * filepath changes * Removing CF Login * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Minor changes * Removed whitespaces * Added CF functions unit tests * Added invalid parameter handling * Removed package and SC flag * Minor changes * Changed tests * Changed tests * Changed tests * Minor changes * Changed tests * removed unnecessary logout * Added documentation * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Changed docu * Removed trailing spaces * Added newline at end of file * code climate fixes * code climate fixes * code climate fixes * Minor changes * Minor changes * Minor changes * Changed tests * Test changes * Splitted Cloud Foundry functions into two classes * Removed two steps from whtielistScriptReference * removed atcrunConfig alias * issue fixes * Changed docu * Changed docu * Changed docu * Removed trailing spaced from docu * Changed docu * Go generator run * Issue fixes * Remove unnecessary imports Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Update whitelistScript Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com> * Adding piperutils for writing xml file * Persisting ATC Results with piperutils * Set failonMissingReports to true * Refactoring for CodeClimate * Changed result file name * Changed credentials aliases * changing secret name * Removing trailing spaces * Added secret name and alias to docu Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com> Co-authored-by: Christopher Fenner <26137398+CCFenner@users.noreply.github.com>
111 lines
3.3 KiB
Go
111 lines
3.3 KiB
Go
package cloudfoundry
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
)
|
|
|
|
//ReadServiceKeyAbapEnvironment from Cloud Foundry and returns it.
|
|
//Depending on user/developer requirements if he wants to perform further Cloud Foundry actions the cfLogoutOption parameters gives the option to logout after reading ABAP communication arrangement or not.
|
|
func ReadServiceKeyAbapEnvironment(options ServiceKeyOptions, cfLogoutOption bool) (ServiceKey, error) {
|
|
var abapServiceKey ServiceKey
|
|
var err error
|
|
|
|
//Logging into Cloud Foundry
|
|
config := LoginOptions{
|
|
CfAPIEndpoint: options.CfAPIEndpoint,
|
|
CfOrg: options.CfOrg,
|
|
CfSpace: options.CfSpace,
|
|
Username: options.Username,
|
|
Password: options.Password,
|
|
}
|
|
|
|
err = Login(config)
|
|
var serviceKeyBytes bytes.Buffer
|
|
c.Stdout(&serviceKeyBytes)
|
|
if err == nil {
|
|
//Reading Service Key
|
|
log.Entry().WithField("cfServiceInstance", options.CfServiceInstance).WithField("cfServiceKey", options.CfServiceKey).Info("Read service key for service instance")
|
|
|
|
cfReadServiceKeyScript := []string{"service-key", options.CfServiceInstance, options.CfServiceKey}
|
|
|
|
err = c.RunExecutable("cf", cfReadServiceKeyScript...)
|
|
}
|
|
if err == nil {
|
|
var serviceKeyJSON string
|
|
|
|
if len(serviceKeyBytes.String()) > 0 {
|
|
var lines []string = strings.Split(serviceKeyBytes.String(), "\n")
|
|
serviceKeyJSON = strings.Join(lines[2:], "")
|
|
}
|
|
|
|
json.Unmarshal([]byte(serviceKeyJSON), &abapServiceKey)
|
|
if abapServiceKey == (ServiceKey{}) {
|
|
return abapServiceKey, errors.New("Parsing the service key failed")
|
|
}
|
|
|
|
log.Entry().Info("Service Key read successfully")
|
|
}
|
|
if err != nil {
|
|
if cfLogoutOption == true {
|
|
var logoutErr error
|
|
logoutErr = Logout()
|
|
if logoutErr != nil {
|
|
return abapServiceKey, fmt.Errorf("Failed to Logout of Cloud Foundry: %w", err)
|
|
}
|
|
}
|
|
return abapServiceKey, fmt.Errorf("Reading Service Key failed: %w", err)
|
|
}
|
|
|
|
//Logging out of CF
|
|
if cfLogoutOption == true {
|
|
var logoutErr error
|
|
logoutErr = Logout()
|
|
if logoutErr != nil {
|
|
return abapServiceKey, fmt.Errorf("Failed to Logout of Cloud Foundry: %w", err)
|
|
}
|
|
}
|
|
return abapServiceKey, nil
|
|
}
|
|
|
|
//ServiceKeyOptions for reading CF Service Key
|
|
type ServiceKeyOptions struct {
|
|
CfAPIEndpoint string
|
|
CfOrg string
|
|
CfSpace string
|
|
CfServiceInstance string
|
|
CfServiceKey string
|
|
Username string
|
|
Password string
|
|
}
|
|
|
|
//ServiceKey struct to parse CF Service Key
|
|
type ServiceKey struct {
|
|
Abap AbapConnection `json:"abap"`
|
|
Binding AbapBinding `json:"binding"`
|
|
Systemid string `json:"systemid"`
|
|
URL string `json:"url"`
|
|
}
|
|
|
|
//AbapConnection contains information about the ABAP connection for the ABAP endpoint
|
|
type AbapConnection struct {
|
|
CommunicationArrangementID string `json:"communication_arrangement_id"`
|
|
CommunicationScenarioID string `json:"communication_scenario_id"`
|
|
CommunicationSystemID string `json:"communication_system_id"`
|
|
Password string `json:"password"`
|
|
Username string `json:"username"`
|
|
}
|
|
|
|
//AbapBinding contains information about service binding in Cloud Foundry
|
|
type AbapBinding struct {
|
|
Env string `json:"env"`
|
|
ID string `json:"id"`
|
|
Type string `json:"type"`
|
|
Version string `json:"version"`
|
|
}
|