Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Fix linter findings for revive:exported in plugins/inputs/webhooks/* #16411

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions plugins/inputs/webhooks/artifactory/artifactory_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ import (
"github.com/influxdata/telegraf"
)

type ArtifactoryWebhook struct {
type Webhook struct {
Path string
Secret string
acc telegraf.Accumulator
log telegraf.Logger
}

func (awh *ArtifactoryWebhook) Register(router *mux.Router, acc telegraf.Accumulator, log telegraf.Logger) {
// Register registers the webhook with the provided router
func (awh *Webhook) Register(router *mux.Router, acc telegraf.Accumulator, log telegraf.Logger) {
router.HandleFunc(awh.Path, awh.eventHandler).Methods("POST")

awh.log = log
awh.log.Infof("Started webhooks_artifactory on %s", awh.Path)
awh.acc = acc
}

func (awh *ArtifactoryWebhook) eventHandler(rw http.ResponseWriter, r *http.Request) {
func (awh *Webhook) eventHandler(rw http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
data, err := io.ReadAll(r.Body)
if err != nil {
Expand All @@ -49,13 +50,13 @@ func (awh *ArtifactoryWebhook) eventHandler(rw http.ResponseWriter, r *http.Requ
}
et := fmt.Sprintf("%v", bodyFields["event_type"])
ed := fmt.Sprintf("%v", bodyFields["domain"])
ne, err := awh.NewEvent(data, et, ed)
ne, err := awh.newEvent(data, et, ed)

if err != nil {
rw.WriteHeader(http.StatusBadRequest)
}
if ne != nil {
nm := ne.NewMetric()
nm := ne.newMetric()
awh.acc.AddFields("artifactory_webhooks", nm.Fields(), nm.Tags(), nm.Time())
}

Expand All @@ -70,7 +71,7 @@ func (e *newEventError) Error() string {
return e.s
}

func (awh *ArtifactoryWebhook) NewEvent(data []byte, et, ed string) (event, error) {
func (awh *Webhook) newEvent(data []byte, et, ed string) (event, error) {
awh.log.Debugf("New %v domain %v event received", ed, et)
switch ed {
case "artifact":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package artifactory

func UnsupportedEventJSON() string {
func unsupportedEventJSON() string {
return `
{
"domain": "not_supported",
Expand All @@ -15,7 +15,7 @@ func UnsupportedEventJSON() string {
}`
}

func ArtifactDeployedEventJSON() string {
func artifactDeployedEventJSON() string {
return `
{
"domain": "artifact",
Expand All @@ -30,7 +30,7 @@ func ArtifactDeployedEventJSON() string {
}`
}

func ArtifactDeletedEventJSON() string {
func artifactDeletedEventJSON() string {
return `
{
"domain": "artifact",
Expand All @@ -45,7 +45,7 @@ func ArtifactDeletedEventJSON() string {
}`
}

func ArtifactMovedEventJSON() string {
func artifactMovedEventJSON() string {
return `
{
"domain": "artifact",
Expand All @@ -62,7 +62,7 @@ func ArtifactMovedEventJSON() string {
}`
}

func ArtifactCopiedEventJSON() string {
func artifactCopiedEventJSON() string {
return `
{
"domain": "artifact",
Expand All @@ -79,7 +79,7 @@ func ArtifactCopiedEventJSON() string {
}`
}

func ArtifactPropertiesAddedEventJSON() string {
func artifactPropertiesAddedEventJSON() string {
return `
{
"domain": "artifact_property",
Expand All @@ -98,7 +98,7 @@ func ArtifactPropertiesAddedEventJSON() string {
}`
}

func ArtifactPropertiesDeletedEventJSON() string {
func artifactPropertiesDeletedEventJSON() string {
return `
{
"domain": "artifact_property",
Expand All @@ -117,7 +117,7 @@ func ArtifactPropertiesDeletedEventJSON() string {
}`
}

func DockerPushedEventJSON() string {
func dockerPushedEventJSON() string {
return `
{
"domain": "docker",
Expand All @@ -140,7 +140,7 @@ func DockerPushedEventJSON() string {
}`
}

func DockerDeletedEventJSON() string {
func dockerDeletedEventJSON() string {
return `
{
"domain": "docker",
Expand All @@ -163,7 +163,7 @@ func DockerDeletedEventJSON() string {
}`
}

func DockerPromotedEventJSON() string {
func dockerPromotedEventJSON() string {
return `
{
"domain": "docker",
Expand All @@ -186,7 +186,7 @@ func DockerPromotedEventJSON() string {
}`
}

func BuildUploadedEventJSON() string {
func buildUploadedEventJSON() string {
return `
{
"domain": "build",
Expand All @@ -199,7 +199,7 @@ func BuildUploadedEventJSON() string {
}`
}

func BuildDeletedEventJSON() string {
func buildDeletedEventJSON() string {
return `
{
"domain": "build",
Expand All @@ -212,7 +212,7 @@ func BuildDeletedEventJSON() string {
}`
}

func BuildPromotedEventJSON() string {
func buildPromotedEventJSON() string {
return `
{
"domain": "build",
Expand All @@ -225,7 +225,7 @@ func BuildPromotedEventJSON() string {
}`
}

func ReleaseBundleCreatedEventJSON() string {
func releaseBundleCreatedEventJSON() string {
return `
{
"domain": "release_bundle",
Expand All @@ -240,7 +240,7 @@ func ReleaseBundleCreatedEventJSON() string {
}`
}

func ReleaseBundleSignedEventJSON() string {
func releaseBundleSignedEventJSON() string {
return `
{
"domain": "release_bundle",
Expand All @@ -255,7 +255,7 @@ func ReleaseBundleSignedEventJSON() string {
}`
}

func ReleaseBundleDeletedEventJSON() string {
func releaseBundleDeletedEventJSON() string {
return `
{
"domain": "release_bundle",
Expand All @@ -270,7 +270,7 @@ func ReleaseBundleDeletedEventJSON() string {
}`
}

func DistributionStartedEventJSON() string {
func distributionStartedEventJSON() string {
return `
{
"domain": "distribution",
Expand All @@ -297,7 +297,7 @@ func DistributionStartedEventJSON() string {
}`
}

func DistributionCompletedEventJSON() string {
func distributionCompletedEventJSON() string {
return `
{
"domain": "distribution",
Expand All @@ -324,7 +324,7 @@ func DistributionCompletedEventJSON() string {
}`
}

func DistributionAbortedEventJSON() string {
func distributionAbortedEventJSON() string {
return `
{
"domain": "distribution",
Expand All @@ -351,7 +351,7 @@ func DistributionAbortedEventJSON() string {
}`
}

func DistributionFailedEventJSON() string {
func distributionFailedEventJSON() string {
return `
{
"domain": "distribution",
Expand All @@ -378,7 +378,7 @@ func DistributionFailedEventJSON() string {
}`
}

func DestinationReceivedEventJSON() string {
func destinationReceivedEventJSON() string {
return `
{
"domain": "destination",
Expand All @@ -393,7 +393,7 @@ func DestinationReceivedEventJSON() string {
}`
}

func DestinationDeleteStartedEventJSON() string {
func destinationDeleteStartedEventJSON() string {
return `
{
"domain": "destination",
Expand All @@ -408,7 +408,7 @@ func DestinationDeleteStartedEventJSON() string {
}`
}

func DestinationDeleteCompletedEventJSON() string {
func destinationDeleteCompletedEventJSON() string {
return `
{
"domain": "destination",
Expand All @@ -423,7 +423,7 @@ func DestinationDeleteCompletedEventJSON() string {
}`
}

func DestinationDeleteFailedEventJSON() string {
func destinationDeleteFailedEventJSON() string {
return `
{
"domain": "destination",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
const meas = "artifactory_webhooks"

type event interface {
NewMetric() telegraf.Metric
newMetric() telegraf.Metric
}

type artifactDeploymentOrDeletedEvent struct {
Expand All @@ -26,7 +26,7 @@ type artifactDeploymentOrDeletedEvent struct {
} `json:"data"`
}

func (e artifactDeploymentOrDeletedEvent) NewMetric() telegraf.Metric {
func (e artifactDeploymentOrDeletedEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -55,7 +55,7 @@ type artifactMovedOrCopiedEvent struct {
} `json:"data"`
}

func (e artifactMovedOrCopiedEvent) NewMetric() telegraf.Metric {
func (e artifactMovedOrCopiedEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -85,7 +85,7 @@ type artifactPropertiesEvent struct {
}
}

func (e artifactPropertiesEvent) NewMetric() telegraf.Metric {
func (e artifactPropertiesEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -120,7 +120,7 @@ type dockerEvent struct {
} `json:"data"`
}

func (e dockerEvent) NewMetric() telegraf.Metric {
func (e dockerEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -149,7 +149,7 @@ type buildEvent struct {
} `json:"data"`
}

func (e buildEvent) NewMetric() telegraf.Metric {
func (e buildEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand All @@ -175,7 +175,7 @@ type releaseBundleEvent struct {
JpdOrigin string `json:"jpd_origin"`
}

func (e releaseBundleEvent) NewMetric() telegraf.Metric {
func (e releaseBundleEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -209,7 +209,7 @@ type distributionEvent struct {
OriginURL string `json:"jpd_origin"`
}

func (e distributionEvent) NewMetric() telegraf.Metric {
func (e distributionEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down Expand Up @@ -239,7 +239,7 @@ type destinationEvent struct {
OriginURL string `json:"jpd_origin"`
}

func (e destinationEvent) NewMetric() telegraf.Metric {
func (e destinationEvent) newMetric() telegraf.Metric {
t := map[string]string{
"domain": e.Domain,
"event_type": e.Event,
Expand Down
Loading
Loading