Module "os" is no longer needed since Risor comes with an "os" and "exec" module out of the box now.
27 lines
592 B
Go
27 lines
592 B
Go
package scriptmanager
|
|
|
|
import (
|
|
"context"
|
|
"github.com/risor-io/risor/limits"
|
|
)
|
|
|
|
// scriptEnv is the runtime environment for a particular script execution
|
|
type scriptEnv struct {
|
|
filename string
|
|
}
|
|
|
|
type scriptEnvKeyType struct{}
|
|
|
|
var scriptEnvKey = scriptEnvKeyType{}
|
|
|
|
func scriptEnvFromCtx(ctx context.Context) scriptEnv {
|
|
perms, _ := ctx.Value(scriptEnvKey).(scriptEnv)
|
|
return perms
|
|
}
|
|
|
|
func ctxWithScriptEnv(ctx context.Context, perms scriptEnv) context.Context {
|
|
newCtx := context.WithValue(ctx, scriptEnvKey, perms)
|
|
newCtx = limits.WithLimits(newCtx, limits.New())
|
|
return newCtx
|
|
}
|