Refactor exec plugin load to error if plugin isn't executable

This commit is contained in:
Dominykas Djacenko
2019-10-20 17:07:04 -07:00
parent 9f8faa7d7e
commit a4784ee5ec
3 changed files with 29 additions and 17 deletions

View File

@@ -44,8 +44,15 @@ type ExecPlugin struct {
h *resmap.PluginHelpers
}
func NewExecPlugin(p string) *ExecPlugin {
return &ExecPlugin{path: p}
func NewExecPlugin(p string) (*ExecPlugin, error) {
f, err := os.Stat(p)
if err != nil {
return nil, err
}
if f.Mode()&0111 == 0000 {
return nil, fmt.Errorf("unable to execute plugin on path: %s", p)
}
return &ExecPlugin{path: p}, nil
}
func (p *ExecPlugin) Path() string {
@@ -60,15 +67,6 @@ func (p *ExecPlugin) Cfg() []byte {
return p.cfg
}
// isAvailable checks to see if the plugin is available
func (p *ExecPlugin) IsAvailable() bool {
f, err := os.Stat(p.path)
if os.IsNotExist(err) {
return false
}
return f.Mode()&0111 != 0000
}
func (p *ExecPlugin) Config(h *resmap.PluginHelpers, config []byte) error {
p.h = h
p.cfg = config