2020-08-04 17:52:28 +02:00
// Code generated by piper's step-generator. DO NOT EDIT.
package cmd
import (
"fmt"
"os"
"time"
"github.com/SAP/jenkins-library/pkg/config"
"github.com/SAP/jenkins-library/pkg/log"
2021-05-17 12:14:04 +02:00
"github.com/SAP/jenkins-library/pkg/splunk"
2020-08-04 17:52:28 +02:00
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/spf13/cobra"
)
type abapEnvironmentCheckoutBranchOptions struct {
Username string ` json:"username,omitempty" `
Password string ` json:"password,omitempty" `
RepositoryName string ` json:"repositoryName,omitempty" `
BranchName string ` json:"branchName,omitempty" `
Host string ` json:"host,omitempty" `
2020-10-05 14:38:35 +02:00
Repositories string ` json:"repositories,omitempty" `
2020-08-04 17:52:28 +02:00
CfAPIEndpoint string ` json:"cfApiEndpoint,omitempty" `
CfOrg string ` json:"cfOrg,omitempty" `
CfSpace string ` json:"cfSpace,omitempty" `
CfServiceInstance string ` json:"cfServiceInstance,omitempty" `
CfServiceKeyName string ` json:"cfServiceKeyName,omitempty" `
}
// AbapEnvironmentCheckoutBranchCommand Switches between branches of a git repository on a SAP Cloud Platform ABAP Environment system
func AbapEnvironmentCheckoutBranchCommand ( ) * cobra . Command {
const STEP_NAME = "abapEnvironmentCheckoutBranch"
metadata := abapEnvironmentCheckoutBranchMetadata ( )
var stepConfig abapEnvironmentCheckoutBranchOptions
var startTime time . Time
2021-05-17 12:14:04 +02:00
var logCollector * log . CollectorHook
2020-08-04 17:52:28 +02:00
var createAbapEnvironmentCheckoutBranchCmd = & cobra . Command {
Use : STEP_NAME ,
Short : "Switches between branches of a git repository on a SAP Cloud Platform ABAP Environment system" ,
Long : ` This step switches between branches of a git repository ( Software Component ) on a SAP Cloud Platform ABAP Environment system .
Please provide either of the following options :
2020-10-15 14:57:33 +02:00
* The host and credentials the Cloud Platform ABAP Environment system itself . The credentials must be configured for the Communication Scenario [ SAP_COM_0510 ] ( https : //help.sap.com/viewer/65de2977205c403bbc107264b8eccf4b/Cloud/en-US/b04a9ae412894725a2fc539bfb1ca055.html).
2020-08-04 17:52:28 +02:00
* The Cloud Foundry parameters ( API endpoint , organization , space ) , credentials , the service instance for the ABAP service and the service key for the Communication Scenario SAP_COM_0510 .
* Only provide one of those options with the respective credentials . If all values are provided , the direct communication ( via host ) has priority . ` ,
PreRunE : func ( cmd * cobra . Command , _ [ ] string ) error {
startTime = time . Now ( )
log . SetStepName ( STEP_NAME )
log . SetVerbose ( GeneralConfig . Verbose )
path , _ := os . Getwd ( )
fatalHook := & log . FatalHook { CorrelationID : GeneralConfig . CorrelationID , Path : path }
log . RegisterHook ( fatalHook )
err := PrepareConfig ( cmd , & metadata , STEP_NAME , & stepConfig , config . OpenPiperFile )
if err != nil {
log . SetErrorCategory ( log . ErrorConfiguration )
return err
}
log . RegisterSecret ( stepConfig . Username )
log . RegisterSecret ( stepConfig . Password )
if len ( GeneralConfig . HookConfig . SentryConfig . Dsn ) > 0 {
sentryHook := log . NewSentryHook ( GeneralConfig . HookConfig . SentryConfig . Dsn , GeneralConfig . CorrelationID )
log . RegisterHook ( & sentryHook )
}
2021-05-17 12:14:04 +02:00
if len ( GeneralConfig . HookConfig . SplunkConfig . Dsn ) > 0 {
logCollector = & log . CollectorHook { CorrelationID : GeneralConfig . CorrelationID }
log . RegisterHook ( logCollector )
}
2020-08-04 17:52:28 +02:00
return nil
} ,
Run : func ( _ * cobra . Command , _ [ ] string ) {
telemetryData := telemetry . CustomData { }
telemetryData . ErrorCode = "1"
handler := func ( ) {
2020-10-26 15:20:04 +02:00
config . RemoveVaultSecretFiles ( )
2020-08-04 17:52:28 +02:00
telemetryData . Duration = fmt . Sprintf ( "%v" , time . Since ( startTime ) . Milliseconds ( ) )
2020-09-29 13:49:40 +02:00
telemetryData . ErrorCategory = log . GetErrorCategory ( ) . String ( )
2020-08-04 17:52:28 +02:00
telemetry . Send ( & telemetryData )
2021-05-17 12:14:04 +02:00
if len ( GeneralConfig . HookConfig . SplunkConfig . Dsn ) > 0 {
splunk . Send ( & telemetryData , logCollector )
}
2020-08-04 17:52:28 +02:00
}
log . DeferExitHandler ( handler )
defer handler ( )
telemetry . Initialize ( GeneralConfig . NoTelemetry , STEP_NAME )
2021-05-17 12:14:04 +02:00
if len ( GeneralConfig . HookConfig . SplunkConfig . Dsn ) > 0 {
splunk . Initialize ( GeneralConfig . CorrelationID ,
GeneralConfig . HookConfig . SplunkConfig . Dsn ,
GeneralConfig . HookConfig . SplunkConfig . Token ,
GeneralConfig . HookConfig . SplunkConfig . Index ,
GeneralConfig . HookConfig . SplunkConfig . SendLogs )
}
2020-08-04 17:52:28 +02:00
abapEnvironmentCheckoutBranch ( stepConfig , & telemetryData )
telemetryData . ErrorCode = "0"
log . Entry ( ) . Info ( "SUCCESS" )
} ,
}
addAbapEnvironmentCheckoutBranchFlags ( createAbapEnvironmentCheckoutBranchCmd , & stepConfig )
return createAbapEnvironmentCheckoutBranchCmd
}
func addAbapEnvironmentCheckoutBranchFlags ( cmd * cobra . Command , stepConfig * abapEnvironmentCheckoutBranchOptions ) {
cmd . Flags ( ) . StringVar ( & stepConfig . Username , "username" , os . Getenv ( "PIPER_username" ) , "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510" )
cmd . Flags ( ) . StringVar ( & stepConfig . Password , "password" , os . Getenv ( "PIPER_password" ) , "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0510" )
cmd . Flags ( ) . StringVar ( & stepConfig . RepositoryName , "repositoryName" , os . Getenv ( "PIPER_repositoryName" ) , "Specifies a Repository (Software Component) on the SAP Cloud Platform ABAP Environment system" )
cmd . Flags ( ) . StringVar ( & stepConfig . BranchName , "branchName" , os . Getenv ( "PIPER_branchName" ) , "Specifies a Branch of a Repository (Software Component) on the SAP Cloud Platform ABAP Environment system" )
cmd . Flags ( ) . StringVar ( & stepConfig . Host , "host" , os . Getenv ( "PIPER_host" ) , "Specifies the host address of the SAP Cloud Platform ABAP Environment system" )
2020-10-05 14:38:35 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . Repositories , "repositories" , os . Getenv ( "PIPER_repositories" ) , "Specifies a YAML file containing the repositories configuration" )
2020-08-04 17:52:28 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . CfAPIEndpoint , "cfApiEndpoint" , os . Getenv ( "PIPER_cfApiEndpoint" ) , "Cloud Foundry API Enpoint" )
cmd . Flags ( ) . StringVar ( & stepConfig . CfOrg , "cfOrg" , os . Getenv ( "PIPER_cfOrg" ) , "Cloud Foundry target organization" )
cmd . Flags ( ) . StringVar ( & stepConfig . CfSpace , "cfSpace" , os . Getenv ( "PIPER_cfSpace" ) , "Cloud Foundry target space" )
cmd . Flags ( ) . StringVar ( & stepConfig . CfServiceInstance , "cfServiceInstance" , os . Getenv ( "PIPER_cfServiceInstance" ) , "Cloud Foundry Service Instance" )
cmd . Flags ( ) . StringVar ( & stepConfig . CfServiceKeyName , "cfServiceKeyName" , os . Getenv ( "PIPER_cfServiceKeyName" ) , "Cloud Foundry Service Key" )
cmd . MarkFlagRequired ( "username" )
cmd . MarkFlagRequired ( "password" )
}
// retrieve step metadata
func abapEnvironmentCheckoutBranchMetadata ( ) config . StepData {
var theMetaData = config . StepData {
Metadata : config . StepMetadata {
2020-11-20 09:13:59 +02:00
Name : "abapEnvironmentCheckoutBranch" ,
Aliases : [ ] config . Alias { } ,
Description : "Switches between branches of a git repository on a SAP Cloud Platform ABAP Environment system" ,
2020-08-04 17:52:28 +02:00
} ,
Spec : config . StepSpec {
Inputs : config . StepInputs {
2021-06-16 08:43:30 +02:00
Secrets : [ ] config . StepSecrets {
{ Name : "abapCredentialsId" , Description : "Jenkins credentials ID containing user and password to authenticate to the Cloud Platform ABAP Environment system or the Cloud Foundry API" , Type : "jenkins" , Aliases : [ ] config . Alias { { Name : "cfCredentialsId" , Deprecated : false } , { Name : "credentialsId" , Deprecated : false } } } ,
} ,
2020-08-04 17:52:28 +02:00
Parameters : [ ] config . StepParameters {
{
2020-09-16 14:50:09 +02:00
Name : "username" ,
ResourceRef : [ ] config . ResourceReference {
{
Name : "abapCredentialsId" ,
Param : "username" ,
Type : "secret" ,
} ,
} ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_username" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
2020-09-16 14:50:09 +02:00
Name : "password" ,
ResourceRef : [ ] config . ResourceReference {
{
Name : "abapCredentialsId" ,
Param : "password" ,
Type : "secret" ,
} ,
} ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_password" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "repositoryName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
2020-10-05 14:38:35 +02:00
Mandatory : false ,
2020-08-04 17:52:28 +02:00
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_repositoryName" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "branchName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
2020-10-14 14:42:53 +02:00
Mandatory : false ,
2020-08-04 17:52:28 +02:00
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_branchName" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "host" ,
ResourceRef : [ ] config . ResourceReference { } ,
2020-08-06 09:59:55 +02:00
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
2020-08-04 17:52:28 +02:00
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_host" ) ,
2020-08-04 17:52:28 +02:00
} ,
2020-10-05 14:38:35 +02:00
{
Name : "repositories" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "GENERAL" , "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_repositories" ) ,
2020-10-05 14:38:35 +02:00
} ,
2020-08-04 17:52:28 +02:00
{
Name : "cfApiEndpoint" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/apiEndpoint" } } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_cfApiEndpoint" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "cfOrg" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/org" } } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_cfOrg" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "cfSpace" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/space" } } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_cfSpace" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "cfServiceInstance" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/serviceInstance" } } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_cfServiceInstance" ) ,
2020-08-04 17:52:28 +02:00
} ,
{
Name : "cfServiceKeyName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/serviceKey" } , { Name : "cloudFoundry/serviceKeyName" } , { Name : "cfServiceKeyName" } } ,
2021-06-16 08:43:30 +02:00
Default : os . Getenv ( "PIPER_cfServiceKeyName" ) ,
2020-08-04 17:52:28 +02:00
} ,
} ,
} ,
2020-11-20 09:13:59 +02:00
Containers : [ ] config . Container {
2021-02-16 19:03:29 +02:00
{ Name : "cf" , Image : "ppiper/cf-cli:7" } ,
2020-11-20 09:13:59 +02:00
} ,
2020-08-04 17:52:28 +02:00
} ,
}
return theMetaData
}