github.com/SAP/jenkins-library@v1.362.0/cmd/abapAddonAssemblyKitReleasePackages_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 abapAddonAssemblyKitReleasePackagesOptions struct { 21 AbapAddonAssemblyKitCertificateFile string `json:"abapAddonAssemblyKitCertificateFile,omitempty"` 22 AbapAddonAssemblyKitCertificatePass string `json:"abapAddonAssemblyKitCertificatePass,omitempty"` 23 AbapAddonAssemblyKitEndpoint string `json:"abapAddonAssemblyKitEndpoint,omitempty"` 24 Username string `json:"username,omitempty"` 25 Password string `json:"password,omitempty"` 26 AddonDescriptor string `json:"addonDescriptor,omitempty"` 27 MaxRuntimeInMinutes int `json:"maxRuntimeInMinutes,omitempty"` 28 PollingIntervalInSeconds int `json:"pollingIntervalInSeconds,omitempty"` 29 AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"` 30 } 31 32 type abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment struct { 33 abap struct { 34 addonDescriptor string 35 } 36 } 37 38 func (p *abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment) persist(path, resourceName string) { 39 content := []struct { 40 category string 41 name string 42 value interface{} 43 }{ 44 {category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, 45 } 46 47 errCount := 0 48 for _, param := range content { 49 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 50 if err != nil { 51 log.Entry().WithError(err).Error("Error persisting piper environment.") 52 errCount++ 53 } 54 } 55 if errCount > 0 { 56 log.Entry().Error("failed to persist Piper environment") 57 } 58 } 59 60 // AbapAddonAssemblyKitReleasePackagesCommand This step releases the physical Delivery Packages 61 func AbapAddonAssemblyKitReleasePackagesCommand() *cobra.Command { 62 const STEP_NAME = "abapAddonAssemblyKitReleasePackages" 63 64 metadata := abapAddonAssemblyKitReleasePackagesMetadata() 65 var stepConfig abapAddonAssemblyKitReleasePackagesOptions 66 var startTime time.Time 67 var commonPipelineEnvironment abapAddonAssemblyKitReleasePackagesCommonPipelineEnvironment 68 var logCollector *log.CollectorHook 69 var splunkClient *splunk.Splunk 70 telemetryClient := &telemetry.Telemetry{} 71 72 var createAbapAddonAssemblyKitReleasePackagesCmd = &cobra.Command{ 73 Use: STEP_NAME, 74 Short: "This step releases the physical Delivery Packages", 75 Long: `This step takes the list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. 76 The physical Delivery Packages in status āLā are released. The new status "R"eleased is written back to the addonDescriptor in the commonPipelineEnvironment. 77 <br /> 78 For logon you can either provide a credential with basic authorization (username and password) or two secret text credentials containing the technical s-users certificate (see note [2805811](https://me.sap.com/notes/2805811) for download) as base64 encoded string and the password to decrypt the file 79 <br /> 80 For Terminology refer to the [Scenario Description](https://www.project-piper.io/scenarios/abapEnvironmentAddons/).`, 81 PreRunE: func(cmd *cobra.Command, _ []string) error { 82 startTime = time.Now() 83 log.SetStepName(STEP_NAME) 84 log.SetVerbose(GeneralConfig.Verbose) 85 86 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 87 88 path, _ := os.Getwd() 89 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 90 log.RegisterHook(fatalHook) 91 92 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 93 if err != nil { 94 log.SetErrorCategory(log.ErrorConfiguration) 95 return err 96 } 97 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitCertificateFile) 98 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitCertificatePass) 99 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash) 100 101 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 102 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 103 log.RegisterHook(&sentryHook) 104 } 105 106 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 || len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 107 splunkClient = &splunk.Splunk{} 108 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 109 log.RegisterHook(logCollector) 110 } 111 112 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 113 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 114 } 115 116 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 117 if err != nil { 118 return err 119 } 120 if err = validation.ValidateStruct(stepConfig); err != nil { 121 log.SetErrorCategory(log.ErrorConfiguration) 122 return err 123 } 124 125 return nil 126 }, 127 Run: func(_ *cobra.Command, _ []string) { 128 stepTelemetryData := telemetry.CustomData{} 129 stepTelemetryData.ErrorCode = "1" 130 handler := func() { 131 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 132 config.RemoveVaultSecretFiles() 133 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 134 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 135 stepTelemetryData.PiperCommitHash = GitCommit 136 telemetryClient.SetData(&stepTelemetryData) 137 telemetryClient.Send() 138 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 139 splunkClient.Initialize(GeneralConfig.CorrelationID, 140 GeneralConfig.HookConfig.SplunkConfig.Dsn, 141 GeneralConfig.HookConfig.SplunkConfig.Token, 142 GeneralConfig.HookConfig.SplunkConfig.Index, 143 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 144 splunkClient.Send(telemetryClient.GetData(), logCollector) 145 } 146 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 147 splunkClient.Initialize(GeneralConfig.CorrelationID, 148 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 149 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 150 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 151 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 152 splunkClient.Send(telemetryClient.GetData(), logCollector) 153 } 154 } 155 log.DeferExitHandler(handler) 156 defer handler() 157 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME, GeneralConfig.HookConfig.PendoConfig.Token) 158 abapAddonAssemblyKitReleasePackages(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 159 stepTelemetryData.ErrorCode = "0" 160 log.Entry().Info("SUCCESS") 161 }, 162 } 163 164 addAbapAddonAssemblyKitReleasePackagesFlags(createAbapAddonAssemblyKitReleasePackagesCmd, &stepConfig) 165 return createAbapAddonAssemblyKitReleasePackagesCmd 166 } 167 168 func addAbapAddonAssemblyKitReleasePackagesFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitReleasePackagesOptions) { 169 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitCertificateFile, "abapAddonAssemblyKitCertificateFile", os.Getenv("PIPER_abapAddonAssemblyKitCertificateFile"), "base64 encoded certificate pfx file (PKCS12 format) see note [2805811](https://me.sap.com/notes/2805811)") 170 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitCertificatePass, "abapAddonAssemblyKitCertificatePass", os.Getenv("PIPER_abapAddonAssemblyKitCertificatePass"), "password to decrypt the certificate file") 171 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", `https://apps.support.sap.com`, "Base URL to the Addon Assembly Kit as a Service (AAKaaS) system") 172 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system") 173 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system") 174 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") 175 cmd.Flags().IntVar(&stepConfig.MaxRuntimeInMinutes, "maxRuntimeInMinutes", 5, "Maximum runtime for status polling in minutes") 176 cmd.Flags().IntVar(&stepConfig.PollingIntervalInSeconds, "pollingIntervalInSeconds", 30, "Wait time in seconds between polling calls") 177 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios") 178 179 cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint") 180 cmd.MarkFlagRequired("addonDescriptor") 181 } 182 183 // retrieve step metadata 184 func abapAddonAssemblyKitReleasePackagesMetadata() config.StepData { 185 var theMetaData = config.StepData{ 186 Metadata: config.StepMetadata{ 187 Name: "abapAddonAssemblyKitReleasePackages", 188 Aliases: []config.Alias{}, 189 Description: "This step releases the physical Delivery Packages", 190 }, 191 Spec: config.StepSpec{ 192 Inputs: config.StepInputs{ 193 Secrets: []config.StepSecrets{ 194 {Name: "abapAddonAssemblyKitCredentialsId", Description: "Credential stored in Jenkins for the Addon Assembly Kit as a Service (AAKaaS) system", Type: "jenkins"}, 195 {Name: "abapAddonAssemblyKitCertificateFileCredentialsId", Description: "Jenkins secret text credential ID containing the base64 encoded certificate pfx file (PKCS12 format) see note [2805811](https://me.sap.com/notes/2805811)", Type: "jenkins"}, 196 {Name: "abapAddonAssemblyKitCertificatePassCredentialsId", Description: "Jenkins secret text credential ID containing the password to decrypt the certificate file stored in abapAddonAssemblyKitCertificateFileCredentialsId", Type: "jenkins"}, 197 }, 198 Parameters: []config.StepParameters{ 199 { 200 Name: "abapAddonAssemblyKitCertificateFile", 201 ResourceRef: []config.ResourceReference{ 202 { 203 Name: "abapAddonAssemblyKitCertificateFileCredentialsId", 204 Param: "abapAddonAssemblyKitCertificateFile", 205 Type: "secret", 206 }, 207 }, 208 Scope: []string{"PARAMETERS"}, 209 Type: "string", 210 Mandatory: false, 211 Aliases: []config.Alias{}, 212 Default: os.Getenv("PIPER_abapAddonAssemblyKitCertificateFile"), 213 }, 214 { 215 Name: "abapAddonAssemblyKitCertificatePass", 216 ResourceRef: []config.ResourceReference{ 217 { 218 Name: "abapAddonAssemblyKitCertificatePassCredentialsId", 219 Param: "abapAddonAssemblyKitCertificatePass", 220 Type: "secret", 221 }, 222 }, 223 Scope: []string{"PARAMETERS"}, 224 Type: "string", 225 Mandatory: false, 226 Aliases: []config.Alias{}, 227 Default: os.Getenv("PIPER_abapAddonAssemblyKitCertificatePass"), 228 }, 229 { 230 Name: "abapAddonAssemblyKitEndpoint", 231 ResourceRef: []config.ResourceReference{}, 232 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 233 Type: "string", 234 Mandatory: true, 235 Aliases: []config.Alias{}, 236 Default: `https://apps.support.sap.com`, 237 }, 238 { 239 Name: "username", 240 ResourceRef: []config.ResourceReference{}, 241 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 242 Type: "string", 243 Mandatory: false, 244 Aliases: []config.Alias{}, 245 Default: os.Getenv("PIPER_username"), 246 }, 247 { 248 Name: "password", 249 ResourceRef: []config.ResourceReference{}, 250 Scope: []string{"PARAMETERS"}, 251 Type: "string", 252 Mandatory: false, 253 Aliases: []config.Alias{}, 254 Default: os.Getenv("PIPER_password"), 255 }, 256 { 257 Name: "addonDescriptor", 258 ResourceRef: []config.ResourceReference{ 259 { 260 Name: "commonPipelineEnvironment", 261 Param: "abap/addonDescriptor", 262 }, 263 }, 264 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 265 Type: "string", 266 Mandatory: true, 267 Aliases: []config.Alias{}, 268 Default: os.Getenv("PIPER_addonDescriptor"), 269 }, 270 { 271 Name: "maxRuntimeInMinutes", 272 ResourceRef: []config.ResourceReference{}, 273 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 274 Type: "int", 275 Mandatory: false, 276 Aliases: []config.Alias{}, 277 Default: 5, 278 }, 279 { 280 Name: "pollingIntervalInSeconds", 281 ResourceRef: []config.ResourceReference{}, 282 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 283 Type: "int", 284 Mandatory: false, 285 Aliases: []config.Alias{}, 286 Default: 30, 287 }, 288 { 289 Name: "abapAddonAssemblyKitOriginHash", 290 ResourceRef: []config.ResourceReference{}, 291 Scope: []string{"PARAMETERS"}, 292 Type: "string", 293 Mandatory: false, 294 Aliases: []config.Alias{}, 295 Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), 296 }, 297 }, 298 }, 299 Outputs: config.StepOutputs{ 300 Resources: []config.StepResources{ 301 { 302 Name: "commonPipelineEnvironment", 303 Type: "piperEnvironment", 304 Parameters: []map[string]interface{}{ 305 {"name": "abap/addonDescriptor"}, 306 }, 307 }, 308 }, 309 }, 310 }, 311 } 312 return theMetaData 313 }