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"
"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" `
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
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 :
* The host and credentials the Cloud Platform ABAP Environment system itself . The credentials must be configured for the Communication Scenario SAP_COM_0510 .
* 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 )
}
return nil
} ,
Run : func ( _ * cobra . Command , _ [ ] string ) {
telemetryData := telemetry . CustomData { }
telemetryData . ErrorCode = "1"
handler := func ( ) {
telemetryData . Duration = fmt . Sprintf ( "%v" , time . Since ( startTime ) . Milliseconds ( ) )
telemetry . Send ( & telemetryData )
}
log . DeferExitHandler ( handler )
defer handler ( )
telemetry . Initialize ( GeneralConfig . NoTelemetry , STEP_NAME )
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" )
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" )
cmd . MarkFlagRequired ( "repositoryName" )
cmd . MarkFlagRequired ( "branchName" )
}
// retrieve step metadata
func abapEnvironmentCheckoutBranchMetadata ( ) config . StepData {
var theMetaData = config . StepData {
Metadata : config . StepMetadata {
Name : "abapEnvironmentCheckoutBranch" ,
Aliases : [ ] config . Alias { } ,
} ,
Spec : config . StepSpec {
Inputs : config . StepInputs {
Parameters : [ ] config . StepParameters {
{
Name : "username" ,
2020-08-28 15:38:15 +02:00
ResourceRef : [ ] config . ResourceReference { { Name : "abapCredentialsId" , Param : "username" } } ,
2020-08-04 17:52:28 +02:00
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "password" ,
2020-08-28 15:38:15 +02:00
ResourceRef : [ ] config . ResourceReference { { Name : "abapCredentialsId" , Param : "password" } } ,
2020-08-04 17:52:28 +02:00
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "repositoryName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "branchName" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
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 { } ,
} ,
{
Name : "cfApiEndpoint" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/apiEndpoint" } } ,
} ,
{
Name : "cfOrg" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/org" } } ,
} ,
{
Name : "cfSpace" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/space" } } ,
} ,
{
Name : "cfServiceInstance" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "cloudFoundry/serviceInstance" } } ,
} ,
{
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" } } ,
} ,
} ,
} ,
} ,
}
return theMetaData
}