1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2025-01-16 05:16:08 +02:00
sap-jenkins-library/cmd/ansSendEvent.go
Pavel Busko 98e4e01635
feat(cnbBuild): warn users when dockerConfigJSON is missing necessary credentials (#5007)
* feat(cnbBuild): warn users when dockerConfigJSON is missing necessary credentials

* Update cmd/cnbBuild.go

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>

* Update pkg/cnbutils/auth.go

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>

* fix linting

---------

Co-authored-by: Ralf Pannemans <ralf.pannemans@sap.com>
2024-08-15 10:20:01 +02:00

59 lines
1.5 KiB
Go

package cmd
import (
"encoding/json"
"time"
"github.com/SAP/jenkins-library/pkg/ans"
"github.com/SAP/jenkins-library/pkg/log"
"github.com/SAP/jenkins-library/pkg/telemetry"
)
func ansSendEvent(config ansSendEventOptions, telemetryData *telemetry.CustomData) {
err := runAnsSendEvent(&config, &ans.ANS{})
if err != nil {
log.Entry().WithError(err).Fatal("step execution failed")
}
}
func runAnsSendEvent(config *ansSendEventOptions, c ans.Client) error {
ansServiceKey, err := ans.UnmarshallServiceKeyJSON(config.AnsServiceKey)
if err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
c.SetServiceKey(ansServiceKey)
event := ans.Event{
EventType: config.EventType,
Severity: config.Severity,
Category: config.Category,
Subject: config.Subject,
Body: config.Body,
Priority: config.Priority,
Tags: config.Tags,
Resource: &ans.Resource{
ResourceName: config.ResourceName,
ResourceType: config.ResourceType,
ResourceInstance: config.ResourceInstance,
Tags: config.ResourceTags,
},
}
if GeneralConfig.Verbose {
eventJson, _ := json.MarshalIndent(event, "", " ")
log.Entry().Infof("Event details: %s", eventJson)
}
if err = event.Validate(); err != nil {
log.SetErrorCategory(log.ErrorConfiguration)
return err
}
// We set the time
event.EventTimestamp = time.Now().Unix()
if err = c.Send(event); err != nil {
log.SetErrorCategory(log.ErrorService)
}
return err
}