github.com/SAP/jenkins-library@v1.362.0/cmd/abapAddonAssemblyKitCreateTargetVector_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 abapAddonAssemblyKitCreateTargetVectorOptions 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 abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment struct { 31 abap struct { 32 addonDescriptor string 33 } 34 } 35 36 func (p *abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment) 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 // AbapAddonAssemblyKitCreateTargetVectorCommand This step creates a Target Vector for software lifecycle operations 59 func AbapAddonAssemblyKitCreateTargetVectorCommand() *cobra.Command { 60 const STEP_NAME = "abapAddonAssemblyKitCreateTargetVector" 61 62 metadata := abapAddonAssemblyKitCreateTargetVectorMetadata() 63 var stepConfig abapAddonAssemblyKitCreateTargetVectorOptions 64 var startTime time.Time 65 var commonPipelineEnvironment abapAddonAssemblyKitCreateTargetVectorCommonPipelineEnvironment 66 var logCollector *log.CollectorHook 67 var splunkClient *splunk.Splunk 68 telemetryClient := &telemetry.Telemetry{} 69 70 var createAbapAddonAssemblyKitCreateTargetVectorCmd = &cobra.Command{ 71 Use: STEP_NAME, 72 Short: "This step creates a Target Vector for software lifecycle operations", 73 Long: `This step takes the Product Version and the corresponding list of Software Component Versions from the addonDescriptor in the commonPipelineEnvironment. 74 With these it creates a Target Vector, which is necessary for executing software lifecylce operations in ABAP Cloud Platform systems. 75 The Target Vector describes the software state, which shall be reached in the managed ABAP Cloud Platform system. 76 <br /> 77 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 78 <br /> 79 For Terminology refer to the [Scenario Description](https://www.project-piper.io/scenarios/abapEnvironmentAddons/).`, 80 PreRunE: func(cmd *cobra.Command, _ []string) error { 81 startTime = time.Now() 82 log.SetStepName(STEP_NAME) 83 log.SetVerbose(GeneralConfig.Verbose) 84 85 GeneralConfig.GitHubAccessTokens = ResolveAccessTokens(GeneralConfig.GitHubTokens) 86 87 path, _ := os.Getwd() 88 fatalHook := &log.FatalHook{CorrelationID: GeneralConfig.CorrelationID, Path: path} 89 log.RegisterHook(fatalHook) 90 91 err := PrepareConfig(cmd, &metadata, STEP_NAME, &stepConfig, config.OpenPiperFile) 92 if err != nil { 93 log.SetErrorCategory(log.ErrorConfiguration) 94 return err 95 } 96 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitCertificateFile) 97 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitCertificatePass) 98 log.RegisterSecret(stepConfig.Username) 99 log.RegisterSecret(stepConfig.Password) 100 log.RegisterSecret(stepConfig.AbapAddonAssemblyKitOriginHash) 101 102 if len(GeneralConfig.HookConfig.SentryConfig.Dsn) > 0 { 103 sentryHook := log.NewSentryHook(GeneralConfig.HookConfig.SentryConfig.Dsn, GeneralConfig.CorrelationID) 104 log.RegisterHook(&sentryHook) 105 } 106 107 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 || len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 108 splunkClient = &splunk.Splunk{} 109 logCollector = &log.CollectorHook{CorrelationID: GeneralConfig.CorrelationID} 110 log.RegisterHook(logCollector) 111 } 112 113 if err = log.RegisterANSHookIfConfigured(GeneralConfig.CorrelationID); err != nil { 114 log.Entry().WithError(err).Warn("failed to set up SAP Alert Notification Service log hook") 115 } 116 117 validation, err := validation.New(validation.WithJSONNamesForStructFields(), validation.WithPredefinedErrorMessages()) 118 if err != nil { 119 return err 120 } 121 if err = validation.ValidateStruct(stepConfig); err != nil { 122 log.SetErrorCategory(log.ErrorConfiguration) 123 return err 124 } 125 126 return nil 127 }, 128 Run: func(_ *cobra.Command, _ []string) { 129 stepTelemetryData := telemetry.CustomData{} 130 stepTelemetryData.ErrorCode = "1" 131 handler := func() { 132 commonPipelineEnvironment.persist(GeneralConfig.EnvRootPath, "commonPipelineEnvironment") 133 config.RemoveVaultSecretFiles() 134 stepTelemetryData.Duration = fmt.Sprintf("%v", time.Since(startTime).Milliseconds()) 135 stepTelemetryData.ErrorCategory = log.GetErrorCategory().String() 136 stepTelemetryData.PiperCommitHash = GitCommit 137 telemetryClient.SetData(&stepTelemetryData) 138 telemetryClient.Send() 139 if len(GeneralConfig.HookConfig.SplunkConfig.Dsn) > 0 { 140 splunkClient.Initialize(GeneralConfig.CorrelationID, 141 GeneralConfig.HookConfig.SplunkConfig.Dsn, 142 GeneralConfig.HookConfig.SplunkConfig.Token, 143 GeneralConfig.HookConfig.SplunkConfig.Index, 144 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 145 splunkClient.Send(telemetryClient.GetData(), logCollector) 146 } 147 if len(GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint) > 0 { 148 splunkClient.Initialize(GeneralConfig.CorrelationID, 149 GeneralConfig.HookConfig.SplunkConfig.ProdCriblEndpoint, 150 GeneralConfig.HookConfig.SplunkConfig.ProdCriblToken, 151 GeneralConfig.HookConfig.SplunkConfig.ProdCriblIndex, 152 GeneralConfig.HookConfig.SplunkConfig.SendLogs) 153 splunkClient.Send(telemetryClient.GetData(), logCollector) 154 } 155 } 156 log.DeferExitHandler(handler) 157 defer handler() 158 telemetryClient.Initialize(GeneralConfig.NoTelemetry, STEP_NAME, GeneralConfig.HookConfig.PendoConfig.Token) 159 abapAddonAssemblyKitCreateTargetVector(stepConfig, &stepTelemetryData, &commonPipelineEnvironment) 160 stepTelemetryData.ErrorCode = "0" 161 log.Entry().Info("SUCCESS") 162 }, 163 } 164 165 addAbapAddonAssemblyKitCreateTargetVectorFlags(createAbapAddonAssemblyKitCreateTargetVectorCmd, &stepConfig) 166 return createAbapAddonAssemblyKitCreateTargetVectorCmd 167 } 168 169 func addAbapAddonAssemblyKitCreateTargetVectorFlags(cmd *cobra.Command, stepConfig *abapAddonAssemblyKitCreateTargetVectorOptions) { 170 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)") 171 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitCertificatePass, "abapAddonAssemblyKitCertificatePass", os.Getenv("PIPER_abapAddonAssemblyKitCertificatePass"), "password to decrypt the certificate file") 172 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitEndpoint, "abapAddonAssemblyKitEndpoint", `https://apps.support.sap.com`, "Base URL to the Addon Assembly Kit as a Service (AAKaaS) system") 173 cmd.Flags().StringVar(&stepConfig.Username, "username", os.Getenv("PIPER_username"), "User for the Addon Assembly Kit as a Service (AAKaaS) system") 174 cmd.Flags().StringVar(&stepConfig.Password, "password", os.Getenv("PIPER_password"), "Password for the Addon Assembly Kit as a Service (AAKaaS) system") 175 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") 176 cmd.Flags().StringVar(&stepConfig.AbapAddonAssemblyKitOriginHash, "abapAddonAssemblyKitOriginHash", os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), "Origin Hash for restricted AAKaaS scenarios") 177 178 cmd.MarkFlagRequired("abapAddonAssemblyKitEndpoint") 179 cmd.MarkFlagRequired("addonDescriptor") 180 } 181 182 // retrieve step metadata 183 func abapAddonAssemblyKitCreateTargetVectorMetadata() config.StepData { 184 var theMetaData = config.StepData{ 185 Metadata: config.StepMetadata{ 186 Name: "abapAddonAssemblyKitCreateTargetVector", 187 Aliases: []config.Alias{}, 188 Description: "This step creates a Target Vector for software lifecycle operations", 189 }, 190 Spec: config.StepSpec{ 191 Inputs: config.StepInputs{ 192 Secrets: []config.StepSecrets{ 193 {Name: "abapAddonAssemblyKitCredentialsId", Description: "Credential stored in Jenkins for the Addon Assembly Kit as a Service (AAKaaS) system", Type: "jenkins"}, 194 {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"}, 195 {Name: "abapAddonAssemblyKitCertificatePassCredentialsId", Description: "Jenkins secret text credential ID containing the password to decrypt the certificate file stored in abapAddonAssemblyKitCertificateFileCredentialsId", Type: "jenkins"}, 196 }, 197 Parameters: []config.StepParameters{ 198 { 199 Name: "abapAddonAssemblyKitCertificateFile", 200 ResourceRef: []config.ResourceReference{ 201 { 202 Name: "abapAddonAssemblyKitCertificateFileCredentialsId", 203 Param: "abapAddonAssemblyKitCertificateFile", 204 Type: "secret", 205 }, 206 }, 207 Scope: []string{"PARAMETERS"}, 208 Type: "string", 209 Mandatory: false, 210 Aliases: []config.Alias{}, 211 Default: os.Getenv("PIPER_abapAddonAssemblyKitCertificateFile"), 212 }, 213 { 214 Name: "abapAddonAssemblyKitCertificatePass", 215 ResourceRef: []config.ResourceReference{ 216 { 217 Name: "abapAddonAssemblyKitCertificatePassCredentialsId", 218 Param: "abapAddonAssemblyKitCertificatePass", 219 Type: "secret", 220 }, 221 }, 222 Scope: []string{"PARAMETERS"}, 223 Type: "string", 224 Mandatory: false, 225 Aliases: []config.Alias{}, 226 Default: os.Getenv("PIPER_abapAddonAssemblyKitCertificatePass"), 227 }, 228 { 229 Name: "abapAddonAssemblyKitEndpoint", 230 ResourceRef: []config.ResourceReference{}, 231 Scope: []string{"PARAMETERS", "STAGES", "STEPS", "GENERAL"}, 232 Type: "string", 233 Mandatory: true, 234 Aliases: []config.Alias{}, 235 Default: `https://apps.support.sap.com`, 236 }, 237 { 238 Name: "username", 239 ResourceRef: []config.ResourceReference{}, 240 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 241 Type: "string", 242 Mandatory: false, 243 Aliases: []config.Alias{}, 244 Default: os.Getenv("PIPER_username"), 245 }, 246 { 247 Name: "password", 248 ResourceRef: []config.ResourceReference{}, 249 Scope: []string{"PARAMETERS"}, 250 Type: "string", 251 Mandatory: false, 252 Aliases: []config.Alias{}, 253 Default: os.Getenv("PIPER_password"), 254 }, 255 { 256 Name: "addonDescriptor", 257 ResourceRef: []config.ResourceReference{ 258 { 259 Name: "commonPipelineEnvironment", 260 Param: "abap/addonDescriptor", 261 }, 262 }, 263 Scope: []string{"PARAMETERS", "STAGES", "STEPS"}, 264 Type: "string", 265 Mandatory: true, 266 Aliases: []config.Alias{}, 267 Default: os.Getenv("PIPER_addonDescriptor"), 268 }, 269 { 270 Name: "abapAddonAssemblyKitOriginHash", 271 ResourceRef: []config.ResourceReference{}, 272 Scope: []string{"PARAMETERS"}, 273 Type: "string", 274 Mandatory: false, 275 Aliases: []config.Alias{}, 276 Default: os.Getenv("PIPER_abapAddonAssemblyKitOriginHash"), 277 }, 278 }, 279 }, 280 Outputs: config.StepOutputs{ 281 Resources: []config.StepResources{ 282 { 283 Name: "commonPipelineEnvironment", 284 Type: "piperEnvironment", 285 Parameters: []map[string]interface{}{ 286 {"name": "abap/addonDescriptor"}, 287 }, 288 }, 289 }, 290 }, 291 }, 292 } 293 return theMetaData 294 }