diff --git a/Dockerfile b/Dockerfile index e4ebccd..3df70c2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM teamserverless/license-check:0.3.9 as license-check -FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.15 as build +FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.16 as build ARG GIT_COMMIT ARG VERSION diff --git a/Gopkg.lock b/Gopkg.lock deleted file mode 100644 index 137f1ff..0000000 --- a/Gopkg.lock +++ /dev/null @@ -1,63 +0,0 @@ -# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. - - -[[projects]] - digest = "1:bb89a2542933056fcebc2950bb15ec636e623cc43c96597288aa2009f15b0ce1" - name = "github.com/eclipse/paho.mqtt.golang" - packages = [ - ".", - "packets", - ] - pruneopts = "UT" - revision = "adca289fdcf8c883800aafa545bc263452290bae" - version = "v1.2.0" - -[[projects]] - digest = "1:f74e36b9c7f0fcf4d73483a71d873672ebc8a309c57c273af7e11f6f4e32654e" - name = "github.com/openfaas/connector-sdk" - packages = ["types"] - pruneopts = "UT" - revision = "193b73292e32864286853efeccbc5190b5d3c84d" - version = "0.5.3" - -[[projects]] - digest = "1:5ef12e7154e453638378dfc853ca53d2d775aee2d7a6da535df639d5933b39c7" - name = "github.com/openfaas/faas-provider" - packages = [ - "auth", - "types", - ] - pruneopts = "UT" - revision = "7677057e416ba796df41f9f366956a491c5684ff" - version = "0.13.2" - -[[projects]] - digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b" - name = "github.com/pkg/errors" - packages = ["."] - pruneopts = "UT" - revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4" - version = "v0.8.1" - -[[projects]] - branch = "master" - digest = "1:323d0eeaa3893e9f9cf6c11b11e3c5ce949b32d672b037e663b0e98de6f2d004" - name = "golang.org/x/net" - packages = [ - "internal/socks", - "proxy", - "websocket", - ] - pruneopts = "UT" - revision = "ef20fe5d793301b553005db740f730d87993f778" - -[solve-meta] - analyzer-name = "dep" - analyzer-version = 1 - input-imports = [ - "github.com/eclipse/paho.mqtt.golang", - "github.com/openfaas/connector-sdk/types", - "github.com/openfaas/faas-provider/auth", - ] - solver-name = "gps-cdcl" - solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml deleted file mode 100644 index ef2bfec..0000000 --- a/Gopkg.toml +++ /dev/null @@ -1,38 +0,0 @@ -# Gopkg.toml example -# -# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html -# for detailed Gopkg.toml documentation. -# -# required = ["github.com/user/thing/cmd/thing"] -# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] -# -# [[constraint]] -# name = "github.com/user/project" -# version = "1.0.0" -# -# [[constraint]] -# name = "github.com/user/project2" -# branch = "dev" -# source = "github.com/myfork/project2" -# -# [[override]] -# name = "github.com/x/y" -# version = "2.4.0" -# -# [prune] -# non-go = false -# go-tests = true -# unused-packages = true - - -[prune] - go-tests = true - unused-packages = true - -[[constraint]] - name = "github.com/gorilla/websocket" - version = "1.4.1" - -[[constraint]] - branch = "master" - name = "golang.org/x/net" diff --git a/go.mod b/go.mod index 33e22bb..4ce5285 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( github.com/eclipse/paho.mqtt.golang v1.2.0 - github.com/openfaas/connector-sdk v0.0.0-20201220114541-89f0ffcc5448 + github.com/openfaas/connector-sdk v0.6.1 github.com/openfaas/faas-provider v0.17.1 golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 // indirect ) diff --git a/go.sum b/go.sum index b304e5f..254aa94 100644 --- a/go.sum +++ b/go.sum @@ -7,6 +7,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/openfaas/connector-sdk v0.0.0-20201220114541-89f0ffcc5448 h1:gHh56/nHvUPTcFyXszTOrPJePCg2Q3JKln11G1IU3PU= github.com/openfaas/connector-sdk v0.0.0-20201220114541-89f0ffcc5448/go.mod h1:hxiCgJmfEWQj17jwnr8yj1qbxQAqRPcudKU53lIu/QI= +github.com/openfaas/connector-sdk v0.6.1 h1:nVhJFKSTrFSgKMcYKCeGPW4gsS64A/inmsUu40J6xso= +github.com/openfaas/connector-sdk v0.6.1/go.mod h1:hxiCgJmfEWQj17jwnr8yj1qbxQAqRPcudKU53lIu/QI= github.com/openfaas/faas-provider v0.16.1/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98= github.com/openfaas/faas-provider v0.17.1 h1:P5xTLN+/08PLLh4auIlO/PaUD/J3BUTmaC3en8N5zbs= github.com/openfaas/faas-provider v0.17.1/go.mod h1:fq1JL0mX4rNvVVvRLaLRJ3H6o667sHuyP5p/7SZEe98= diff --git a/main.go b/main.go index 480c920..5a21fd6 100644 --- a/main.go +++ b/main.go @@ -53,6 +53,11 @@ func main() { creds = types.GetCredentials() } + contentType := "application/json" + if v, exists := os.LookupEnv("content_type"); exists && len(v) > 0 { + contentType = v + } + gatewayURL := os.Getenv("gateway_url") if len(gatewayFlag) > 0 { @@ -71,6 +76,7 @@ func main() { PrintResponseBody: true, TopicAnnotationDelimiter: ",", AsyncFunctionInvocation: asyncInvoke, + ContentType: contentType, } log.Printf("Topic: %q\tBroker: %q\n", topic, broker) diff --git a/vendor/github.com/openfaas/connector-sdk/types/controller.go b/vendor/github.com/openfaas/connector-sdk/types/controller.go index 012e606..0b224c0 100644 --- a/vendor/github.com/openfaas/connector-sdk/types/controller.go +++ b/vendor/github.com/openfaas/connector-sdk/types/controller.go @@ -38,6 +38,10 @@ type ControllerConfig struct { // PrintSync indicates whether the sync should be logged. PrintSync bool + + // ContentType defines which content type will be set in the header to inkoke the function. i.e "application/json". + // Optional, if not set the Content-Type header will not be set. + ContentType string } // Controller is used to invoke functions on a per-topic basis and to subscribe to responses returned by said functions. @@ -79,6 +83,7 @@ func NewController(credentials *auth.BasicAuthCredentials, config *ControllerCon invoker := NewInvoker(gatewayFunctionPath, MakeClient(config.UpstreamTimeout), + config.ContentType, config.PrintResponse) subs := []ResponseSubscriber{} diff --git a/vendor/github.com/openfaas/connector-sdk/types/invoker.go b/vendor/github.com/openfaas/connector-sdk/types/invoker.go index 4653b11..f0efaac 100644 --- a/vendor/github.com/openfaas/connector-sdk/types/invoker.go +++ b/vendor/github.com/openfaas/connector-sdk/types/invoker.go @@ -21,6 +21,7 @@ type Invoker struct { PrintResponse bool Client *http.Client GatewayURL string + ContentType string Responses chan InvokerResponse } @@ -37,11 +38,12 @@ type InvokerResponse struct { } // NewInvoker constructs an Invoker instance -func NewInvoker(gatewayURL string, client *http.Client, printResponse bool) *Invoker { +func NewInvoker(gatewayURL string, client *http.Client, contentType string, printResponse bool) *Invoker { return &Invoker{ PrintResponse: printResponse, Client: client, GatewayURL: gatewayURL, + ContentType: contentType, Responses: make(chan InvokerResponse), } } @@ -67,7 +69,7 @@ func (i *Invoker) InvokeWithContext(ctx context.Context, topicMap *TopicMap, top gwURL := fmt.Sprintf("%s/%s", i.GatewayURL, matchedFunction) reader := bytes.NewReader(*message) - body, statusCode, header, doErr := invokefunction(ctx, i.Client, gwURL, reader) + body, statusCode, header, doErr := invokefunction(ctx, i.Client, gwURL, i.ContentType, reader) if doErr != nil { i.Responses <- InvokerResponse{ @@ -88,7 +90,7 @@ func (i *Invoker) InvokeWithContext(ctx context.Context, topicMap *TopicMap, top } } -func invokefunction(ctx context.Context, c *http.Client, gwURL string, reader io.Reader) (*[]byte, int, *http.Header, error) { +func invokefunction(ctx context.Context, c *http.Client, gwURL, contentType string, reader io.Reader) (*[]byte, int, *http.Header, error) { httpReq, err := http.NewRequest(http.MethodPost, gwURL, reader) if err != nil { @@ -100,6 +102,10 @@ func invokefunction(ctx context.Context, c *http.Client, gwURL string, reader io defer httpReq.Body.Close() } + if contentType != "" { + httpReq.Header.Set("Content-Type", contentType) + } + var body *[]byte res, doErr := c.Do(httpReq) diff --git a/vendor/modules.txt b/vendor/modules.txt index 8fbaf85..25fbc82 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2,7 +2,7 @@ ## explicit github.com/eclipse/paho.mqtt.golang github.com/eclipse/paho.mqtt.golang/packets -# github.com/openfaas/connector-sdk v0.0.0-20201220114541-89f0ffcc5448 +# github.com/openfaas/connector-sdk v0.6.1 ## explicit github.com/openfaas/connector-sdk/types # github.com/openfaas/faas-provider v0.17.1