github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/plugin/rpcplugin/sandbox/supervisor.go (about)

     1  // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package sandbox
     5  
     6  import (
     7  	"context"
     8  	"fmt"
     9  	"io"
    10  	"path/filepath"
    11  	"strings"
    12  
    13  	"github.com/mattermost/mattermost-server/model"
    14  	"github.com/mattermost/mattermost-server/plugin"
    15  	"github.com/mattermost/mattermost-server/plugin/rpcplugin"
    16  )
    17  
    18  func SupervisorProvider(bundle *model.BundleInfo) (plugin.Supervisor, error) {
    19  	return rpcplugin.SupervisorWithNewProcessFunc(bundle, func(ctx context.Context) (rpcplugin.Process, io.ReadWriteCloser, error) {
    20  		executable := filepath.Clean(filepath.Join(".", bundle.Manifest.Backend.Executable))
    21  		if strings.HasPrefix(executable, "..") {
    22  			return nil, nil, fmt.Errorf("invalid backend executable")
    23  		}
    24  		return NewProcess(ctx, &Configuration{
    25  			MountPoints: []*MountPoint{{
    26  				Source:      bundle.Path,
    27  				Destination: "/plugin",
    28  				ReadOnly:    true,
    29  			}},
    30  			WorkingDirectory: "/plugin",
    31  		}, filepath.Join("/plugin", executable))
    32  	})
    33  }