plugin

package
v0.0.0-...-ee3d319 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 16, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// These PageScope constants determine which page a panel hooks into
	TaskPage    PageScope = "task"
	BuildPage   PageScope = "build"
	VersionPage PageScope = "version"

	// These pagePosition constants determine where on a page a panel is
	// injected. If no position is given, it defaults to PageCenter
	PageLeft   pagePosition = "Left"
	PageRight  pagePosition = "Right"
	PageCenter pagePosition = "Center"
)

Variables

View Source
var (
	// These are slices of all plugins that have made themselves
	// visible to the Evergreen system. A Plugin can add itself by appending an instance
	// of itself to these slices on init, i.e. by adding the following to its
	// source file:
	//  func init(){
	//	plugin.Publish(&MyCoolPlugin{})
	//  }
	// This list is then used by Agent, API, and UI Server code to register
	// the published plugins.
	UIPlugins []UIPlugin
)

Functions

func GetTask

func GetTask(r *http.Request) *task.Task

GetTask returns the task object for a plugin API request at runtime, it is a valuable helper function for API PluginRoute handlers.

func GetUser

func GetUser(r *http.Request) *user.DBUser

GetUser fetches the user, if it exists, from the request context.

func Publish

func Publish(plugin Plugin)

Publish is called in a plugin's "init" func to announce that plugin's presence to the entire plugin package. This architecture is designed to make it easy to add new external plugin code to Evergreen by simply importing the new plugin's package in plugin/config/installed_plugins.go

Packages implementing the Plugin interface MUST call Publish in their init code in order for Evergreen to detect and use them. A plugin must also implement one of CommandPlugin or UIPlugin in order to be useable.

See the documentation of the 10gen.com/mci/plugin/config package for more

func SetTask

func SetTask(r *http.Request, task *task.Task) *http.Request

SetTask puts the task for an API request into the context of a request. This task can be retrieved in a handler function by using "GetTask()"

func SetUser

func SetUser(u *user.DBUser, r *http.Request) *http.Request

SetUser sets the user for the request context. This is a helper for UI middleware.

func TemplateRoot

func TemplateRoot(name string) string

Types

type AppUIPlugin

type AppUIPlugin interface {
	UIPlugin

	// GetAppPluginInfo returns all the information
	// needed for the UI server to render a page from the navigation bar.
	GetAppPluginInfo() *UIPage
}

AppUIPlugin represents a UIPlugin that also has a page route.

type PageScope

type PageScope string

PageScope is a type for setting the page a panel appears on

type PanelConfig

type PanelConfig struct {
	// Handler is an http.Handler which receives plugin-specific HTTP requests from the UI
	Handler http.Handler

	// Panels is an array of UIPanels to inject into task, version,
	// and build pages
	Panels []UIPanel
}

PanelConfig stores all UI-related plugin hooks

type PanelLayout

type PanelLayout struct {
	Left   []template.HTML
	Right  []template.HTML
	Center []template.HTML
}

PanelLayout tells the view renderer what panel HTML data to inject and where on the page to inject it.

type PanelManager

type PanelManager interface {
	RegisterPlugins([]UIPlugin) error
	Includes(PageScope) ([]template.HTML, error)
	Panels(PageScope) (PanelLayout, error)
	UIData(UIContext, PageScope) (map[string]interface{}, error)
	GetAppPlugins() []AppUIPlugin
}

PanelManager is the manager the UI server uses to register and load plugin UI information efficiently.

type Plugin

type Plugin interface {
	// Returns the name to identify this plugin when registered.
	Name() string
}

Plugin defines the interface that all evergreen plugins must implement in order to register themselves with Evergreen. A plugin must also implement one of the PluginCommand or UIPlugin interfaces in order to do useful work.

type SimplePanelManager

type SimplePanelManager struct {
	// contains filtered or unexported fields
}

SimplePanelManager is a basic implementation of a plugin panel manager.

