2020-05-18 21:39:35 +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-05-18 21:39:35 +02:00
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/spf13/cobra"
)
type gctsDeployOptions struct {
2021-05-10 14:05:21 +02:00
Username string ` json:"username,omitempty" `
Password string ` json:"password,omitempty" `
Repository string ` json:"repository,omitempty" `
Host string ` json:"host,omitempty" `
Client string ` json:"client,omitempty" `
Commit string ` json:"commit,omitempty" `
RemoteRepositoryURL string ` json:"remoteRepositoryURL,omitempty" `
Role string ` json:"role,omitempty" `
VSID string ` json:"vSID,omitempty" `
Type string ` json:"type,omitempty" `
Branch string ` json:"branch,omitempty" `
Scope string ` json:"scope,omitempty" `
Rollback bool ` json:"rollback,omitempty" `
Configuration map [ string ] interface { } ` json:"configuration,omitempty" `
2020-05-18 21:39:35 +02:00
}
2021-05-10 14:05:21 +02:00
// GctsDeployCommand Deploys a Git Repository to a local Repository and then to an ABAP System
2020-05-18 21:39:35 +02:00
func GctsDeployCommand ( ) * cobra . Command {
const STEP_NAME = "gctsDeploy"
metadata := gctsDeployMetadata ( )
var stepConfig gctsDeployOptions
var startTime time . Time
2021-05-17 12:14:04 +02:00
var logCollector * log . CollectorHook
2020-05-18 21:39:35 +02:00
var createGctsDeployCmd = & cobra . Command {
Use : STEP_NAME ,
2021-05-10 14:05:21 +02:00
Short : "Deploys a Git Repository to a local Repository and then to an ABAP System" ,
Long : ` The steps deploys a git repository to an ABAP System . If a repository does not exists in the system , it creates and clones it to the local
repository and then deploys it into the ABAP system . ` ,
2020-06-23 18:05:21 +02:00
PreRunE : func ( cmd * cobra . Command , _ [ ] string ) error {
2020-05-18 21:39:35 +02:00
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 {
2020-06-24 10:04:05 +02:00
log . SetErrorCategory ( log . ErrorConfiguration )
2020-05-18 21:39:35 +02:00
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-05-18 21:39:35 +02:00
return nil
} ,
2020-06-23 18:05:21 +02:00
Run : func ( _ * cobra . Command , _ [ ] string ) {
2020-05-18 21:39:35 +02:00
telemetryData := telemetry . CustomData { }
telemetryData . ErrorCode = "1"
handler := func ( ) {
2020-10-26 15:20:04 +02:00
config . RemoveVaultSecretFiles ( )
2020-05-18 21:39:35 +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-05-18 21:39:35 +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-05-18 21:39:35 +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-05-18 21:39:35 +02:00
gctsDeploy ( stepConfig , & telemetryData )
telemetryData . ErrorCode = "0"
2020-05-18 21:52:54 +02:00
log . Entry ( ) . Info ( "SUCCESS" )
2020-05-18 21:39:35 +02:00
} ,
}
addGctsDeployFlags ( createGctsDeployCmd , & stepConfig )
return createGctsDeployCmd
}
func addGctsDeployFlags ( cmd * cobra . Command , stepConfig * gctsDeployOptions ) {
cmd . Flags ( ) . StringVar ( & stepConfig . Username , "username" , os . Getenv ( "PIPER_username" ) , "User to authenticate to the ABAP system" )
cmd . Flags ( ) . StringVar ( & stepConfig . Password , "password" , os . Getenv ( "PIPER_password" ) , "Password to authenticate to the ABAP system" )
cmd . Flags ( ) . StringVar ( & stepConfig . Repository , "repository" , os . Getenv ( "PIPER_repository" ) , "Specifies the name (ID) of the local repsitory on the ABAP system" )
2020-09-24 07:41:06 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . Host , "host" , os . Getenv ( "PIPER_host" ) , "Specifies the protocol and host address, including the port. Please provide in the format `<protocol>://<host>:<port>`. Supported protocols are `http` and `https`." )
cmd . Flags ( ) . StringVar ( & stepConfig . Client , "client" , os . Getenv ( "PIPER_client" ) , "Specifies the client of the ABAP system to be addressed" )
2020-05-18 21:39:35 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . Commit , "commit" , os . Getenv ( "PIPER_commit" ) , "Specifies the commit to be deployed" )
2021-05-10 14:05:21 +02:00
cmd . Flags ( ) . StringVar ( & stepConfig . RemoteRepositoryURL , "remoteRepositoryURL" , os . Getenv ( "PIPER_remoteRepositoryURL" ) , "URL of the corresponding remote repository" )
cmd . Flags ( ) . StringVar ( & stepConfig . Role , "role" , os . Getenv ( "PIPER_role" ) , "Role of the local repository. Choose between 'TARGET' and 'SOURCE'. Local repositories with a TARGET role will NOT be able to be the source of code changes" )
cmd . Flags ( ) . StringVar ( & stepConfig . VSID , "vSID" , os . Getenv ( "PIPER_vSID" ) , "Virtual SID of the local repository. The vSID corresponds to the transport route that delivers content to the remote Git repository" )
cmd . Flags ( ) . StringVar ( & stepConfig . Type , "type" , ` GIT ` , "Type of the used source code management tool" )
cmd . Flags ( ) . StringVar ( & stepConfig . Branch , "branch" , os . Getenv ( "PIPER_branch" ) , "Name of the branch to which the deploy has to be done to." )
cmd . Flags ( ) . StringVar ( & stepConfig . Scope , "scope" , os . Getenv ( "PIPER_scope" ) , "The scope of the gcts deploy api call" )
cmd . Flags ( ) . BoolVar ( & stepConfig . Rollback , "rollback" , false , "The rollback flag for a failure during the deploy step. A true value would mean gCTS would roll back to the last clean state" )
2020-05-18 21:39:35 +02:00
cmd . MarkFlagRequired ( "username" )
cmd . MarkFlagRequired ( "password" )
cmd . MarkFlagRequired ( "repository" )
cmd . MarkFlagRequired ( "host" )
cmd . MarkFlagRequired ( "client" )
2021-05-10 14:05:21 +02:00
cmd . MarkFlagRequired ( "remoteRepositoryURL" )
2020-05-18 21:39:35 +02:00
}
// retrieve step metadata
func gctsDeployMetadata ( ) config . StepData {
var theMetaData = config . StepData {
Metadata : config . StepMetadata {
2020-11-20 09:13:59 +02:00
Name : "gctsDeploy" ,
Aliases : [ ] config . Alias { } ,
2021-05-10 14:05:21 +02:00
Description : "Deploys a Git Repository to a local Repository and then to an ABAP System" ,
2020-05-18 21:39:35 +02:00
} ,
Spec : config . StepSpec {
Inputs : config . StepInputs {
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 { } ,
2020-05-18 21:39:35 +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 { } ,
2020-05-18 21:39:35 +02:00
} ,
{
Name : "repository" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "host" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "client" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "commit" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
2021-05-10 14:05:21 +02:00
{
Name : "remoteRepositoryURL" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : true ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "role" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "vSID" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "type" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "branch" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "scope" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "string" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "rollback" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" } ,
Type : "bool" ,
Mandatory : false ,
Aliases : [ ] config . Alias { } ,
} ,
{
Name : "configuration" ,
ResourceRef : [ ] config . ResourceReference { } ,
Scope : [ ] string { "PARAMETERS" , "STAGES" , "STEPS" , "GENERAL" } ,
Type : "map[string]interface{}" ,
Mandatory : false ,
Aliases : [ ] config . Alias { { Name : "gctsRepositoryConfigurations" } } ,
} ,
2020-05-18 21:39:35 +02:00
} ,
} ,
} ,
}
return theMetaData
}