github.com/xgoffin/jenkins-library@v1.154.0/cmd/transportRequestUploadRFC_generated.go (about) 1 // Code generated by piper's step-generator. DO NOT EDIT. 2 3 package cmd 4 5 import ( 6 "fmt" 7 "os" 8 "path/filepath" 9 "time" 10 11 "github.com/SAP/jenkins-library/pkg/config" 12 "github.com/SAP/jenkins-library/pkg/log" 13 "github.com/SAP/jenkins-library/pkg/piperenv" 14 "github.com/SAP/jenkins-library/pkg/splunk" 15 "github.com/SAP/jenkins-library/pkg/telemetry" 16 "github.com/SAP/jenkins-library/pkg/validation" 17 "github.com/spf13/cobra" 18 ) 19 20 type transportRequestUploadRFCOptions struct { 21 Endpoint string `json:"endpoint,omitempty"` 22 Instance string `json:"instance,omitempty"` 23 Username string `json:"username,omitempty"` 24 Password string `json:"password,omitempty"` 25 Client string `json:"client,omitempty"` 26 ApplicationName string `json:"applicationName,omitempty"` 27 ApplicationDescription string `json:"applicationDescription,omitempty"` 28 AbapPackage string `json:"abapPackage,omitempty"` 29 ApplicationURL string `json:"applicationUrl,omitempty"` 30 CodePage string `json:"codePage,omitempty"` 31 AcceptUnixStyleLineEndings bool `json:"acceptUnixStyleLineEndings,omitempty"` 32 FailUploadOnWarning bool `json:"failUploadOnWarning,omitempty"` 33 TransportRequestID string `json:"transportRequestId,omitempty"` 34 } 35 36 type transportRequestUploadRFCCommonPipelineEnvironment struct { 37 custom struct { 38 transportRequestID string 39 } 40 } 41 42 func (p *transportRequestUploadRFCCommonPipelineEnvironment) persist(path, resourceName string) { 43 content := []struct { 44 category string 45 name string 46 value interface{} 47 }{ 48 {category: "custom", name: "transportRequestId", value: p.custom.transportRequestID}, 49 } 50 51 errCount := 0 52 for _, param := range content { 53 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 54 if err != nil { 55 log.Entry().WithError(err).Error("Error persisting piper environment.") 56 errCount++ 57 } 58 } 59 if errCount > 0 { 60 log.Entry().Error("failed to persist Piper environment") 61 } 62 } 63 64 // TransportRequestUploadRFCCommand This step uploads a UI5 application as ZIP file to the ABAP system via RFC connections. 65 func TransportRequestUploadRFCCommand() *cobra.Command { 66 const STEP_NAME = "transportRequestUploadRFC" 67 68 metadata := transportRequestUploadRFCMetadata() 69 var stepConfig transportRequestUploadRFCOptions 70 var startTime time.Time 71 var commonPipelineEnvironment transportRequestUploadRFCCommonPipelineEnvironment 72 var logCollector *log.CollectorHook 73 var splunkClient *splunk.Splunk 74 telemetryClient := &telemetry.Telemetry{} 75 76 var createTransportRequestUploadRFCCmd = &cobra.Command{ 77 Use: STEP_NAME, 78 Short: "This step uploads a UI5 application as ZIP file to the ABAP system via RFC connections.", 79 Long: `This step uploads a UI5 application as ZIP file to the ABAP system via RFC connections.`, 80 PreRunE: func(cmd *cobra.Command, _ []string) error { 81 startTime = time.Now() 82 log.SetStepName(STEP_NAME) 83 log.SetVerbose(GeneralConfig.Verbose) 84 85 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 86 87 path, _ := os.Getwd() 88 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 89 log.RegisterHook(fatalHook) 90 91 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 92 if err != nil { 93 log.SetErrorCategory(log.ErrorConfiguration) 94 return err 95 } 96 log.RegisterSecret(stepConfig.Username) 97 log.RegisterSecret(stepConfig.Password) 98 99 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 100 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 101 log.RegisterHook(&sentryHook) 102 } 103 104 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 105 splunkClient = &splunk.Splunk{} 106 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 107 log.RegisterHook(logCollector) 108 } 109 110 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 111 if err != nil { 112 return err 113 } 114 if err = validation.ValidateStruct(stepConfig); err != nil { 115 log.SetErrorCategory(log.ErrorConfiguration) 116 return err 117 } 118 119 return nil 120 }, 121 Run: func(_ *cobra.Command, _ []string) { 122 stepTelemetryData := telemetry.CustomData{} 123 stepTelemetryData.ErrorCode = "1" 124 handler := func() { 125 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 126 config.RemoveVaultSecretFiles() 127 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 128 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 129 stepTelemetryData.PiperCommitHash = GitCommit 130 telemetryClient.SetData(&stepTelemetryData) 131 telemetryClient.Send() 132 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 133 splunkClient.Send(telemetryClient.GetData(), logCollector) 134 } 135 } 136 log.DeferExitHandler(handler) 137 defer handler() 138 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 139 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 140 splunkClient.Initialize(GeneralConfig.CorrelationID, 141 GeneralConfig.HookConfig.SplunkConfig.Dsn, 142 GeneralConfig.HookConfig.SplunkConfig.Token, 143 GeneralConfig.HookConfig.SplunkConfig.Index, 144 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 145 } 146 transportRequestUploadRFC(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 147 stepTelemetryData.ErrorCode = "0" 148 log.Entry().Info("SUCCESS") 149 }, 150 } 151 152 addTransportRequestUploadRFCFlags(createTransportRequestUploadRFCCmd, &stepConfig) 153 return createTransportRequestUploadRFCCmd 154 } 155 156 func addTransportRequestUploadRFCFlags(cmd *cobra.Command, stepConfig *transportRequestUploadRFCOptions) { 157 cmd.Flags().StringVar(&stepConfig.Endpoint, "endpoint", os.Getenv("PIPER_endpoint"), "Service endpoint, Application server URL") 158 cmd.Flags().StringVar(&stepConfig.Instance, "instance", os.Getenv("PIPER_instance"), "AS ABAP instance number") 159 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "Service user for uploading to the ABAP system via RFC") 160 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Service user password for uploading to the ABAP system via RFC") 161 cmd.Flags().StringVar(&stepConfig.Client, "client", os.Getenv("PIPER_client"), "AS ABAP client number") 162 cmd.Flags().StringVar(&stepConfig.ApplicationName, "applicationName", os.Getenv("PIPER_applicationName"), "Name of the UI5 application") 163 cmd.Flags().StringVar(&stepConfig.ApplicationDescription, "applicationDescription", os.Getenv("PIPER_applicationDescription"), "Description of the UI5 application") 164 cmd.Flags().StringVar(&stepConfig.AbapPackage, "abapPackage", os.Getenv("PIPER_abapPackage"), "ABAP package name of the UI5 application") 165 cmd.Flags().StringVar(&stepConfig.ApplicationURL, "applicationUrl", os.Getenv("PIPER_applicationUrl"), "URL of the UI5 application package to upload to the ABAP system via RFC") 166 cmd.Flags().StringVar(&stepConfig.CodePage, "codePage", `UTF-8`, "Code page") 167 cmd.Flags().BoolVar(&stepConfig.AcceptUnixStyleLineEndings, "acceptUnixStyleLineEndings", true, "If unix style line endings should be accepted") 168 cmd.Flags().BoolVar(&stepConfig.FailUploadOnWarning, "failUploadOnWarning", true, "If the upload should fail in case the log contains warnings") 169 cmd.Flags().StringVar(&stepConfig.TransportRequestID, "transportRequestId", os.Getenv("PIPER_transportRequestId"), "ID of the transport request to which the UI5 application is uploaded") 170 171 cmd.MarkFlagRequired("endpoint") 172 cmd.MarkFlagRequired("username") 173 cmd.MarkFlagRequired("password") 174 cmd.MarkFlagRequired("applicationName") 175 cmd.MarkFlagRequired("abapPackage") 176 cmd.MarkFlagRequired("applicationUrl") 177 cmd.MarkFlagRequired("transportRequestId") 178 } 179 180 // retrieve step metadata 181 func transportRequestUploadRFCMetadata() config.StepData { 182 var theMetaData = config.StepData{ 183 Metadata: config.StepMetadata{ 184 Name: "transportRequestUploadRFC", 185 Aliases: []config.Alias{{Name: "transportRequestUploadFile", Deprecated: false}}, 186 Description: "This step uploads a UI5 application as ZIP file to the ABAP system via RFC connections.", 187 }, 188 Spec: config.StepSpec{ 189 Inputs: config.StepInputs{ 190 Secrets: []config.StepSecrets{ 191 {Name: "uploadCredentialsId", Description: "Jenkins 'Username with password' credentials ID containing user and password to authenticate against the ABAP system", Type: "jenkins", Aliases: []config.Alias{{Name: "changeManagement/credentialsId", Deprecated: false}}}, 192 }, 193 Parameters: []config.StepParameters{ 194 { 195 Name: "endpoint", 196 ResourceRef: []config.ResourceReference{}, 197 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 198 Type: "string", 199 Mandatory: true, 200 Aliases: []config.Alias{{Name: "changeManagement/endpoint"}}, 201 Default: os.Getenv("PIPER_endpoint"), 202 }, 203 { 204 Name: "instance", 205 ResourceRef: []config.ResourceReference{}, 206 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 207 Type: "string", 208 Mandatory: false, 209 Aliases: []config.Alias{{Name: "changeManagement/instance"}, {Name: "changeManagement/rfc/developmentInstance"}}, 210 Default: os.Getenv("PIPER_instance"), 211 }, 212 { 213 Name: "username", 214 ResourceRef: []config.ResourceReference{ 215 { 216 Name: "uploadCredentialsId", 217 Param: "username", 218 Type: "secret", 219 }, 220 }, 221 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 222 Type: "string", 223 Mandatory: true, 224 Aliases: []config.Alias{}, 225 Default: os.Getenv("PIPER_username"), 226 }, 227 { 228 Name: "password", 229 ResourceRef: []config.ResourceReference{ 230 { 231 Name: "uploadCredentialsId", 232 Param: "password", 233 Type: "secret", 234 }, 235 }, 236 Scope: []string{"PARAMETERS"}, 237 Type: "string", 238 Mandatory: true, 239 Aliases: []config.Alias{}, 240 Default: os.Getenv("PIPER_password"), 241 }, 242 { 243 Name: "client", 244 ResourceRef: []config.ResourceReference{}, 245 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 246 Type: "string", 247 Mandatory: false, 248 Aliases: []config.Alias{{Name: "changeManagement/client"}, {Name: "changeManagement/rfc/developmentClient"}}, 249 Default: os.Getenv("PIPER_client"), 250 }, 251 { 252 Name: "applicationName", 253 ResourceRef: []config.ResourceReference{}, 254 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 255 Type: "string", 256 Mandatory: true, 257 Aliases: []config.Alias{}, 258 Default: os.Getenv("PIPER_applicationName"), 259 }, 260 { 261 Name: "applicationDescription", 262 ResourceRef: []config.ResourceReference{}, 263 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 264 Type: "string", 265 Mandatory: false, 266 Aliases: []config.Alias{}, 267 Default: os.Getenv("PIPER_applicationDescription"), 268 }, 269 { 270 Name: "abapPackage", 271 ResourceRef: []config.ResourceReference{}, 272 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 273 Type: "string", 274 Mandatory: true, 275 Aliases: []config.Alias{}, 276 Default: os.Getenv("PIPER_abapPackage"), 277 }, 278 { 279 Name: "applicationUrl", 280 ResourceRef: []config.ResourceReference{}, 281 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 282 Type: "string", 283 Mandatory: true, 284 Aliases: []config.Alias{}, 285 Default: os.Getenv("PIPER_applicationUrl"), 286 }, 287 { 288 Name: "codePage", 289 ResourceRef: []config.ResourceReference{}, 290 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 291 Type: "string", 292 Mandatory: false, 293 Aliases: []config.Alias{}, 294 Default: `UTF-8`, 295 }, 296 { 297 Name: "acceptUnixStyleLineEndings", 298 ResourceRef: []config.ResourceReference{}, 299 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 300 Type: "bool", 301 Mandatory: false, 302 Aliases: []config.Alias{}, 303 Default: true, 304 }, 305 { 306 Name: "failUploadOnWarning", 307 ResourceRef: []config.ResourceReference{}, 308 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 309 Type: "bool", 310 Mandatory: false, 311 Aliases: []config.Alias{{Name: "failOnWarning"}}, 312 Default: true, 313 }, 314 { 315 Name: "transportRequestId", 316 ResourceRef: []config.ResourceReference{ 317 { 318 Name: "commonPipelineEnvironment", 319 Param: "custom/transportRequestId", 320 }, 321 }, 322 Scope: []string{"PARAMETERS"}, 323 Type: "string", 324 Mandatory: true, 325 Aliases: []config.Alias{}, 326 Default: os.Getenv("PIPER_transportRequestId"), 327 }, 328 }, 329 }, 330 Containers: []config.Container{ 331 {Name: "rfcclient", Image: "rfc-client"}, 332 }, 333 Outputs: config.StepOutputs{ 334 Resources: []config.StepResources{ 335 { 336 Name: "commonPipelineEnvironment", 337 Type: "piperEnvironment", 338 Parameters: []map[string]interface{}{ 339 {"name": "custom/transportRequestId"}, 340 }, 341 }, 342 }, 343 }, 344 }, 345 } 346 return theMetaData 347 }