mirror of
https://github.com/SAP/jenkins-library.git
synced 2024-12-14 11:03:09 +02:00
17de9ed34c
* Allow cALM service keys * Fix typo Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> * fix typo Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> * Hardcode tms endpoint in calm test case * Add new serviceKey parameter * Use new serviceKey parameter With deprecation warning if old tmsServiceKey parameter is used * Add unit tests and optimise * Remove tms from service key log message * Apply suggestions from code review Co-authored-by: Artem Bannikov <62880541+artembannikov@users.noreply.github.com> * Remove unused json fields mapping * Apply review suggestion * Apply further review suggestions * Use new parameter name in groovy * Generate again * Fix groovy test --------- Co-authored-by: Srinikitha Kondreddy <srinikitha.kondreddy@sap.com> Co-authored-by: Artem Bannikov <62880541+artembannikov@users.noreply.github.com>
64 lines
2.2 KiB
Go
64 lines
2.2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
"github.com/SAP/jenkins-library/pkg/tms"
|
|
)
|
|
|
|
func tmsUpload(uploadConfig tmsUploadOptions, telemetryData *telemetry.CustomData, influx *tmsUploadInflux) {
|
|
utils := tms.NewTmsUtils()
|
|
config := convertUploadOptions(uploadConfig)
|
|
communicationInstance := tms.SetupCommunication(config)
|
|
|
|
err := runTmsUpload(uploadConfig, communicationInstance, utils)
|
|
if err != nil {
|
|
log.Entry().WithError(err).Fatal("Failed to run tmsUpload step")
|
|
}
|
|
}
|
|
|
|
func runTmsUpload(uploadConfig tmsUploadOptions, communicationInstance tms.CommunicationInterface, utils tms.TmsUtils) error {
|
|
config := convertUploadOptions(uploadConfig)
|
|
fileInfo, errUploadFile := tms.UploadFile(config, communicationInstance, utils)
|
|
if errUploadFile != nil {
|
|
return errUploadFile
|
|
}
|
|
|
|
errUploadDescriptors := tms.UploadDescriptors(config, communicationInstance, utils)
|
|
if errUploadDescriptors != nil {
|
|
return errUploadDescriptors
|
|
}
|
|
|
|
_, errUploadFileToNode := communicationInstance.UploadFileToNode(fileInfo, config.NodeName, config.CustomDescription, config.NamedUser)
|
|
if errUploadFileToNode != nil {
|
|
log.SetErrorCategory(log.ErrorService)
|
|
return fmt.Errorf("failed to upload file to node: %w", errUploadFileToNode)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func convertUploadOptions(uploadConfig tmsUploadOptions) tms.Options {
|
|
var config tms.Options
|
|
config.ServiceKey = uploadConfig.ServiceKey
|
|
if uploadConfig.ServiceKey == "" && uploadConfig.TmsServiceKey != "" {
|
|
config.ServiceKey = uploadConfig.TmsServiceKey
|
|
log.Entry().Warn("DEPRECATION WARNING: The tmsServiceKey parameter has been deprecated, please use the serviceKey parameter instead.")
|
|
}
|
|
config.CustomDescription = uploadConfig.CustomDescription
|
|
if config.CustomDescription == "" {
|
|
config.CustomDescription = tms.DEFAULT_TR_DESCRIPTION
|
|
}
|
|
config.NamedUser = uploadConfig.NamedUser
|
|
config.NodeName = uploadConfig.NodeName
|
|
config.MtaPath = uploadConfig.MtaPath
|
|
config.MtaVersion = uploadConfig.MtaVersion
|
|
config.NodeExtDescriptorMapping = uploadConfig.NodeExtDescriptorMapping
|
|
config.Proxy = uploadConfig.Proxy
|
|
config.StashContent = uploadConfig.StashContent
|
|
config.Verbose = GeneralConfig.Verbose
|
|
return config
|
|
}
|