github.com/xgoffin/jenkins-library@v1.154.0/cmd/abapEnvironmentAssembleConfirm_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 abapEnvironmentAssembleConfirmOptions struct { 21 CfAPIEndpoint string `json:"cfApiEndpoint,omitempty"` 22 CfOrg string `json:"cfOrg,omitempty"` 23 CfSpace string `json:"cfSpace,omitempty"` 24 CfServiceInstance string `json:"cfServiceInstance,omitempty"` 25 CfServiceKeyName string `json:"cfServiceKeyName,omitempty"` 26 Host string `json:"host,omitempty"` 27 Username string `json:"username,omitempty"` 28 Password string `json:"password,omitempty"` 29 AddonDescriptor string `json:"addonDescriptor,omitempty"` 30 MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"` 31 } 32 33 type abapEnvironmentAssembleConfirmCommonPipelineEnvironment struct { 34 abap struct { 35 addonDescriptor string 36 } 37 } 38 39 func (p *abapEnvironmentAssembleConfirmCommonPipelineEnvironment) persist(path, resourceName string) { 40 content := []struct { 41 category string 42 name string 43 value interface{} 44 }{ 45 {category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, 46 } 47 48 errCount := 0 49 for _, param := range content { 50 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 51 if err != nil { 52 log.Entry().WithError(err).Error("Error persisting piper environment.") 53 errCount++ 54 } 55 } 56 if errCount > 0 { 57 log.Entry().Error("failed to persist Piper environment") 58 } 59 } 60 61 // AbapEnvironmentAssembleConfirmCommand Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system 62 func AbapEnvironmentAssembleConfirmCommand() *cobra.Command { 63 const STEP_NAME = "abapEnvironmentAssembleConfirm" 64 65 metadata := abapEnvironmentAssembleConfirmMetadata() 66 var stepConfig abapEnvironmentAssembleConfirmOptions 67 var startTime time.Time 68 var commonPipelineEnvironment abapEnvironmentAssembleConfirmCommonPipelineEnvironment 69 var logCollector *log.CollectorHook 70 var splunkClient *splunk.Splunk 71 telemetryClient := &telemetry.Telemetry{} 72 73 var createAbapEnvironmentAssembleConfirmCmd = &cobra.Command{ 74 Use: STEP_NAME, 75 Short: "Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system", 76 Long: `This step confirms the assemblies of provided [installations, support packages or patches] in SAP Cloud Platform ABAP Environment system`, 77 PreRunE: func(cmd *cobra.Command, _ []string) error { 78 startTime = time.Now() 79 log.SetStepName(STEP_NAME) 80 log.SetVerbose(GeneralConfig.Verbose) 81 82 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 83 84 path, _ := os.Getwd() 85 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 86 log.RegisterHook(fatalHook) 87 88 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 89 if err != nil { 90 log.SetErrorCategory(log.ErrorConfiguration) 91 return err 92 } 93 log.RegisterSecret(stepConfig.Username) 94 log.RegisterSecret(stepConfig.Password) 95 96 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 97 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 98 log.RegisterHook(&sentryHook) 99 } 100 101 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 102 splunkClient = &splunk.Splunk{} 103 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 104 log.RegisterHook(logCollector) 105 } 106 107 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 108 if err != nil { 109 return err 110 } 111 if err = validation.ValidateStruct(stepConfig); err != nil { 112 log.SetErrorCategory(log.ErrorConfiguration) 113 return err 114 } 115 116 return nil 117 }, 118 Run: func(_ *cobra.Command, _ []string) { 119 stepTelemetryData := telemetry.CustomData{} 120 stepTelemetryData.ErrorCode = "1" 121 handler := func() { 122 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 123 config.RemoveVaultSecretFiles() 124 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 125 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 126 stepTelemetryData.PiperCommitHash = GitCommit 127 telemetryClient.SetData(&stepTelemetryData) 128 telemetryClient.Send() 129 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 130 splunkClient.Send(telemetryClient.GetData(), logCollector) 131 } 132 } 133 log.DeferExitHandler(handler) 134 defer handler() 135 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME) 136 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 137 splunkClient.Initialize(GeneralConfig.CorrelationID, 138 GeneralConfig.HookConfig.SplunkConfig.Dsn, 139 GeneralConfig.HookConfig.SplunkConfig.Token, 140 GeneralConfig.HookConfig.SplunkConfig.Index, 141 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 142 } 143 abapEnvironmentAssembleConfirm(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 144 stepTelemetryData.ErrorCode = "0" 145 log.Entry().Info("SUCCESS") 146 }, 147 } 148 149 addAbapEnvironmentAssembleConfirmFlags(createAbapEnvironmentAssembleConfirmCmd, &stepConfig) 150 return createAbapEnvironmentAssembleConfirmCmd 151 } 152 153 func addAbapEnvironmentAssembleConfirmFlags(cmd *cobra.Command, stepConfig *abapEnvironmentAssembleConfirmOptions) { 154 cmd.Flags().StringVar(&stepConfig.CfAPIEndpoint, "cfApiEndpoint", os.Getenv("PIPER_cfApiEndpoint"), "Cloud Foundry API endpoint") 155 cmd.Flags().StringVar(&stepConfig.CfOrg, "cfOrg", os.Getenv("PIPER_cfOrg"), "Cloud Foundry target organization") 156 cmd.Flags().StringVar(&stepConfig.CfSpace, "cfSpace", os.Getenv("PIPER_cfSpace"), "Cloud Foundry target space") 157 cmd.Flags().StringVar(&stepConfig.CfServiceInstance, "cfServiceInstance", os.Getenv("PIPER_cfServiceInstance"), "Cloud Foundry Service Instance") 158 cmd.Flags().StringVar(&stepConfig.CfServiceKeyName, "cfServiceKeyName", os.Getenv("PIPER_cfServiceKeyName"), "Cloud Foundry Service Key") 159 cmd.Flags().StringVar(&stepConfig.Host, "host", os.Getenv("PIPER_host"), "Specifies the host address of the SAP Cloud Platform ABAP Environment system") 160 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") 161 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for either the Cloud Foundry API or the Communication Arrangement for SAP_COM_0582") 162 cmd.Flags().StringVar(&stepConfig.AddonDescriptor, "addonDescriptor", os.Getenv("PIPER_addonDescriptor"), "Structure in the commonPipelineEnvironment containing information about the Product Version and corresponding Software Component Versions") 163 cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 360, "maximal runtime of the step") 164 165 cmd.MarkFlagRequired("username") 166 cmd.MarkFlagRequired("password") 167 cmd.MarkFlagRequired("addonDescriptor") 168 cmd.MarkFlagRequired("maxRuntimeInMinutes") 169 } 170 171 // retrieve step metadata 172 func abapEnvironmentAssembleConfirmMetadata() config.StepData { 173 var theMetaData = config.StepData{ 174 Metadata: config.StepMetadata{ 175 Name: "abapEnvironmentAssembleConfirm", 176 Aliases: []config.Alias{}, 177 Description: "Confirm the Delivery of Assembly for installation, support package or patch in SAP Cloud Platform ABAP Environment system", 178 }, 179 Spec: config.StepSpec{ 180 Inputs: config.StepInputs{ 181 Secrets: []config.StepSecrets{ 182 {Name: "abapCredentialsId", Description: "Jenkins credentials ID containing user and password to authenticate to the Cloud Platform ABAP Environment system or the Cloud Foundry API", Type: "jenkins", Aliases: []config.Alias{{Name: "cfCredentialsId", Deprecated: false}, {Name: "credentialsId", Deprecated: false}}}, 183 }, 184 Parameters: []config.StepParameters{ 185 { 186 Name: "cfApiEndpoint", 187 ResourceRef: []config.ResourceReference{}, 188 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 189 Type: "string", 190 Mandatory: false, 191 Aliases: []config.Alias{{Name: "cloudFoundry/apiEndpoint"}}, 192 Default: os.Getenv("PIPER_cfApiEndpoint"), 193 }, 194 { 195 Name: "cfOrg", 196 ResourceRef: []config.ResourceReference{}, 197 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 198 Type: "string", 199 Mandatory: false, 200 Aliases: []config.Alias{{Name: "cloudFoundry/org"}}, 201 Default: os.Getenv("PIPER_cfOrg"), 202 }, 203 { 204 Name: "cfSpace", 205 ResourceRef: []config.ResourceReference{}, 206 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 207 Type: "string", 208 Mandatory: false, 209 Aliases: []config.Alias{{Name: "cloudFoundry/space"}}, 210 Default: os.Getenv("PIPER_cfSpace"), 211 }, 212 { 213 Name: "cfServiceInstance", 214 ResourceRef: []config.ResourceReference{}, 215 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 216 Type: "string", 217 Mandatory: false, 218 Aliases: []config.Alias{{Name: "cloudFoundry/serviceInstance"}}, 219 Default: os.Getenv("PIPER_cfServiceInstance"), 220 }, 221 { 222 Name: "cfServiceKeyName", 223 ResourceRef: []config.ResourceReference{}, 224 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 225 Type: "string", 226 Mandatory: false, 227 Aliases: []config.Alias{{Name: "cloudFoundry/serviceKey"}, {Name: "cloudFoundry/serviceKeyName"}, {Name: "cfServiceKey"}}, 228 Default: os.Getenv("PIPER_cfServiceKeyName"), 229 }, 230 { 231 Name: "host", 232 ResourceRef: []config.ResourceReference{}, 233 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 234 Type: "string", 235 Mandatory: false, 236 Aliases: []config.Alias{}, 237 Default: os.Getenv("PIPER_host"), 238 }, 239 { 240 Name: "username", 241 ResourceRef: []config.ResourceReference{}, 242 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 243 Type: "string", 244 Mandatory: true, 245 Aliases: []config.Alias{}, 246 Default: os.Getenv("PIPER_username"), 247 }, 248 { 249 Name: "password", 250 ResourceRef: []config.ResourceReference{}, 251 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 252 Type: "string", 253 Mandatory: true, 254 Aliases: []config.Alias{}, 255 Default: os.Getenv("PIPER_password"), 256 }, 257 { 258 Name: "addonDescriptor", 259 ResourceRef: []config.ResourceReference{ 260 { 261 Name: "commonPipelineEnvironment", 262 Param: "abap/addonDescriptor", 263 }, 264 }, 265 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 266 Type: "string", 267 Mandatory: true, 268 Aliases: []config.Alias{}, 269 Default: os.Getenv("PIPER_addonDescriptor"), 270 }, 271 { 272 Name: "maxRuntimeInMinutes", 273 ResourceRef: []config.ResourceReference{}, 274 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 275 Type: "int", 276 Mandatory: true, 277 Aliases: []config.Alias{}, 278 Default: 360, 279 }, 280 }, 281 }, 282 Containers: []config.Container{ 283 {Name: "cf", Image: "ppiper/cf-cli:7"}, 284 }, 285 Outputs: config.StepOutputs{ 286 Resources: []config.StepResources{ 287 { 288 Name: "commonPipelineEnvironment", 289 Type: "piperEnvironment", 290 Parameters: []map[string]interface{}{ 291 {"name": "abap/addonDescriptor"}, 292 }, 293 }, 294 }, 295 }, 296 }, 297 } 298 return theMetaData 299 }