Example #1
0
// Creates a FilterRunner for the specified sandbox name and configuration.
func (this *SandboxManagerFilter) createRunner(dir, name string, configSection toml.Primitive) (
	pipeline.FilterRunner, error) {

	maker, err := pipeline.NewPluginMaker(name, this.pConfig, configSection)
	if err != nil {
		return nil, err
	}
	if maker.Type() != "SandboxFilter" {
		return nil, fmt.Errorf("Plugin must be a SandboxFilter, received %s",
			maker.Type())
	}

	// Customize the PrepConfig method so we can override any specified
	// settings with the manager's settings.
	mutMaker := maker.(pipeline.MutableMaker)
	prepConfig := func() (interface{}, error) {
		config, err := mutMaker.OrigPrepConfig()
		if err != nil {
			return nil, err
		}
		conf := config.(*SandboxConfig)
		conf.ScriptFilename = filepath.Join(dir, fmt.Sprintf("%s.%s", name, conf.ScriptType))
		conf.ModuleDirectory = this.moduleDirectory
		conf.MemoryLimit = this.memoryLimit
		conf.InstructionLimit = this.instructionLimit
		conf.OutputLimit = this.outputLimit
		conf.PluginType = "filter"
		return conf, nil
	}
	mutMaker.SetPrepConfig(prepConfig)

	// Finally call MakeRunner() to initialize the plugin and create the
	// runner.
	runner, err := mutMaker.MakeRunner(name)
	if err != nil {
		return nil, err
	}
	sbxFilter := runner.Plugin().(*SandboxFilter)
	sbxFilter.manager = this
	return runner.(pipeline.FilterRunner), nil
}
Example #2
0
// Creates a FilterRunner for the specified sandbox name and configuration.
func (this *SandboxManagerFilter) createRunner(dir, name string, configSection toml.Primitive) (
	pipeline.FilterRunner, error) {

	maker, err := pipeline.NewPluginMaker(name, this.pConfig, configSection)
	if err != nil {
		return nil, err
	}
	if maker.Type() != "SandboxFilter" {
		return nil, fmt.Errorf("Plugin must be a SandboxFilter, received %s",
			maker.Type())
	}

	// First load the config that the user specified into the filter's config
	// struct.
	if err = maker.PrepConfig(); err != nil {
		return nil, fmt.Errorf("Error prepping config: %s", err.Error())
	}
	// Then override some of the user provided settings with the manager
	// settings.
	mutMaker := maker.(pipeline.MutableMaker)
	conf := mutMaker.Config().(*SandboxConfig)
	conf.ScriptFilename = filepath.Join(dir, fmt.Sprintf("%s.%s", name, conf.ScriptType))
	conf.ModuleDirectory = this.moduleDirectory
	conf.MemoryLimit = this.memoryLimit
	conf.InstructionLimit = this.instructionLimit
	conf.OutputLimit = this.outputLimit
	conf.PluginType = "filter"
	mutMaker.SetConfig(conf)

	// Finally call MakeRunner() to initialize the plugin and create the
	// runner.
	runner, err := mutMaker.MakeRunner(name)
	if err != nil {
		return nil, err
	}
	sbxFilter := runner.Plugin().(*SandboxFilter)
	sbxFilter.manager = this
	return runner.(pipeline.FilterRunner), nil
}