Add ability to disable script runner calls
With script runner disabled, all critical scripts would fail
This commit is contained in:
@@ -49,13 +49,18 @@ type (
|
||||
)
|
||||
|
||||
// @todo move to opt so all services can use it
|
||||
func ScriptRunner(c options.ScriptRunnerOpt) (*scriptRunner, error) {
|
||||
var svc = &scriptRunner{
|
||||
func ScriptRunner(c options.ScriptRunnerOpt) (svc *scriptRunner, err error) {
|
||||
svc = &scriptRunner{
|
||||
c: c,
|
||||
logger: DefaultLogger.Named("script-runner"),
|
||||
jwtEncoder: auth.DefaultJwtHandler,
|
||||
}
|
||||
|
||||
if !c.Enabled {
|
||||
// Do not connect when script runner is not enabled
|
||||
return
|
||||
}
|
||||
|
||||
return svc, svc.connect()
|
||||
}
|
||||
|
||||
@@ -128,6 +133,20 @@ func (svc scriptRunner) Record(ctx context.Context, s Runnable, ns *types.Namesp
|
||||
return nil, errors.New("module not provided")
|
||||
}
|
||||
|
||||
if !svc.c.Enabled {
|
||||
if s.IsCritical() {
|
||||
// Oh dear, we are in quite a pickle:
|
||||
// Script runner is disabled but we have critical script to run
|
||||
return nil, errors.New("script runner disabled")
|
||||
}
|
||||
|
||||
// Log this
|
||||
svc.logger.Debug("executing script", zap.Any("record", r))
|
||||
|
||||
// and pretend like nothing happened
|
||||
return r, nil
|
||||
}
|
||||
|
||||
svc.logger.Debug("executing script", zap.Any("record", r))
|
||||
|
||||
ctx, cancelFn := context.WithTimeout(ctx, time.Second*5)
|
||||
|
||||
Reference in New Issue
Block a user