1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/cmd/tmsExport.go
Oliver Feldmann 17de9ed34c
Allow cALM service key for cTMS steps (#4661)
* 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>
2023-11-27 14:28:18 +01:00

70 lines
2.3 KiB
Go

package cmd
import (
"fmt"
"github.com/SAP/jenkins-library/pkg/command"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/piperutils"
"github.com/SAP/jenkins-library/pkg/telemetry"
"github.com/SAP/jenkins-library/pkg/tms"
)
type tmsExportUtilsBundle struct {
*command.Command
*piperutils.Files
}
func tmsExport(exportConfig tmsExportOptions, telemetryData *telemetry.CustomData, influx *tmsExportInflux) {
utils := tms.NewTmsUtils()
config := convertExportOptions(exportConfig)
communicationInstance := tms.SetupCommunication(config)
err := runTmsExport(exportConfig, communicationInstance, utils)
if err != nil {
log.Entry().WithError(err).Fatal("Failed to run tmsExport")
}
}
func runTmsExport(exportConfig tmsExportOptions, communicationInstance tms.CommunicationInterface, utils tms.TmsUtils) error {
config := convertExportOptions(exportConfig)
fileInfo, errUploadFile := tms.UploadFile(config, communicationInstance, utils)
if errUploadFile != nil {
return errUploadFile
}
errUploadDescriptors := tms.UploadDescriptors(config, communicationInstance, utils)
if errUploadDescriptors != nil {
return errUploadDescriptors
}
_, errExportFileToNode := communicationInstance.ExportFileToNode(fileInfo, config.NodeName, config.CustomDescription, config.NamedUser)
if errExportFileToNode != nil {
log.SetErrorCategory(log.ErrorService)
return fmt.Errorf("failed to export file to node: %w", errExportFileToNode)
}
return nil
}
func convertExportOptions(exportConfig tmsExportOptions) tms.Options {
var config tms.Options
config.ServiceKey = exportConfig.ServiceKey
if exportConfig.ServiceKey == "" && exportConfig.TmsServiceKey != "" {
config.ServiceKey = exportConfig.TmsServiceKey
log.Entry().Warn("DEPRECATION WARNING: The tmsServiceKey parameter has been deprecated, please use the serviceKey parameter instead.")
}
config.CustomDescription = exportConfig.CustomDescription
if config.CustomDescription == "" {
config.CustomDescription = tms.DEFAULT_TR_DESCRIPTION
}
config.NamedUser = exportConfig.NamedUser
config.NodeName = exportConfig.NodeName
config.MtaPath = exportConfig.MtaPath
config.MtaVersion = exportConfig.MtaVersion
config.NodeExtDescriptorMapping = exportConfig.NodeExtDescriptorMapping
config.Proxy = exportConfig.Proxy
config.Verbose = GeneralConfig.Verbose
return config
}