github.com/jaylevin/jenkins-library@v1.230.4/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 { 78 splunkClient = &splunk.Splunk{} 79 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 80 log.RegisterHook(logCollector) 81 } 82 83 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 84 if err != nil { 85 return err 86 } 87 if err = validation.ValidateStruct(stepConfig); err != nil { 88 log.SetErrorCategory(log.ErrorConfiguration) 89 return err 90 } 91 92 return nil 93 }, 94 Run: func(_ *cobra.Command, _ []string) { 95 stepTelemetryData := telemetry.CustomData{} 96 stepTelemetryData.ErrorCode = "1" 97 handler := func() { 98 config.RemoveVaultSecretFiles() 99 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 100 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 101 stepTelemetryData.PiperCommitHash = GitCommit 102 telemetryClient.SetData(&stepTelemetryData) 103 telemetryClient.Send() 104 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 105 splunkClient.Send(telemetryClient.GetData(), logCollector) 106 } 107 } 108 log.DeferExitHandler(handler) 109 defer handler() 110 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 111 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 112 splunkClient.Initialize(GeneralConfig.CorrelationID, 113 GeneralConfig.HookConfig.SplunkConfig.Dsn, 114 GeneralConfig.HookConfig.SplunkConfig.Token, 115 GeneralConfig.HookConfig.SplunkConfig.Index, 116 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 117 } 118 abapEnvironmentCreateSystem(stepConfig, &stepTelemetryData) 119 stepTelemetryData.ErrorCode = "0" 120 log.Entry().Info("SUCCESS") 121 }, 122 } 123 124 addAbapEnvironmentCreateSystemFlags(createAbapEnvironmentCreateSystemCmd, &stepConfig) 125 return createAbapEnvironmentCreateSystemCmd 126 } 127 128 func addAbapEnvironmentCreateSystemFlags(cmd *cobra.Command, stepConfig *abapEnvironmentCreateSystemOptions) { 129 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", `https://api.cf.eu10.hana.ondemand.com`, "Cloud Foundry API endpoint") 130 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User or E-Mail for CF") 131 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for Cloud Foundry User") 132 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry org") 133 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry Space") 134 cmd.Flags().StringVar(&stepConfig.CfService, "cfService", os.Getenv("PIPER_cfService"), "Parameter for Cloud Foundry Service to be used for creating Cloud Foundry Service") 135 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") 136 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Parameter for naming the Service Instance when creating a Cloud Foundry Service") 137 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") 138 cmd.Flags().StringVar(&stepConfig.AbapSystemAdminEmail, "abapSystemAdminEmail", os.Getenv("PIPER_abapSystemAdminEmail"), "Admin E-Mail address for the initial administrator of the system") 139 cmd.Flags().StringVar(&stepConfig.AbapSystemDescription, "abapSystemDescription", `Test system created by an automated pipeline`, "Description for the ABAP Environment system") 140 cmd.Flags().BoolVar(&stepConfig.AbapSystemIsDevelopmentAllowed, "abapSystemIsDevelopmentAllowed", true, "This parameter determines, if development is allowed on the system") 141 cmd.Flags().StringVar(&stepConfig.AbapSystemID, "abapSystemID", `H02`, "The three character name of the system - maps to 'sapSystemName'") 142 cmd.Flags().IntVar(&stepConfig.AbapSystemSizeOfPersistence, "abapSystemSizeOfPersistence", 0, "The size of the persistence") 143 cmd.Flags().IntVar(&stepConfig.AbapSystemSizeOfRuntime, "abapSystemSizeOfRuntime", 0, "The size of the runtime") 144 cmd.Flags().StringVar(&stepConfig.AddonDescriptorFileName, "addonDescriptorFileName", os.Getenv("PIPER_addonDescriptorFileName"), "The file name of the addonDescriptor") 145 cmd.Flags().BoolVar(&stepConfig.IncludeAddon, "includeAddon", false, "Must be set to true to install the addon provided via 'addonDescriptorFileName'") 146 147 cmd.MarkFlagRequired("cfApiEndpoint") 148 cmd.MarkFlagRequired("username") 149 cmd.MarkFlagRequired("password") 150 cmd.MarkFlagRequired("cfOrg") 151 cmd.MarkFlagRequired("cfSpace") 152 } 153 154 // retrieve step metadata 155 func abapEnvironmentCreateSystemMetadata() config.StepData { 156 var theMetaData = config.StepData{ 157 Metadata: config.StepMetadata{ 158 Name: "abapEnvironmentCreateSystem", 159 Aliases: []config.Alias{}, 160 Description: "Creates a SAP BTP ABAP Environment system (aka Steampunk system)", 161 }, 162 Spec: config.StepSpec{ 163 Inputs: config.StepInputs{ 164 Secrets: []config.StepSecrets{ 165 {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}}}, 166 }, 167 Parameters: []config.StepParameters{ 168 { 169 Name: "cfApiEndpoint", 170 ResourceRef: []config.ResourceReference{}, 171 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 172 Type: "string", 173 Mandatory: true, 174 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 175 Default: `https://api.cf.eu10.hana.ondemand.com`, 176 }, 177 { 178 Name: "username", 179 ResourceRef: []config.ResourceReference{ 180 { 181 Name: "cfCredentialsId", 182 Param: "username", 183 Type: "secret", 184 }, 185 186 { 187 Name: "cloudfoundryVaultSecretName", 188 Type: "vaultSecret", 189 Default: "cloudfoundry-$(org)-$(space)", 190 }, 191 }, 192 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 193 Type: "string", 194 Mandatory: true, 195 Aliases: []config.Alias{}, 196 Default: os.Getenv("PIPER_username"), 197 }, 198 { 199 Name: "password", 200 ResourceRef: []config.ResourceReference{ 201 { 202 Name: "cfCredentialsId", 203 Param: "password", 204 Type: "secret", 205 }, 206 207 { 208 Name: "cloudfoundryVaultSecretName", 209 Type: "vaultSecret", 210 Default: "cloudfoundry-$(org)-$(space)", 211 }, 212 }, 213 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 214 Type: "string", 215 Mandatory: true, 216 Aliases: []config.Alias{}, 217 Default: os.Getenv("PIPER_password"), 218 }, 219 { 220 Name: "cfOrg", 221 ResourceRef: []config.ResourceReference{}, 222 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 223 Type: "string", 224 Mandatory: true, 225 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 226 Default: os.Getenv("PIPER_cfOrg"), 227 }, 228 { 229 Name: "cfSpace", 230 ResourceRef: []config.ResourceReference{}, 231 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 232 Type: "string", 233 Mandatory: true, 234 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 235 Default: os.Getenv("PIPER_cfSpace"), 236 }, 237 { 238 Name: "cfService", 239 ResourceRef: []config.ResourceReference{}, 240 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 241 Type: "string", 242 Mandatory: false, 243 Aliases: []config.Alias{{Name: "cloudFoundry/service"}}, 244 Default: os.Getenv("PIPER_cfService"), 245 }, 246 { 247 Name: "cfServicePlan", 248 ResourceRef: []config.ResourceReference{}, 249 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 250 Type: "string", 251 Mandatory: false, 252 Aliases: []config.Alias{{Name: "cloudFoundry/servicePlan"}}, 253 Default: os.Getenv("PIPER_cfServicePlan"), 254 }, 255 { 256 Name: "cfServiceInstance", 257 ResourceRef: []config.ResourceReference{}, 258 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 259 Type: "string", 260 Mandatory: false, 261 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 262 Default: os.Getenv("PIPER_cfServiceInstance"), 263 }, 264 { 265 Name: "serviceManifest", 266 ResourceRef: []config.ResourceReference{}, 267 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 268 Type: "string", 269 Mandatory: false, 270 Aliases: []config.Alias{{Name: "cloudFoundry/serviceManifest"}, {Name: "cfServiceManifest"}}, 271 Default: os.Getenv("PIPER_serviceManifest"), 272 }, 273 { 274 Name: "abapSystemAdminEmail", 275 ResourceRef: []config.ResourceReference{}, 276 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 277 Type: "string", 278 Mandatory: false, 279 Aliases: []config.Alias{}, 280 Default: os.Getenv("PIPER_abapSystemAdminEmail"), 281 }, 282 { 283 Name: "abapSystemDescription", 284 ResourceRef: []config.ResourceReference{}, 285 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 286 Type: "string", 287 Mandatory: false, 288 Aliases: []config.Alias{}, 289 Default: `Test system created by an automated pipeline`, 290 }, 291 { 292 Name: "abapSystemIsDevelopmentAllowed", 293 ResourceRef: []config.ResourceReference{}, 294 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 295 Type: "bool", 296 Mandatory: false, 297 Aliases: []config.Alias{}, 298 Default: true, 299 }, 300 { 301 Name: "abapSystemID", 302 ResourceRef: []config.ResourceReference{}, 303 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 304 Type: "string", 305 Mandatory: false, 306 Aliases: []config.Alias{}, 307 Default: `H02`, 308 }, 309 { 310 Name: "abapSystemSizeOfPersistence", 311 ResourceRef: []config.ResourceReference{}, 312 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 313 Type: "int", 314 Mandatory: false, 315 Aliases: []config.Alias{}, 316 Default: 0, 317 }, 318 { 319 Name: "abapSystemSizeOfRuntime", 320 ResourceRef: []config.ResourceReference{}, 321 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 322 Type: "int", 323 Mandatory: false, 324 Aliases: []config.Alias{}, 325 Default: 0, 326 }, 327 { 328 Name: "addonDescriptorFileName", 329 ResourceRef: []config.ResourceReference{}, 330 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 331 Type: "string", 332 Mandatory: false, 333 Aliases: []config.Alias{}, 334 Default: os.Getenv("PIPER_addonDescriptorFileName"), 335 }, 336 { 337 Name: "includeAddon", 338 ResourceRef: []config.ResourceReference{}, 339 Scope: []string{"PARAMETERS", "STAGES"}, 340 Type: "bool", 341 Mandatory: false, 342 Aliases: []config.Alias{}, 343 Default: false, 344 }, 345 }, 346 }, 347 Containers: []config.Container{ 348 {Name: "cf", Image: "ppiper/cf-cli:7"}, 349 }, 350 }, 351 } 352 return theMetaData 353 }