Skip to content

Commit 3fd37fb

Browse files
weltekialexellis
authored andcommitted
Set openfaas env variables with local-run
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) <[email protected]>
1 parent e07d8db commit 3fd37fb

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

commands/local_run.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,21 @@ func runFunction(ctx context.Context, name string, opts runOptions, args []strin
195195
// Always try to remove before running, to clear up any previous state
196196
removeContainer(name)
197197

198-
cmd, err := buildDockerRun(ctx, name, services.Functions[name], opts)
198+
function := services.Functions[name]
199+
200+
functionNamespace = function.Namespace
201+
if len(functionNamespace) == 0 {
202+
functionNamespace = "openfaas-fn"
203+
}
204+
205+
// Add openfaas env variables that are normally injected by the provider.
206+
opts.extraEnv["OPENFAAS_NAME"] = name
207+
opts.extraEnv["OPENFAAS_NAMESPACE"] = functionNamespace
208+
209+
// Enable local jwt auth by default
210+
opts.extraEnv["jwt_auth_local"] = "true"
211+
212+
cmd, err := buildDockerRun(ctx, name, function, opts)
199213
if err != nil {
200214
return err
201215
}

0 commit comments

Comments
 (0)