Skip to content

Commit

Permalink
Set openfaas env variables with local-run
Browse files Browse the repository at this point in the history
Set env variables that are normally injects by the provider like,
'OPENFAAS_NAME' and 'OPENFAAS_NAMESPACE' when running function with
local-run.

This change makes it possible to use built-in function authentication
with local-run. The 'jwt_auth_local' env variable is to true by default
to help with this.

Signed-off-by: Han Verstraete (OpenFaaS Ltd) <han@openfaas.com>
  • Loading branch information
welteki authored and alexellis committed Jun 19, 2024
1 parent e07d8db commit 3fd37fb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion commands/local_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,21 @@ func runFunction(ctx context.Context, name string, opts runOptions, args []strin
// Always try to remove before running, to clear up any previous state
removeContainer(name)

cmd, err := buildDockerRun(ctx, name, services.Functions[name], opts)
function := services.Functions[name]

functionNamespace = function.Namespace
if len(functionNamespace) == 0 {
functionNamespace = "openfaas-fn"
}

// Add openfaas env variables that are normally injected by the provider.
opts.extraEnv["OPENFAAS_NAME"] = name
opts.extraEnv["OPENFAAS_NAMESPACE"] = functionNamespace

// Enable local jwt auth by default
opts.extraEnv["jwt_auth_local"] = "true"

cmd, err := buildDockerRun(ctx, name, function, opts)
if err != nil {
return err
}
Expand Down

0 comments on commit 3fd37fb

Please sign in to comment.