Skip to content

Commit

Permalink
Fix noctx lint
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Aug 2, 2023
1 parent 725e8ba commit ecac754
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
5 changes: 3 additions & 2 deletions internal/handlers/active-directory-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package handlers

import (
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -237,6 +238,6 @@ func (d *activeDirectoryDeploymentToSNowDeliverer) PluginTypeID() string {
return "active-directory-deployment-to-servicenow.v1"
}

func (d *activeDirectoryDeploymentToSNowDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
return d.Client.DeliverChangePayload(payload)
func (d *activeDirectoryDeploymentToSNowDeliverer) DeliverPayload(ctx context.Context, payload []byte) (*tenso.DeliveryLog, error) {
return d.Client.DeliverChangePayload(ctx, payload)
}
7 changes: 4 additions & 3 deletions internal/handlers/awx-workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package handlers

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -180,7 +181,7 @@ func (a *awxWorkflowToSwiftDeliverer) PluginTypeID() string {
return "infra-workflow-to-swift.v1"
}

func (a *awxWorkflowToSwiftDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
func (a *awxWorkflowToSwiftDeliverer) DeliverPayload(_ context.Context, payload []byte) (*tenso.DeliveryLog, error) {
event, err := jsonUnmarshalStrict[awxWorkflowEvent](payload)
if err != nil {
return nil, err
Expand Down Expand Up @@ -263,10 +264,10 @@ func (a *awxWorkflowToSNowDeliverer) PluginTypeID() string {
return "infra-workflow-to-servicenow.v1"
}

func (a *awxWorkflowToSNowDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
func (a *awxWorkflowToSNowDeliverer) DeliverPayload(ctx context.Context, payload []byte) (*tenso.DeliveryLog, error) {
//if the TranslationHandler wants us to ignore this payload, skip the delivery
if string(payload) == "skip" {
return nil, nil
}
return a.Client.DeliverChangePayload(payload)
return a.Client.DeliverChangePayload(ctx, payload)
}
9 changes: 5 additions & 4 deletions internal/handlers/helm-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package handlers

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -152,7 +153,7 @@ func (h *helmDeploymentToElkDeliverer) PluginTypeID() string {
return "helm-deployment-to-elk.v1"
}

func (h *helmDeploymentToElkDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
func (h *helmDeploymentToElkDeliverer) DeliverPayload(_ context.Context, payload []byte) (*tenso.DeliveryLog, error) {
//Logstash wants everything on one line, so ensure we don't have unnecessary whitespace in the payload
var buf bytes.Buffer
err := json.Compact(&buf, payload)
Expand Down Expand Up @@ -193,7 +194,7 @@ func (h *helmDeploymentToSwiftDeliverer) PluginTypeID() string {
return "helm-deployment-to-swift.v1"
}

func (h *helmDeploymentToSwiftDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
func (h *helmDeploymentToSwiftDeliverer) DeliverPayload(_ context.Context, payload []byte) (*tenso.DeliveryLog, error) {
event, err := jsonUnmarshalStrict[deployevent.Event](payload)
if err != nil {
return nil, err
Expand Down Expand Up @@ -261,6 +262,6 @@ func (h *helmDeploymentToSNowDeliverer) PluginTypeID() string {
return "helm-deployment-to-servicenow.v1"
}

func (h *helmDeploymentToSNowDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
return h.Client.DeliverChangePayload(payload)
func (h *helmDeploymentToSNowDeliverer) DeliverPayload(ctx context.Context, payload []byte) (*tenso.DeliveryLog, error) {
return h.Client.DeliverChangePayload(ctx, payload)
}
7 changes: 4 additions & 3 deletions internal/handlers/terraform-deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package handlers

import (
"bytes"
"context"
"errors"
"fmt"
"sort"
Expand Down Expand Up @@ -134,7 +135,7 @@ func (h *terraformDeploymentToSwiftDeliverer) PluginTypeID() string {
return "terraform-deployment-to-swift.v1"
}

func (h *terraformDeploymentToSwiftDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
func (h *terraformDeploymentToSwiftDeliverer) DeliverPayload(_ context.Context, payload []byte) (*tenso.DeliveryLog, error) {
event, err := jsonUnmarshalStrict[deployevent.Event](payload)
if err != nil {
return nil, err
Expand Down Expand Up @@ -242,6 +243,6 @@ func (d *terraformDeploymentToSNowDeliverer) PluginTypeID() string {
return "terraform-deployment-to-servicenow.v1"
}

func (d *terraformDeploymentToSNowDeliverer) DeliverPayload(payload []byte) (*tenso.DeliveryLog, error) {
return d.Client.DeliverChangePayload(payload)
func (d *terraformDeploymentToSNowDeliverer) DeliverPayload(ctx context.Context, payload []byte) (*tenso.DeliveryLog, error) {
return d.Client.DeliverChangePayload(ctx, payload)
}
5 changes: 3 additions & 2 deletions internal/servicenow/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package servicenow

import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -85,13 +86,13 @@ func NewClientFromEnv(envPrefix string) (*Client, error) {
// DeliverChangePayload delivers a change payload to ServiceNow. This function
// has the same interface as DeliverPayload() in the tenso.DeliveryHandler
// interface.
func (c *Client) DeliverChangePayload(payload []byte) (*tenso.DeliveryLog, error) {
func (c *Client) DeliverChangePayload(ctx context.Context, payload []byte) (*tenso.DeliveryLog, error) {
//if the TranslationHandler wants us to ignore this payload, skip the delivery
if string(payload) == "skip" {
return nil, nil
}

req, err := http.NewRequest(http.MethodPost, c.EndpointURL, bytes.NewReader(payload))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, c.EndpointURL, bytes.NewReader(payload))
if err != nil {
return nil, fmt.Errorf("while preparing request for POST %s: %w", c.EndpointURL, err)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tasks/deliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (c *Context) DeliveryJob(registerer prometheus.Registerer) jobloop.Job {
}).Setup(registerer)
}

func (c *Context) processDelivery(_ context.Context, tx *gorp.Transaction, pd tenso.PendingDelivery, labels prometheus.Labels) (returnedError error) {
func (c *Context) processDelivery(ctx context.Context, tx *gorp.Transaction, pd tenso.PendingDelivery, labels prometheus.Labels) (returnedError error) {
var event tenso.Event

labels["payload_type"] = pd.PayloadType
Expand Down Expand Up @@ -98,7 +98,7 @@ func (c *Context) processDelivery(_ context.Context, tx *gorp.Transaction, pd te
}

//try to translate the payload, or set up a delayed retry on failure
dlog, err := dh.DeliverPayload([]byte(*pd.Payload))
dlog, err := dh.DeliverPayload(ctx, []byte(*pd.Payload))
if err != nil {
pd.NextDeliveryAt = c.timeNow().Add(DeliveryRetryInterval)
pd.FailedDeliveryCount++
Expand Down
3 changes: 2 additions & 1 deletion internal/tenso/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package tenso

import (
"context"
"fmt"
"strings"

Expand Down Expand Up @@ -94,7 +95,7 @@ type DeliveryHandler interface {
//talk to OpenStack. During unit tests, (nil, nil) will be provided instead.
Init(pc *gophercloud.ProviderClient, eo gophercloud.EndpointOpts) error

DeliverPayload(payload []byte) (*DeliveryLog, error)
DeliverPayload(ctx context.Context, payload []byte) (*DeliveryLog, error)
}

// DeliveryLog can be returned by DeliverPayload() to produce additional log
Expand Down
3 changes: 2 additions & 1 deletion internal/test/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package test

import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -115,7 +116,7 @@ func (h *testDeliveryHandler) PluginTypeID() string {
return fmt.Sprintf("test-%s.v1", h.Type)
}

func (h *testDeliveryHandler) DeliverPayload(data []byte) (*tenso.DeliveryLog, error) {
func (h *testDeliveryHandler) DeliverPayload(_ context.Context, data []byte) (*tenso.DeliveryLog, error) {
//We don't actually deliver anywhere, but by giving us an invalid payload, tests can "simulate" a delivery failure.
_, err := parseTestPayload(data, h.Type)
if err != nil {
Expand Down

0 comments on commit ecac754

Please sign in to comment.