From 1e5c432e1029601a664454388ae366ef69618d62 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 25 Jun 2018 12:33:13 -0700 Subject: MM-10702 Moving plugins to use hashicorp go-plugin. (#8978) * Moving plugins to use hashicorp go-plugin. * Tweaks from feedback. --- plugin/hooks.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'plugin/hooks.go') diff --git a/plugin/hooks.go b/plugin/hooks.go index e41081e48..68eca8ede 100644 --- a/plugin/hooks.go +++ b/plugin/hooks.go @@ -9,15 +9,32 @@ import ( "github.com/mattermost/mattermost-server/model" ) +// These assignments are part of the wire protocol. You can add more, but should not change existing +// assignments. Follow the naming convention of Id as the autogenerated glue code depends on that. +const ( + OnActivateId = 0 + OnDeactivateId = 1 + ServeHTTPId = 2 + OnConfigurationChangeId = 3 + ExecuteCommandId = 4 + MessageWillBePostedId = 5 + MessageWillBeUpdatedId = 6 + MessageHasBeenPostedId = 7 + MessageHasBeenUpdatedId = 8 + TotalHooksId = iota +) + // Methods from the Hooks interface can be used by a plugin to respond to events. Methods are likely // to be added over time, and plugins are not expected to implement all of them. Instead, plugins // are expected to implement a subset of them and pass an instance to plugin/rpcplugin.Main, which // will take over execution of the process and add default behaviors for missing hooks. type Hooks interface { - // OnActivate is invoked when the plugin is activated. Implementations will usually want to save - // the api argument for later use. Loading configuration for the first time is also a commonly - // done here. - OnActivate(API) error + // OnActivate is invoked when the plugin is activated. + OnActivate() error + + // Implemented returns a list of hooks that are implmented by the plugin. + // Plugins do not need to provide an implementation. Any given will be ignored. + Implemented() ([]string, error) // OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to // use the API, and the plugin will be terminated shortly after this invocation. @@ -31,7 +48,7 @@ type Hooks interface { // // The Mattermost-User-Id header will be present if (and only if) the request is by an // authenticated user. - ServeHTTP(http.ResponseWriter, *http.Request) + ServeHTTP(w http.ResponseWriter, r *http.Request) // ExecuteCommand executes a command that has been previously registered via the RegisterCommand // API. -- cgit v1.2.3-1-g7c22 From 4c1ddcff10b359baf5728b334acb60cc3e1b1123 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 6 Jul 2018 06:07:09 -0700 Subject: MM-10703 Adding blank request context to plugin hooks for future use. (#9043) * Adding blank request context to plugin hooks for future use. * Rename RequestContext to Context * Adding context to ServeHTTP and ExecuteCommand * Fixing import cycle in test. --- plugin/hooks.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'plugin/hooks.go') diff --git a/plugin/hooks.go b/plugin/hooks.go index 68eca8ede..852f4684c 100644 --- a/plugin/hooks.go +++ b/plugin/hooks.go @@ -48,11 +48,11 @@ type Hooks interface { // // The Mattermost-User-Id header will be present if (and only if) the request is by an // authenticated user. - ServeHTTP(w http.ResponseWriter, r *http.Request) + ServeHTTP(c *Context, w http.ResponseWriter, r *http.Request) // ExecuteCommand executes a command that has been previously registered via the RegisterCommand // API. - ExecuteCommand(args *model.CommandArgs) (*model.CommandResponse, *model.AppError) + ExecuteCommand(c *Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) // MessageWillBePosted is invoked when a message is posted by a user before it is commited // to the database. If you also want to act on edited posts, see MessageWillBeUpdated. @@ -62,7 +62,7 @@ type Hooks interface { // // Note that this method will be called for posts created by plugins, including the plugin that // created the post. - MessageWillBePosted(post *model.Post) (*model.Post, string) + MessageWillBePosted(c *Context, post *model.Post) (*model.Post, string) // MessageWillBeUpdated is invoked when a message is updated by a user before it is commited // to the database. If you also want to act on new posts, see MessageWillBePosted. @@ -73,17 +73,17 @@ type Hooks interface { // // Note that this method will be called for posts updated by plugins, including the plugin that // updated the post. - MessageWillBeUpdated(newPost, oldPost *model.Post) (*model.Post, string) + MessageWillBeUpdated(c *Context, newPost, oldPost *model.Post) (*model.Post, string) // MessageHasBeenPosted is invoked after the message has been commited to the databse. // If you need to modify or reject the post, see MessageWillBePosted // Note that this method will be called for posts created by plugins, including the plugin that // created the post. - MessageHasBeenPosted(post *model.Post) + MessageHasBeenPosted(c *Context, post *model.Post) // MessageHasBeenUpdated is invoked after a message is updated and has been updated in the databse. // If you need to modify or reject the post, see MessageWillBeUpdated // Note that this method will be called for posts created by plugins, including the plugin that // created the post. - MessageHasBeenUpdated(newPost, oldPost *model.Post) + MessageHasBeenUpdated(c *Context, newPost, oldPost *model.Post) } -- cgit v1.2.3-1-g7c22 From 359f12db33d45b6ffade0872ddf3652a5c52f4a8 Mon Sep 17 00:00:00 2001 From: Daniel Schalla Date: Sat, 7 Jul 2018 00:32:55 +0200 Subject: First batch of new plugin api methods (#9022) update api mocks Generated new hooks ChannelHasJoinedChannel Implementation User Left Team/Channel Hook; User Joined Team Hook Implementation Update RPC Client and Mocks gofmt go tests fix Add Config API Methods codegne Add Channel Has Been Created Hook Fix ChannelHasBeenCreated hook fix missing context param fix duplicate hooks; remove redudandcy --- plugin/hooks.go | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) (limited to 'plugin/hooks.go') diff --git a/plugin/hooks.go b/plugin/hooks.go index 852f4684c..daeffbc32 100644 --- a/plugin/hooks.go +++ b/plugin/hooks.go @@ -21,6 +21,11 @@ const ( MessageWillBeUpdatedId = 6 MessageHasBeenPostedId = 7 MessageHasBeenUpdatedId = 8 + UserHasJoinedChannelId = 9 + UserHasLeftChannelId = 10 + UserHasJoinedTeamId = 11 + UserHasLeftTeamId = 12 + ChannelHasBeenCreatedId = 13 TotalHooksId = iota ) @@ -54,7 +59,7 @@ type Hooks interface { // API. ExecuteCommand(c *Context, args *model.CommandArgs) (*model.CommandResponse, *model.AppError) - // MessageWillBePosted is invoked when a message is posted by a user before it is commited + // MessageWillBePosted is invoked when a message is posted by a user before it is committed // to the database. If you also want to act on edited posts, see MessageWillBeUpdated. // Return values should be the modified post or nil if rejected and an explanation for the user. // @@ -64,7 +69,7 @@ type Hooks interface { // created the post. MessageWillBePosted(c *Context, post *model.Post) (*model.Post, string) - // MessageWillBeUpdated is invoked when a message is updated by a user before it is commited + // MessageWillBeUpdated is invoked when a message is updated by a user before it is committed // to the database. If you also want to act on new posts, see MessageWillBePosted. // Return values should be the modified post or nil if rejected and an explanation for the user. // On rejection, the post will be kept in its previous state. @@ -75,15 +80,34 @@ type Hooks interface { // updated the post. MessageWillBeUpdated(c *Context, newPost, oldPost *model.Post) (*model.Post, string) - // MessageHasBeenPosted is invoked after the message has been commited to the databse. + // MessageHasBeenPosted is invoked after the message has been committed to the database. // If you need to modify or reject the post, see MessageWillBePosted // Note that this method will be called for posts created by plugins, including the plugin that // created the post. MessageHasBeenPosted(c *Context, post *model.Post) - // MessageHasBeenUpdated is invoked after a message is updated and has been updated in the databse. + // MessageHasBeenUpdated is invoked after a message is updated and has been updated in the database. // If you need to modify or reject the post, see MessageWillBeUpdated // Note that this method will be called for posts created by plugins, including the plugin that // created the post. MessageHasBeenUpdated(c *Context, newPost, oldPost *model.Post) + + // ChannelHasBeenCreated is invoked after the channel has been committed to the database. + ChannelHasBeenCreated(c *Context, channel *model.Channel) + + // UserHasJoinedChannel is invoked after the membership has been committed to the database. + // If actor is not nil, the user was invited to the channel by the actor. + UserHasJoinedChannel(c *Context, channelMember *model.ChannelMember, actor *model.User) + + // UserHasLeftChannel is invoked after the membership has been removed from the database. + // If actor is not nil, the user was removed from the channel by the actor. + UserHasLeftChannel(c *Context, channelMember *model.ChannelMember, actor *model.User) + + // UserHasJoinedTeam is invoked after the membership has been committed to the database. + // If actor is not nil, the user was added to the team by the actor. + UserHasJoinedTeam(c *Context, teamMember *model.TeamMember, actor *model.User) + + // UserHasLeftTeam is invoked after the membership has been removed from the database. + // If actor is not nil, the user was removed from the team by the actor. + UserHasLeftTeam(c *Context, teamMember *model.TeamMember, actor *model.User) } -- cgit v1.2.3-1-g7c22