From 98e1231fcc6f12eedad2d5fd7a28bf9d349dd853 Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 7 Mar 2018 13:53:07 -0600 Subject: respect plugin manifest webapp bundle_path (#8393) --- plugin/pluginenv/environment.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'plugin') diff --git a/plugin/pluginenv/environment.go b/plugin/pluginenv/environment.go index f53021f74..adc9ddbde 100644 --- a/plugin/pluginenv/environment.go +++ b/plugin/pluginenv/environment.go @@ -8,6 +8,7 @@ import ( "fmt" "io/ioutil" "net/http" + "path/filepath" "sync" "github.com/pkg/errors" @@ -163,12 +164,24 @@ func (env *Environment) ActivatePlugin(id string) error { return fmt.Errorf("env missing webapp path, cannot activate plugin: %v", id) } - webappBundle, err := ioutil.ReadFile(fmt.Sprintf("%s/%s/webapp/%s_bundle.js", env.searchPath, id, id)) + bundlePath := filepath.Clean(bundle.Manifest.Webapp.BundlePath) + if bundlePath == "" || bundlePath[0] == '.' { + return fmt.Errorf("invalid webapp bundle path") + } + bundlePath = filepath.Join(env.searchPath, id, bundlePath) + + webappBundle, err := ioutil.ReadFile(bundlePath) if err != nil { - if supervisor != nil { - supervisor.Stop() + // Backwards compatibility for plugins where webapp.bundle_path was ignored. This should + // be removed eventually. + if webappBundle2, err2 := ioutil.ReadFile(fmt.Sprintf("%s/%s/webapp/%s_bundle.js", env.searchPath, id, id)); err2 == nil { + webappBundle = webappBundle2 + } else { + if supervisor != nil { + supervisor.Stop() + } + return errors.Wrapf(err, "unable to read webapp bundle: %v", id) } - return errors.Wrapf(err, "unable to read webapp bundle: %v", id) } err = ioutil.WriteFile(fmt.Sprintf("%s/%s_bundle.js", env.webappPath, id), webappBundle, 0644) -- cgit v1.2.3-1-g7c22