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/api.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'plugin/api.go') diff --git a/plugin/api.go b/plugin/api.go index d62c2f069..ed2bfa733 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -4,6 +4,7 @@ package plugin import ( + "github.com/hashicorp/go-plugin" "github.com/mattermost/mattermost-server/model" ) @@ -104,17 +105,18 @@ type API interface { // UpdatePost updates a post. UpdatePost(post *model.Post) (*model.Post, *model.AppError) - // KeyValueStore returns an object for accessing the persistent key value storage. - KeyValueStore() KeyValueStore -} - -type KeyValueStore interface { // Set will store a key-value pair, unique per plugin. - Set(key string, value []byte) *model.AppError + KVSet(key string, value []byte) *model.AppError // Get will retrieve a value based on the key. Returns nil for non-existent keys. - Get(key string) ([]byte, *model.AppError) + KVGet(key string) ([]byte, *model.AppError) // Delete will remove a key-value pair. Returns nil for non-existent keys. - Delete(key string) *model.AppError + KVDelete(key string) *model.AppError +} + +var Handshake = plugin.HandshakeConfig{ + ProtocolVersion: 1, + MagicCookieKey: "MATTERMOST_PLUGIN", + MagicCookieValue: "Securely message teams, anywhere.", } -- cgit v1.2.3-1-g7c22 From d7976549a0b45a42c04ac043a15677b7ca1228e9 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Wed, 27 Jun 2018 08:46:38 -0400 Subject: MM-9674 Add plugin API for publishing custom WebSocket events (#8999) * Add plugin API for publishing custom WebSocket events * Add clearer payload comment * Update comment --- plugin/api.go | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'plugin/api.go') diff --git a/plugin/api.go b/plugin/api.go index ed2bfa733..842cef4f6 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -113,6 +113,12 @@ type API interface { // Delete will remove a key-value pair. Returns nil for non-existent keys. KVDelete(key string) *model.AppError + + // PublishWebSocketEvent sends an event to WebSocket connections. + // event is the type and will be prepended with "custom__" + // payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types + // broadcast determines to which users to send the event + PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) } var Handshake = plugin.HandshakeConfig{ -- cgit v1.2.3-1-g7c22 From 83a3ac089cff0d05559e6ba5c2c60b09f5cae176 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Tue, 3 Jul 2018 09:58:28 -0700 Subject: MM-11029 Adding plugin logging functionality. (#9034) * Capturing stdout, stderr of plugins in logs. * Cleanup go-plugin debug logs. * Adding logging to plugin API * Generating mocks. * godoc convention --- plugin/api.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'plugin/api.go') diff --git a/plugin/api.go b/plugin/api.go index 842cef4f6..81a27c330 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -119,6 +119,30 @@ type API interface { // payload is the data sent with the event. Interface values must be primitive Go types or mattermost-server/model types // broadcast determines to which users to send the event PublishWebSocketEvent(event string, payload map[string]interface{}, broadcast *model.WebsocketBroadcast) + + // LogDebug writes a log message to the Mattermost server log file. + // Appropriate context such as the plugin name will already be added as fields so plugins + // do not need to add that info. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogDebug(msg string, keyValuePairs ...interface{}) + + // LogInfo writes a log message to the Mattermost server log file. + // Appropriate context such as the plugin name will already be added as fields so plugins + // do not need to add that info. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogInfo(msg string, keyValuePairs ...interface{}) + + // LogError writes a log message to the Mattermost server log file. + // Appropriate context such as the plugin name will already be added as fields so plugins + // do not need to add that info. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogError(msg string, keyValuePairs ...interface{}) + + // LogWarn writes a log message to the Mattermost server log file. + // Appropriate context such as the plugin name will already be added as fields so plugins + // do not need to add that info. + // keyValuePairs should be primitive go types or other values that can be encoded by encoding/gob + LogWarn(msg string, keyValuePairs ...interface{}) } var Handshake = plugin.HandshakeConfig{ -- 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/api.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'plugin/api.go') diff --git a/plugin/api.go b/plugin/api.go index 81a27c330..2b15a3d09 100644 --- a/plugin/api.go +++ b/plugin/api.go @@ -24,6 +24,12 @@ type API interface { // UnregisterCommand unregisters a command previously registered via RegisterCommand. UnregisterCommand(teamId, trigger string) error + // GetConfig fetches the currently persisted config + GetConfig() *model.Config + + // SaveConfig sets the given config and persists the changes + SaveConfig(config *model.Config) *model.AppError + // CreateUser creates a user. CreateUser(user *model.User) (*model.User, *model.AppError) @@ -48,6 +54,9 @@ type API interface { // DeleteTeam deletes a team. DeleteTeam(teamId string) *model.AppError + // GetTeam gets all teams. + GetTeams() ([]*model.Team, *model.AppError) + // GetTeam gets a team. GetTeam(teamId string) (*model.Team, *model.AppError) @@ -57,12 +66,33 @@ type API interface { // UpdateTeam updates a team. UpdateTeam(team *model.Team) (*model.Team, *model.AppError) + // CreateTeamMember creates a team membership. + CreateTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) + + // CreateTeamMember creates a team membership for all provided user ids. + CreateTeamMembers(teamId string, userIds []string, requestorId string) ([]*model.TeamMember, *model.AppError) + + // DeleteTeamMember deletes a team membership. + DeleteTeamMember(teamId, userId, requestorId string) *model.AppError + + // GetTeamMembers returns the memberships of a specific team. + GetTeamMembers(teamId string, offset, limit int) ([]*model.TeamMember, *model.AppError) + + // GetTeamMember returns a specific membership. + GetTeamMember(teamId, userId string) (*model.TeamMember, *model.AppError) + + // UpdateTeamMemberRoles updates the role for a team membership. + UpdateTeamMemberRoles(teamId, userId, newRoles string) (*model.TeamMember, *model.AppError) + // CreateChannel creates a channel. CreateChannel(channel *model.Channel) (*model.Channel, *model.AppError) // DeleteChannel deletes a channel. DeleteChannel(channelId string) *model.AppError + // GetChannels gets a list of all channels. + GetPublicChannelsForTeam(teamId string, offset, limit int) (*model.ChannelList, *model.AppError) + // GetChannel gets a channel. GetChannel(channelId string) (*model.Channel, *model.AppError) @@ -96,6 +126,9 @@ type API interface { // CreatePost creates a post. CreatePost(post *model.Post) (*model.Post, *model.AppError) + // SendEphemeralPost creates an ephemeral post. + SendEphemeralPost(userId string, post *model.Post) *model.Post + // DeletePost deletes a post. DeletePost(postId string) *model.AppError -- cgit v1.2.3-1-g7c22