func (*SimplePanelManager) GetAppPlugins

func (self *SimplePanelManager) GetAppPlugins() []AppUIPlugin

func (*SimplePanelManager) Includes

func (self *SimplePanelManager) Includes(page PageScope) ([]template.HTML, error)

Includes returns a properly-ordered list of html tags to inject into the head of the view for the given page.

func (*SimplePanelManager) Panels

func (self *SimplePanelManager) Panels(page PageScope) (PanelLayout, error)

Panels returns a PanelLayout for the view renderer to inject panels into the given page.

func (*SimplePanelManager) RegisterPlugins

func (self *SimplePanelManager) RegisterPlugins(plugins []UIPlugin) error

RegisterPlugins takes an array of plugins and registers them with the manager. After this step is done, the other manager functions may be used.

func (*SimplePanelManager) UIData

func (self *SimplePanelManager) UIData(context UIContext, page PageScope) (map[string]interface{}, error)

UIData returns a map of plugin name -> data for inclusion in the view's javascript.

type UIContext

type UIContext struct {
	Settings   evergreen.Settings
	User       *user.DBUser
	Task       *task.Task
	Build      *build.Build
	Version    *version.Version
	Patch      *patch.Patch
	ProjectRef *model.ProjectRef
	Request    *http.Request
}

UIContext stores all relevant models for a plugin page.

type UIDataFunction

type UIDataFunction func(context UIContext) (interface{}, error)

UIDataFunction is a function which is called to populate panels which are injected into Task/Build/Version pages at runtime.

type UIDataFunctionError

type UIDataFunctionError []error

UIDataFunctionError is a special error type for data function processing which can record and aggregate multiple error messages.

func (*UIDataFunctionError) AppendError

func (errs *UIDataFunctionError) AppendError(name string, err error)

AppendError adds an error onto the array of data function errors.

func (*UIDataFunctionError) Error

func (errs *UIDataFunctionError) Error() string

Error returns a string aggregating the stored error messages. Implements the error interface.

func (*UIDataFunctionError) HasErrors

func (errs *UIDataFunctionError) HasErrors() bool

HasErrors returns a boolean representing if the UIDataFunctionError contains any errors.

type UIPage

type UIPage struct {
	TemplatePath string
	DataFunc     UIDataFunction
}

UIPage represents the information to be sent over to the ui server in order to render a page for an app level plugin. TemplatePath is the relative path to the template from the template root of the plugin. Data represents the data to send over.

type UIPanel

type UIPanel struct {
	// Page is which page the panel appears on
	Page PageScope

	// Includes is a list of HTML tags to inject into the head of
	// the page. These are meant to be links to css and js code hosted
	// in the plugin's static web root
	Includes []template.HTML

	// PanelHTML is the HTML definition of the panel. Best practices dictate
	// using AngularJS to load up the html as a partial hosted by the plugin
	PanelHTML template.HTML

	// DataFunc is a function to populate plugin data injected into the js
	// of the page the panel is on. The function takes the page request as
	// an argument, and returns data (must be json-serializeable!) or an error
	DataFunc UIDataFunction
	// Position is the side of the page the panel appears in
	Position pagePosition
}

UIPanel is a type for storing all the configuration to properly display one panel in one page of the UI.

type UIPlugin

type UIPlugin interface {
	Plugin

	// Install any server-side handlers needed by this plugin in the UI server
	GetUIHandler() http.Handler

	// GetPanelConfig returns a pointer to a plugin's UI configuration.
	// or an error, if an error occur while trying to generate the config
	// A nil pointer represents a plugin without a UI presence, and is
	// not an error.
	GetPanelConfig() (*PanelConfig, error)

	// Configure reads in a settings map from the Evergreen config file.
	Configure(conf map[string]interface{}) error
}

Directories

Path Synopsis
builtin
The plugin/config package is used to manage which plugins are imported into MCI.
The plugin/config package is used to manage which plugins are imported into MCI.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL