MM-16261 - Store Plugin in File Store (#11511)

* Implemneted saving the plugin bundle on the file store upon plugin upload

* Fixed compilation error

* Fixed compilation issue

* Added deletion from file store upon plugin uninstall

* Added condition to delete from store only when exists. Added case of saving the bundle to the store when uploading from url. Added checks in plugin tests

* Fixed compilation error

* Moved storage of plugin bundle within app/installPlugin

* Moved storing to filestore before enabling the plugin

* Fixed error handling

* Code styling improvements

* Minor styling fix
Этот коммит содержится в:
Maria A Nunez
2019-07-10 16:05:33 -04:00
коммит произвёл Jesse Hallam
родитель b464f31b38
Коммит 859c571558
4 изменённых файлов: 55 добавлений и 4 удалений

Просмотреть файл

@@ -17,11 +17,11 @@ import (
)
// InstallPlugin unpacks and installs a plugin but does not enable or activate it.
func (a *App) InstallPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
func (a *App) InstallPlugin(pluginFile io.ReadSeeker, replace bool) (*model.Manifest, *model.AppError) {
return a.installPlugin(pluginFile, replace)
}
func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) {
func (a *App) installPlugin(pluginFile io.ReadSeeker, replace bool) (*model.Manifest, *model.AppError) {
pluginsEnvironment := a.GetPluginsEnvironment()
if pluginsEnvironment == nil {
return nil, model.NewAppError("installPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented)
@@ -83,6 +83,14 @@ func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest
return nil, model.NewAppError("installPlugin", "app.plugin.mvdir.app_error", nil, err.Error(), http.StatusInternalServerError)
}
// Store bundle in the file store to allow access from other servers.
pluginFile.Seek(0, 0)
storePluginFileName := filepath.Join("./plugins", manifest.Id) + ".tar.gz"
if _, err := a.WriteFile(pluginFile, storePluginFileName); err != nil {
return nil, model.NewAppError("uploadPlugin", "app.plugin.store_bundle.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if stashed != nil && stashed.Enable {
a.EnablePlugin(manifest.Id)
}
@@ -138,5 +146,18 @@ func (a *App) removePlugin(id string) *model.AppError {
return model.NewAppError("removePlugin", "app.plugin.remove.app_error", nil, err.Error(), http.StatusInternalServerError)
}
// Remove bundle from the file store.
storePluginFileName := filepath.Join("./plugins", manifest.Id) + ".tar.gz"
bundleExist, fileErr := a.FileExists(storePluginFileName)
if fileErr != nil {
return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError)
}
if bundleExist {
if err := a.RemoveFile(storePluginFileName); err != nil {
return model.NewAppError("removePlugin", "app.plugin.remove_bundle.app_error", nil, err.Error(), http.StatusInternalServerError)
}
}
return nil
}