github.com/SAP/jenkins-library@v1.362.0/cmd/abapEnvironmentCreateSystem_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 "time" 9 10 "github.com/SAP/jenkins-library/pkg/config" 11 "github.com/SAP/jenkins-library/pkg/log" 12 "github.com/SAP/jenkins-library/pkg/splunk" 13 "github.com/SAP/jenkins-library/pkg/telemetry" 14 "github.com/SAP/jenkins-library/pkg/validation" 15 "github.com/spf13/cobra" 16 ) 17 18 type abapEnvironmentCreateSystemOptions struct { 19 CfAPIEndpoint string `json:"cfApiEndpoint,omitempty"` 20 Username string `json:"username,omitempty"` 21 Password string `json:"password,omitempty"` 22 CfOrg string `json:"cfOrg,omitempty"` 23 CfSpace string `json:"cfSpace,omitempty"` 24 CfService string `json:"cfService,omitempty"` 25 CfServicePlan string `json:"cfServicePlan,omitempty"` 26 CfServiceInstance string `json:"cfServiceInstance,omitempty"` 27 ServiceManifest string `json:"serviceManifest,omitempty"` 28 AbapSystemAdminEmail string `json:"abapSystemAdminEmail,omitempty"` 29 AbapSystemDescription string `json:"abapSystemDescription,omitempty"` 30 AbapSystemIsDevelopmentAllowed bool `json:"abapSystemIsDevelopmentAllowed,omitempty"` 31 AbapSystemID string `json:"abapSystemID,omitempty"` 32 AbapSystemSizeOfPersistence int `json:"abapSystemSizeOfPersistence,omitempty"` 33 AbapSystemSizeOfRuntime int `json:"abapSystemSizeOfRuntime,omitempty"` 34 AddonDescriptorFileName string `json:"addonDescriptorFileName,omitempty"` 35 IncludeAddon bool `json:"includeAddon,omitempty"` 36 } 37 38 // AbapEnvironmentCreateSystemCommand Creates a SAP BTP ABAP Environment system (aka Steampunk system) 39 func AbapEnvironmentCreateSystemCommand() *cobra.Command { 40 const STEP_NAME = "abapEnvironmentCreateSystem" 41 42 metadata := abapEnvironmentCreateSystemMetadata() 43 var stepConfig abapEnvironmentCreateSystemOptions 44 var startTime time.Time 45 var logCollector *log.CollectorHook 46 var splunkClient *splunk.Splunk 47 telemetryClient := &telemetry.Telemetry{} 48 49 var createAbapEnvironmentCreateSystemCmd = &cobra.Command{ 50 Use: STEP_NAME, 51 Short: "Creates a SAP BTP ABAP Environment system (aka Steampunk system)", 52 Long: `This step creates a SAP BTP ABAP Environment system (aka Steampunk system) via the cloud foundry command line interface (cf CLI). This can be done by providing a service manifest as a configuration file (parameter ` + "`" + `serviceManifest` + "`" + `) or by passing the configuration values directly via the other parameters of this step.`, 53 PreRunE: func(cmd *cobra.Command, _ []string) error { 54 startTime = time.Now() 55 log.SetStepName(STEP_NAME) 56 log.SetVerbose(GeneralConfig.Verbose) 57 58 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 59 60 path, _ := os.Getwd() 61 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 62 log.RegisterHook(fatalHook) 63 64 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 65 if err != nil { 66 log.SetErrorCategory(log.ErrorConfiguration) 67 return err 68 } 69 log.RegisterSecret(stepConfig.Username) 70 log.RegisterSecret(stepConfig.Password) 71 72 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 73 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 74 log.RegisterHook(&sentryHook) 75 } 76 77 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 || len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 78 splunkClient = &splunk.Splunk{} 79 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 80 log.RegisterHook(logCollector) 81 } 82 83 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 84 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 85 } 86 87 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 88 if err != nil { 89 return err 90 } 91 if err = validation.ValidateStruct(stepConfig); err != nil { 92 log.SetErrorCategory(log.ErrorConfiguration) 93 return err 94 } 95 96 return nil 97 }, 98 Run: func(_ *cobra.Command, _ []string) { 99 stepTelemetryData := telemetry.CustomData{} 100 stepTelemetryData.ErrorCode = "1" 101 handler := func() { 102 config.RemoveVaultSecretFiles() 103 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 104 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 105 stepTelemetryData.PiperCommitHash = GitCommit 106 telemetryClient.SetData(&stepTelemetryData) 107 telemetryClient.Send() 108 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 109 splunkClient.Initialize(GeneralConfig.CorrelationID, 110 GeneralConfig.HookConfig.SplunkConfig.Dsn, 111 GeneralConfig.HookConfig.SplunkConfig.Token, 112 GeneralConfig.HookConfig.SplunkConfig.Index, 113 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 114 splunkClient.Send(telemetryClient.GetData(), logCollector) 115 } 116 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 117 splunkClient.Initialize(GeneralConfig.CorrelationID, 118 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 119 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 120 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 121 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 122 splunkClient.Send(telemetryClient.GetData(), logCollector) 123 } 124 } 125 log.DeferExitHandler(handler) 126 defer handler() 127 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME, GeneralConfig.HookConfig.PendoConfig.Token) 128 abapEnvironmentCreateSystem(stepConfig, &stepTelemetryData) 129 stepTelemetryData.ErrorCode = "0" 130 log.Entry().Info("SUCCESS") 131 }, 132 } 133 134 addAbapEnvironmentCreateSystemFlags(createAbapEnvironmentCreateSystemCmd, &stepConfig) 135 return createAbapEnvironmentCreateSystemCmd 136 } 137 138 func addAbapEnvironmentCreateSystemFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCreateSystemOptions) { 139 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", `https://api.cf.eu10.hana.ondemand.com`, "Cloud Foundry API endpoint") 140 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User or E-Mail for CF") 141 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for Cloud Foundry User") 142 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry org") 143 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry Space") 144 cmd.Flags().StringVar(&stepConfig.CfService, "cfService", os.Getenv("PIPER_cfService"), "Parameter for Cloud Foundry Service to be used for creating Cloud Foundry Service") 145 cmd.Flags().StringVar(&stepConfig.CfServicePlan, "cfServicePlan", os.Getenv("PIPER_cfServicePlan"), "Parameter for Cloud Foundry Service Plan to be used when creating a Cloud Foundry Service") 146 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Parameter for naming the Service Instance when creating a Cloud Foundry Service") 147 cmd.Flags().StringVar(&stepConfig.ServiceManifest, "serviceManifest", os.Getenv("PIPER_serviceManifest"), "Path to Cloud Foundry Service Manifest in YAML format for multiple service creations that are being passed to a Create-Service-Push Cloud Foundry cli plugin") 148 cmd.Flags().StringVar(&stepConfig.AbapSystemAdminEmail, "abapSystemAdminEmail", os.Getenv("PIPER_abapSystemAdminEmail"), "Admin E-Mail address for the initial administrator of the system") 149 cmd.Flags().StringVar(&stepConfig.AbapSystemDescription, "abapSystemDescription", `Test system created by an automated pipeline`, "Description for the ABAP Environment system") 150 cmd.Flags().BoolVar(&stepConfig.AbapSystemIsDevelopmentAllowed, "abapSystemIsDevelopmentAllowed", true, "This parameter determines, if development is allowed on the system") 151 cmd.Flags().StringVar(&stepConfig.AbapSystemID, "abapSystemID", `H02`, "The three character name of the system - maps to 'sapSystemName'") 152 cmd.Flags().IntVar(&stepConfig.AbapSystemSizeOfPersistence, "abapSystemSizeOfPersistence", 0, "The size of the persistence") 153 cmd.Flags().IntVar(&stepConfig.AbapSystemSizeOfRuntime, "abapSystemSizeOfRuntime", 0, "The size of the runtime") 154 cmd.Flags().StringVar(&stepConfig.AddonDescriptorFileName, "addonDescriptorFileName", os.Getenv("PIPER_addonDescriptorFileName"), "The file name of the addonDescriptor") 155 cmd.Flags().BoolVar(&stepConfig.IncludeAddon, "includeAddon", false, "Must be set to true to install the addon provided via 'addonDescriptorFileName'") 156 157 cmd.MarkFlagRequired("cfApiEndpoint") 158 cmd.MarkFlagRequired("username") 159 cmd.MarkFlagRequired("password") 160 cmd.MarkFlagRequired("cfOrg") 161 cmd.MarkFlagRequired("cfSpace") 162 } 163 164 // retrieve step metadata 165 func abapEnvironmentCreateSystemMetadata() config.StepData { 166 var theMetaData = config.StepData{ 167 Metadata: config.StepMetadata{ 168 Name: "abapEnvironmentCreateSystem", 169 Aliases: []config.Alias{}, 170 Description: "Creates a SAP BTP ABAP Environment system (aka Steampunk system)", 171 }, 172 Spec: config.StepSpec{ 173 Inputs: config.StepInputs{ 174 Secrets: []config.StepSecrets{ 175 {Name: "cfCredentialsId", Description: "Jenkins 'Username with password' credentials ID containing user and password to authenticate to the Cloud Foundry API.", Type: "jenkins", Aliases: []config.Alias{{Name: "cloudFoundry/credentialsId", Deprecated: false}}}, 176 }, 177 Parameters: []config.StepParameters{ 178 { 179 Name: "cfApiEndpoint", 180 ResourceRef: []config.ResourceReference{}, 181 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 182 Type: "string", 183 Mandatory: true, 184 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 185 Default: `https://api.cf.eu10.hana.ondemand.com`, 186 }, 187 { 188 Name: "username", 189 ResourceRef: []config.ResourceReference{ 190 { 191 Name: "cfCredentialsId", 192 Param: "username", 193 Type: "secret", 194 }, 195 196 { 197 Name: "cloudfoundryVaultSecretName", 198 Type: "vaultSecret", 199 Default: "cloudfoundry-$(org)-$(space)", 200 }, 201 }, 202 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 203 Type: "string", 204 Mandatory: true, 205 Aliases: []config.Alias{}, 206 Default: os.Getenv("PIPER_username"), 207 }, 208 { 209 Name: "password", 210 ResourceRef: []config.ResourceReference{ 211 { 212 Name: "cfCredentialsId", 213 Param: "password", 214 Type: "secret", 215 }, 216 217 { 218 Name: "cloudfoundryVaultSecretName", 219 Type: "vaultSecret", 220 Default: "cloudfoundry-$(org)-$(space)", 221 }, 222 }, 223 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 224 Type: "string", 225 Mandatory: true, 226 Aliases: []config.Alias{}, 227 Default: os.Getenv("PIPER_password"), 228 }, 229 { 230 Name: "cfOrg", 231 ResourceRef: []config.ResourceReference{}, 232 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 233 Type: "string", 234 Mandatory: true, 235 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 236 Default: os.Getenv("PIPER_cfOrg"), 237 }, 238 { 239 Name: "cfSpace", 240 ResourceRef: []config.ResourceReference{}, 241 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 242 Type: "string", 243 Mandatory: true, 244 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 245 Default: os.Getenv("PIPER_cfSpace"), 246 }, 247 { 248 Name: "cfService", 249 ResourceRef: []config.ResourceReference{}, 250 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 251 Type: "string", 252 Mandatory: false, 253 Aliases: []config.Alias{{Name: "cloudFoundry/service"}}, 254 Default: os.Getenv("PIPER_cfService"), 255 }, 256 { 257 Name: "cfServicePlan", 258 ResourceRef: []config.ResourceReference{}, 259 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 260 Type: "string", 261 Mandatory: false, 262 Aliases: []config.Alias{{Name: "cloudFoundry/servicePlan"}}, 263 Default: os.Getenv("PIPER_cfServicePlan"), 264 }, 265 { 266 Name: "cfServiceInstance", 267 ResourceRef: []config.ResourceReference{}, 268 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 269 Type: "string", 270 Mandatory: false, 271 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 272 Default: os.Getenv("PIPER_cfServiceInstance"), 273 }, 274 { 275 Name: "serviceManifest", 276 ResourceRef: []config.ResourceReference{}, 277 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 278 Type: "string", 279 Mandatory: false, 280 Aliases: []config.Alias{{Name: "cloudFoundry/serviceManifest"}, {Name: "cfServiceManifest"}}, 281 Default: os.Getenv("PIPER_serviceManifest"), 282 }, 283 { 284 Name: "abapSystemAdminEmail", 285 ResourceRef: []config.ResourceReference{}, 286 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 287 Type: "string", 288 Mandatory: false, 289 Aliases: []config.Alias{}, 290 Default: os.Getenv("PIPER_abapSystemAdminEmail"), 291 }, 292 { 293 Name: "abapSystemDescription", 294 ResourceRef: []config.ResourceReference{}, 295 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 296 Type: "string", 297 Mandatory: false, 298 Aliases: []config.Alias{}, 299 Default: `Test system created by an automated pipeline`, 300 }, 301 { 302 Name: "abapSystemIsDevelopmentAllowed", 303 ResourceRef: []config.ResourceReference{}, 304 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 305 Type: "bool", 306 Mandatory: false, 307 Aliases: []config.Alias{}, 308 Default: true, 309 }, 310 { 311 Name: "abapSystemID", 312 ResourceRef: []config.ResourceReference{}, 313 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 314 Type: "string", 315 Mandatory: false, 316 Aliases: []config.Alias{}, 317 Default: `H02`, 318 }, 319 { 320 Name: "abapSystemSizeOfPersistence", 321 ResourceRef: []config.ResourceReference{}, 322 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 323 Type: "int", 324 Mandatory: false, 325 Aliases: []config.Alias{}, 326 Default: 0, 327 }, 328 { 329 Name: "abapSystemSizeOfRuntime", 330 ResourceRef: []config.ResourceReference{}, 331 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 332 Type: "int", 333 Mandatory: false, 334 Aliases: []config.Alias{}, 335 Default: 0, 336 }, 337 { 338 Name: "addonDescriptorFileName", 339 ResourceRef: []config.ResourceReference{}, 340 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 341 Type: "string", 342 Mandatory: false, 343 Aliases: []config.Alias{}, 344 Default: os.Getenv("PIPER_addonDescriptorFileName"), 345 }, 346 { 347 Name: "includeAddon", 348 ResourceRef: []config.ResourceReference{}, 349 Scope: []string{"PARAMETERS", "STAGES"}, 350 Type: "bool", 351 Mandatory: false, 352 Aliases: []config.Alias{}, 353 Default: false, 354 }, 355 }, 356 }, 357 Containers: []config.Container{ 358 {Name: "cf", Image: "ppiper/cf-cli:v12"}, 359 }, 360 }, 361 } 362 return theMetaData 363 }