openfaas / nats-queue-worker

Queue-worker for OpenFaaS with NATS Streaming
https://docs.openfaas.com/reference/async/
MIT License
128 stars 59 forks source link

Fix basic auth for async report #117

Closed welteki closed 2 years ago

welteki commented 2 years ago

Solves edge case where basic auth fails for function statistics post back to the gateway when the basic_auth env variable is set to “1”.

Description

Use config.BasicAuth instead of checking the env_var in the postReport function.

Motivation and Context

How Has This Been Tested?

Installed openfaas using kind and arkade. Updated the queue-worker deployment.

kubectl edit deploy/queue-worker -n openfaas

changes:

template:
  spec:
    containers:
    - env:
      - name: gateway_invoke
        value: "false"
      - name: basic_auth
        value: "1"
      image: welteki/queue-worker:async-report

Deployed figlet from the store and invoked it async. Logs for the queue-worker:

[#1] Received on [faas-request]: 'sequence:1 subject:"faas-request" data:"{\"Header\":{\"Accept-Encoding\":[\"gzip\"],\"Content-Length\":[\"6\"],\"Content-Type\":[\"text/plain\"],\"User-Agent\":[\"Go-http-client/1.1\"],\"X-Call-Id\":[\"9a9c9817-6436-47a3-8329-40023db9a14e\"],\"X-Start-Time\":[\"1643187927333584634\"]},\"Host\":\"127.0.0.1:8080\",\"Body\":\"YXN5bmMK\",\"Method\":\"POST\",\"Path\":\"\",\"QueryString\":\"\",\"Function\":\"figlet\",\"QueueName\":\"\",\"CallbackUrl\":null}" timestamp:1643187927345634173 '
[#1] Invoking: figlet with 6 bytes, via: http://figlet.openfaas-fn.svc.cluster.local:8080/
[#1] Invoked: figlet [200] in 0.198375s
[#1] figlet returned 174 bytes
[#1] Posting report for figlet, status: 202

Types of changes

Checklist: