github.com/SAP/jenkins-library@v1.362.0/cmd/abapAddonAssemblyKitRegisterPackages_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 abapAddonAssemblyKitRegisterPackagesOptions 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 AbapAddonAssemblyKitOriginHash string `json:"abapAddonAssemblyKitOriginHash,omitempty"` 28 } 29 30 type abapAddonAssemblyKitRegisterPackagesCommonPipelineEnvironment struct { 31 abap struct { 32 addonDescriptor string 33 } 34 } 35 36 func (p *abapAddonAssemblyKitRegisterPackagesCommonPipelineEnvironment) persist(path, resourceName string) { 37 content := []struct { 38 category string 39 name string 40 value interface{} 41 }{ 42 {category: "abap", name: "addonDescriptor", value: p.abap.addonDescriptor}, 43 } 44 45 errCount := 0 46 for _, param := range content { 47 err := piperenv.SetResourceParameter(path, resourceName, filepath.Join(param.category, param.name), param.value) 48 if err != nil { 49 log.Entry().WithError(err).Error("Error persisting piper environment.") 50 errCount++ 51 } 52 } 53 if errCount > 0 { 54 log.Entry().Error("failed to persist Piper environment") 55 } 56 } 57 58 // AbapAddonAssemblyKitRegisterPackagesCommand This step uploads the SAR archives and creates physical Delivery Packages to AAKaaS. 59 func AbapAddonAssemblyKitRegisterPackagesCommand() *cobra.Command { 60 const STEP_NAME = "abapAddonAssemblyKitRegisterPackages" 61 62 metadata := abapAddonAssemblyKitRegisterPackagesMetadata() 63 var stepConfig abapAddonAssemblyKitRegisterPackagesOptions 64 var startTime time.Time 65 var commonPipelineEnvironment abapAddonAssemblyKitRegisterPackagesCommonPipelineEnvironment 66 var logCollector *log.CollectorHook 67 var splunkClient *splunk.Splunk 68 telemetryClient := &telemetry.Telemetry{} 69 70 var createAbapAddonAssemblyKitRegisterPackagesCmd = &cobra.Command{ 71 Use: STEP_NAME, 72 Short: "This step uploads the SAR archives and creates physical Delivery Packages to AAKaaS.", 73 Long: `This step takes the list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. 74 For Packages in status "P" = planned it uploads the SAR archive with the data file and metadata XML of the Delivery Packages composed and exported in the build system 75 and creates physical Delivery Package in AAKaaS. 76 The new status "L" = locked 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.Username) 100 log.RegisterSecret(stepConfig.Password) 101 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash) 102 103 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 104 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 105 log.RegisterHook(&sentryHook) 106 } 107 108 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 || len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 109 splunkClient = &splunk.Splunk{} 110 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 111 log.RegisterHook(logCollector) 112 } 113 114 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 115 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 116 } 117 118 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 119 if err != nil { 120 return err 121 } 122 if err = validation.ValidateStruct(stepConfig); err != nil { 123 log.SetErrorCategory(log.ErrorConfiguration) 124 return err 125 } 126 127 return nil 128 }, 129 Run: func(_ *cobra.Command, _ []string) { 130 stepTelemetryData := telemetry.CustomData{} 131 stepTelemetryData.ErrorCode = "1" 132 handler := func() { 133 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 134 config.RemoveVaultSecretFiles() 135 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 136 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 137 stepTelemetryData.PiperCommitHash = GitCommit 138 telemetryClient.SetData(&stepTelemetryData) 139 telemetryClient.Send() 140 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 141 splunkClient.Initialize(GeneralConfig.CorrelationID, 142 GeneralConfig.HookConfig.SplunkConfig.Dsn, 143 GeneralConfig.HookConfig.SplunkConfig.Token, 144 GeneralConfig.HookConfig.SplunkConfig.Index, 145 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 146 splunkClient.Send(telemetryClient.GetData(), logCollector) 147 } 148 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 149 splunkClient.Initialize(GeneralConfig.CorrelationID, 150 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 151 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 152 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 153 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 154 splunkClient.Send(telemetryClient.GetData(), logCollector) 155 } 156 } 157 log.DeferExitHandler(handler) 158 defer handler() 159 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME, GeneralConfig.HookConfig.PendoConfig.Token) 160 abapAddonAssemblyKitRegisterPackages(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 161 stepTelemetryData.ErrorCode = "0" 162 log.Entry().Info("SUCCESS") 163 }, 164 } 165 166 addAbapAddonAssemblyKitRegisterPackagesFlags(createAbapAddonAssemblyKitRegisterPackagesCmd, &stepConfig) 167 return createAbapAddonAssemblyKitRegisterPackagesCmd 168 } 169 170 func addAbapAddonAssemblyKitRegisterPackagesFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitRegisterPackagesOptions) { 171 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)") 172 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitCertificatePass, "abapAddonAssemblyKitCertificatePass", os.Getenv("PIPER_abapAddonAssemblyKitCertificatePass"), "password to decrypt the certificate file") 173 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", `https://apps.support.sap.com`, "Base URL to the Addon Assembly Kit as a Service (AAKaaS) system") 174 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system") 175 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system") 176 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") 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 abapAddonAssemblyKitRegisterPackagesMetadata() config.StepData { 185 var theMetaData = config.StepData{ 186 Metadata: config.StepMetadata{ 187 Name: "abapAddonAssemblyKitRegisterPackages", 188 Aliases: []config.Alias{}, 189 Description: "This step uploads the SAR archives and creates physical Delivery Packages to AAKaaS.", 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: "abapAddonAssemblyKitOriginHash", 272 ResourceRef: []config.ResourceReference{}, 273 Scope: []string{"PARAMETERS"}, 274 Type: "string", 275 Mandatory: false, 276 Aliases: []config.Alias{}, 277 Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), 278 }, 279 }, 280 }, 281 Outputs: config.StepOutputs{ 282 Resources: []config.StepResources{ 283 { 284 Name: "commonPipelineEnvironment", 285 Type: "piperEnvironment", 286 Parameters: []map[string]interface{}{ 287 {"name": "abap/addonDescriptor"}, 288 }, 289 }, 290 }, 291 }, 292 }, 293 } 294 return theMetaData 295 }