diff --git a/gateway/Gopkg.lock b/gateway/Gopkg.lock index 92348a4b..e7801f71 100644 --- a/gateway/Gopkg.lock +++ b/gateway/Gopkg.lock @@ -75,8 +75,8 @@ [[projects]] name = "github.com/openfaas/nats-queue-worker" packages = ["handler"] - revision = "62e8dcfe87fc01de8b94156f3e4291370c0c84a8" - version = "0.4.6" + revision = "15287c9b2af293cee0c545ccc014a68e1f0a4424" + version = "0.4.7" [[projects]] name = "github.com/prometheus/client_golang" @@ -112,6 +112,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "181fb3c695e3b12e0a8e967135ef717ea83d9525c7c31b92f641d7a963d26254" + inputs-digest = "f6e74bc55788e9ad6ea33f02d2be398013705f4606c29bbead71ac41a3c19514" solver-name = "gps-cdcl" solver-version = 1 diff --git a/gateway/Gopkg.toml b/gateway/Gopkg.toml index 04b106f7..00b01084 100644 --- a/gateway/Gopkg.toml +++ b/gateway/Gopkg.toml @@ -14,7 +14,7 @@ ignored = ["github.com/openfaas/faas/gateway/queue"] [[constraint]] name = "github.com/openfaas/nats-queue-worker" - version = "0.4.5" + version = "0.4.7" [[constraint]] name = "github.com/prometheus/client_golang" diff --git a/gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml b/gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml index d4683af3..199e1e18 100644 --- a/gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml +++ b/gateway/vendor/github.com/openfaas/nats-queue-worker/.travis.yml @@ -17,7 +17,7 @@ install: - echo "Please don't go get" script: - - cd queue-worker && ./build.sh + - ./build.sh after_success: - if [ ! -z "$TRAVIS_TAG" ] ; then diff --git a/gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml b/gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml index e8532211..c690a8c7 100644 --- a/gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml +++ b/gateway/vendor/github.com/openfaas/nats-queue-worker/Gopkg.toml @@ -33,6 +33,10 @@ name = "github.com/openfaas/faas" version = "0.8.2" +[[constraint]] + name = "github.com/nats-io/go-nats" + version = "v1.5.0" + [prune] go-tests = true unused-packages = true diff --git a/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go b/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go index c34fc0ae..c5dac851 100644 --- a/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go +++ b/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go @@ -8,6 +8,7 @@ import ( "github.com/nats-io/go-nats-streaming" "github.com/openfaas/faas/gateway/queue" + "regexp" ) // NatsQueue queue for work @@ -22,9 +23,11 @@ type NatsConfig interface { type DefaultNatsConfig struct { } +var supportedCharacters, _ = regexp.Compile("[^a-zA-Z0-9-_]+") + func (DefaultNatsConfig) GetClientID() string { val, _ := os.Hostname() - return "faas-publisher-" + val + return getClientId(val) } // CreateNatsQueue ready for asynchronous processing @@ -58,3 +61,7 @@ func (q *NatsQueue) Queue(req *queue.Request) error { return err } + +func getClientId(hostname string) string { + return "faas-publisher-" + supportedCharacters.ReplaceAllString(hostname, "_") +} \ No newline at end of file diff --git a/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go b/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go index f1c3a972..c42ba370 100644 --- a/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go +++ b/gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go @@ -17,3 +17,23 @@ func Test_GetClientID_ContainsHostname(t *testing.T) { t.Fail() } } + +func TestCreateClientId(t *testing.T) { + clientId := getClientId("computer-a") + expected := "faas-publisher-computer-a" + if clientId != expected { + t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId) + t.Fail() + } +} + +func TestCreateClientIdWhenHostHasUnsupportedCharacters(t *testing.T) { + clientId := getClientId("computer-a.acme.com") + expected := "faas-publisher-computer-a_acme_com" + if clientId != expected { + t.Logf("Expected client id `%s` actual `%s`\n", expected, clientId) + t.Fail() + } +} + +