Skip to content
Open
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
12 changes: 12 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"os"
"strconv"
"time"

"github.com/openfaas/connector-sdk/types"
Expand Down Expand Up @@ -40,6 +41,16 @@ func getControllerConfig() (*types.ControllerConfig, error) {
rebuildInterval = d
}

var basicAuth bool
if val, exists := os.LookupEnv("basic_auth"); exists {
a, err := strconv.ParseBool(val)
if err != nil {
return nil, err
}

basicAuth = a
}

return &types.ControllerConfig{
RebuildInterval: rebuildInterval,
GatewayURL: gURL,
Expand All @@ -48,5 +59,6 @@ func getControllerConfig() (*types.ControllerConfig, error) {
PrintResponse: true,
PrintResponseBody: printResponseBody,
PrintRequestBody: false,
BasicAuth: basicAuth,
}, nil
}
22 changes: 18 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,27 @@ func (auth *BasicAuth) Set(req *http.Request) error {
return nil
}

// NoAuth auth to when basic auth is disabled
type NoAuth struct {
}

// Set authorization header or request
func (auth *NoAuth) Set(req *http.Request) error {
return nil
}

func startFunctionProbe(interval time.Duration, probeTimeout time.Duration, topic string, c *types.ControllerConfig, cronScheduler *crontypes.Scheduler, invoker *types.Invoker) error {
runningFuncs := make(crontypes.ScheduledFunctions, 0)

creds := types.GetCredentials()
auth := &BasicAuth{
Username: creds.User,
Password: creds.Password,
var auth sdk.ClientAuth
if c.BasicAuth {
creds := types.GetCredentials()
auth = &BasicAuth{
Username: creds.User,
Password: creds.Password,
}
} else {
auth = &NoAuth{}
}

sdkClient, err := sdk.NewClient(auth, c.GatewayURL, nil, &probeTimeout)
Expand Down