Commit graph

66 commits

Author SHA1 Message Date
Joram Wilander
9c76d9ba00 Add GetLDAPUserAttributes method to the plugin API (#9326) 2018-08-29 11:07:27 -07:00
Jesús Espino
cea1796f06 Adding Permissions check and reactions function to plugins API (#9273)
* Adding reactions functions

* Adding permissions checking in the plugins api
2018-08-20 09:22:08 -07:00
Elias Nahum
0aa0adb911 Add FileInfo and get file []byte in plugin api (#9269)
* Add FileInfo and get file []byte in plugin api

* Regenerated plugin mocks

* Rename ReadFileAtPath to ReadFile
2018-08-20 09:18:25 -07:00
Jesse Hallam
687700a989 clarify CopyFileInfos godocs (#9243) 2018-08-10 17:21:37 +02:00
Jesse Hallam
7475cd260a fix plugintest example and docs (#9213) 2018-08-08 12:07:38 +02:00
Jesse Hallam
04749027f6
MM-11575: change plugin nil semantics (#9212)
* change MessageWillBePosted nil return semantics

* change FileWillBeUploaded nil return semantics

* use LogDebug to verify plugin inputs vs. the confusing Delete(User|Team)
2018-08-03 13:15:51 -04:00
dmitrysamuylovpharo
7a731d2bd1 Feature/fileinfo create copy (#9198)
* Initial implementation of a CopyFileInfos function that creates new FileInfo objects copied from provided FileIds with the provided user as the creator and not linked to a post yet. This can subsequently be used to copy existing attachments from another post to attach to a new post without having to re-upload the actual files

* added a unit test for the CopyFileInfos function

* resolving pull request suggestions
2018-08-02 10:37:31 -04:00
Christopher Speller
c8013d4982
Remove accidential dependency (#9203) 2018-08-01 15:38:56 -07:00
Daniel Schalla
2936dc87d0 CSRF Token Implementation for Plugins (#9192)
deleted test config

fix test config

Dont wipe the session token for plugins

Simplified Tokens; Generate CSRF for other sessions

Remove CSRF from Access Token; Remove Getter/Setter from Context

fix removed setter

remove getcsrf helper from plugin api

enforce csrf only for cookie auth
2018-08-01 15:16:04 -07:00
Jesse Hallam
0788cdcadf
MM-11420: plugins: compute bundle hash on load (#9172)
* plugins: compute bundle hash on load

Use this hash to bust client caches whenever the plugin bundle changes.

* eliminate redundant pluginHandler

* switch to 64-bit FNV-1a

* Fix test
2018-07-31 16:29:52 -04:00
Christopher Speller
82dfe9e61d
Adding support for code split plugins. (#9184) 2018-07-31 07:44:44 -07:00
Jesse Hallam
fcb4ee935e
gob register AppError (#9182)
This allows plugin hooks to return the result of calling the API as an
`error`.
2018-07-31 10:34:40 -04:00
Martin Kraft
5872bf9c2f
Pr 9039 (#9187)
* MM-11065: Allow to search and get archived channels from the API

* Fixing more tests

* Add some unit tests

* Add includeDeleted parameter to session permissions check function

* More test fixing

* Adding archive channels list in channels search

* Add restriction for archived channel edition

* Reverting permissions checks modification

* Changed the query parameter to include_deleted

* Enable search archive channels as true by default

* Adding tests for verify search on deleted channels

* Allowing to override archive channels during the imports

* Fixed test

* Search in archive channels from the API must be explicitly requested

* Removing includeDeleted parameter from GetChannelByName and GetChannelByNameForTeam

* Back to ViewArchivedChannels config

* Fixing tests

* Reverting GetChannelByName parameter

* Add include deleted parameter on GetChannel functions in plugins api

* Fixing tests
2018-07-30 15:06:08 -04:00
Daniel Schalla
d23ca07133 Login Hooks (#9177)
Tests; gofmt
2018-07-30 11:55:38 -07:00
Joram Wilander
441c8741c1
Fix compile error caused by bad merge (#9176)
* Fix compile error caused by bad merge

* Fix

* Fix
2018-07-27 12:57:17 -04:00
Jesse Hallam
835c0871a0
MM-11431: handle plugin deadlocks (#9167)
* ensure plugin is always shutdown

Once we call `.client.Client()` the plugin has started, and must be shut
down. `newSupervisor` sometimes returned with an error (and without a
reference to the supervisor), leaving the client running indefinitely.

* Clarify the documentation to explain that plugin hooks will not trigger until `OnActivate` returns successfully, and will stop triggering just before `OnDeactivate` is called.

* test for plugin deadlock

* plugin/environment.go: switch to sync.Map

From: https://golang.org/pkg/sync/#Map

> If a goroutine holds a RWMutex for reading and another goroutine might call Lock, no goroutine should expect to be able to acquire a read lock until the initial read lock is released. In particular, this prohibits recursive read locking. This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock.

The previous `RWMutex` was not safe given that we effectively acquired read locks recursively (hook -> api -> hook). This worked up until we activated or deactivated plugins, tried to acquire a write lock, and the plugin used the API to effectively trigger another hook.

Switching to sync.Map avoids this by divesting the need to lock at all, avoiding the potential for a recursive lock in the first place.
2018-07-27 11:37:17 -04:00
Jesse Hallam
1d9c144854 s/mlog/log/ in apiRPCClient (#9171)
We never actually initialized `log` on apiRPCClient, and it can't log
without making an RPC call anyway, so just switch to logging errors from
the plugin to STDERR instead.
2018-07-27 08:17:29 -07:00
Christopher Speller
026f0152a8 Adding FileWillBeUploaded plugin hook (#9169)
* Adding file upload hook.

* Adding hook test for FileWillBeUploaded

* Some debugging fixes.

* Fix typo.

* Fixing double close

* Fix capitalization on docs.
2018-07-27 08:25:53 -04:00
Jesse Hallam
b89ccca929 fix plugin example docs (#9148) 2018-07-25 08:01:13 -04:00
Jesse Hallam
908a682fcf make GetChannelByName take teamId first (#9134)
* make GetChannelByName take teamId first

I think it is more natural to accept `teamId`, then `channelName`,
given the pattern followed by other Plugin API methods and even the SQL
Store itself. The App layer seems unusual in accepting `channelName`
first.

This also re-generates the mocks fixing the parameter order for the
recently added `UserStatus` APIs.

* add GetChannelByNameForTeamName
2018-07-20 09:03:08 -07:00
Christopher Speller
5a2d46c6cb
MM-11028 Adding some plugin tests. (#9103)
* Rearranging plugin mocks and moving some common test code out.

* Adding tests.

* Fixing tests after GoDoc cleanup changes.
2018-07-18 16:35:12 -07:00
Jesse Hallam
309a3dda60 Support server, deprecate backend in plugin manifest (#9127)
* Support `server`, deprecate `backend` in plugin manifest

This lets us converge on the use of the term `server` everywhere instead
of sometimes `backend` and sometimes `server`. We're still using
`webapp` and will eventually support `mobile` as well.

The plan is actually to rip out these deprecations as part of releasing
5.2, but I want to coordinate the extra additional breakage at the same
time, so for now this is a backwards compatible change.

* fix failing tests
2018-07-18 15:32:33 -07:00
Jesse Hallam
e718d2544f MM-11366: support a plugin bundle with multiple executables (#9121)
This avoids the need to distribute multiple plugins per architecture.
2018-07-17 15:47:05 -07:00
Joram Wilander
275731578e
MM-10254 Add plugin APIs for getting/updating user statuses (#9101)
* Add plugin APIs for getting/updating user statuses

* Add and update tests

* Updates per feedback
2018-07-16 15:49:26 -04:00
Jesse Hallam
17f211c393
MM-11292: clean up plugins GoDoc (#9109)
* clean up plugins GoDoc:

- eliminate plugin.NewBlankContext() as unnecessary
- export ValidIdRegex as a string vs. the less readable var
- add/update various documentation strings
- hide everything by default, except where used by client plugins or the mattermost-server. The exception to this rule are the `*(Args|Returns)` structs which must be public for go-plugin, but are now prefixed with `Z_` with a warning not to use.
- include a top-level example to get plugin authors started

This is not a breaking change for existing plugins compiled against
plugins-v2.

* remove commented out ServeHTTPResponseWriter

* update examples to match developer docs

* add missing plugin/doc.go license header
2018-07-13 10:29:50 -04:00
Daniel Schalla
359f12db33 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
2018-07-06 15:32:55 -07:00
Christopher Speller
4c1ddcff10 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.
2018-07-06 09:07:09 -04:00
Christopher Speller
83a3ac089c
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
2018-07-03 09:58:28 -07:00
Joram Wilander
d7976549a0
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
2018-06-27 08:46:38 -04:00
Christopher Speller
1e5c432e10
MM-10702 Moving plugins to use hashicorp go-plugin. (#8978)
* Moving plugins to use hashicorp go-plugin.

* Tweaks from feedback.
2018-06-25 12:33:13 -07:00
Jesse Hallam
ffb1d5d8e3 disable Supervisor_PluginRepeatedlyCrash (#8918)
* disable Supervisor_PluginRepeatedlyCrash

This test is failing sporadically, largely due to the use of a timeout
to verify results. A more robust solution is required.

* disable Supervisor_PluginCrash

This test is failing sporadically, largely due to the use of a timeout
to verify results. A more robust solution is required.
2018-06-05 22:53:08 +02:00
Jesse Hallam
847c181ec9
MM-8622: Improved plugin error reporting (#8737)
* allow `Wait()`ing on the supervisor

In the event the plugin supervisor shuts down a plugin for crashing too
many times, the new `Wait()` interface allows the `ActivatePlugin` to
accept a callback function to trigger when `supervisor.Wait()` returns.
If the supervisor shuts down normally, this callback is invoked with
a nil error, otherwise any error reported by the supervisor is passed
along.

* improve plugin activation/deactivation logic

Avoid triggering activation of previously failed-to-start plugins just
becase something in the configuration changed. Now, intelligently
compare the global enable bit as well as the each individual plugin's
enabled bit.

* expose store to manipulate PluginStatuses

* expose API to fetch plugin statuses

* keep track of whether or not plugin sandboxing is supported

* transition plugin statuses

* restore error on plugin activation if already active

* don't initialize test plugins until successfully loaded

* emit websocket events when plugin statuses change

* skip pruning if already initialized

* MM-8622: maintain plugin statuses in memory

Switch away from persisting plugin statuses to the database, and
maintain in memory instead. This will be followed by a cluster interface
to query the in-memory status of plugin statuses from all cluster nodes.

At the same time, rename `cluster_discovery_id` on the `PluginStatus`
model object to `cluster_id`.

* MM-8622: aggregate plugin statuses across cluster

* fetch cluster plugin statuses when emitting websocket notification

* address unit test fixes after rebasing

* relax (poor) racey unit test re: supervisor.Wait()

* make store-mocks
2018-05-23 14:26:35 -04:00
Christopher Speller
df6a7f8b19
MM-10249 Adding plugin ability to intercept posts before they reach the DB. (#8791)
* Adding plugin ability to intercept posts before they reach the DB.

* s/envoked/invoked/
2018-05-15 13:33:47 -07:00
Jesse Hallam
1e6553704d MM-8622: improved plugin error handling (#8692)
* don't report an error on plugin activation if already active

* improved plugin logging events

Log an error when a plugin's ServeHTTP fails, or when it unexpectedly
terminates.

Restart a plugin at most three times, allowing its failure to later
bubble up under the "failed to stay running" status.

* clarified plugin activation/deactivation

Avoid repeatedly activating when any configuration bit changes. Improved
logging.

* constrain plugin ids to ^[a-zA-Z0-9-_\.]+$ and enforce minimum length

Previously, the plugin id was used unsanitized to relocate the plugin
bundle, which allowed writing outside the `plugins/` directory by using
an `id` containing `../`.

Similarly, an empty string was accepted as an id and led to unexpected
error messages.

* remove plugins by manifest path, not id

If the id within the manifest ever diverges from the actual plugin
location, it becomes impossible to remove via the API. Instead, if the
plugin is found by id, remove the path containing the manifest.

* ignore plugins with nil manifests

If a plugin was detected, but had a manifest that couldn't be parsed, it
will be left nil but still be listed among the packages. Skip over these
in most cases to avoid segfaults.

* leverage mlog more effectively for plugins

* build issues
2018-05-01 07:34:12 -07:00
Jesse Hallam
116849842b MM-8678: add CUD support for channel members via plugins (#8565)
* add CUD support for channel members via plugins

This effectively exposes AddChannelMember, UpdateChannelMemberRoles,
UpdateChannelMemberNotifyProps and LeaveChannel via the plugin API.

It also modifies the semantics of AddChannelMember to explicitly allow
for an empty user requestor, left as such for now via the plugin API.

* change the signature of AddChannelMember to accept a channel id instead of a channel
2018-04-06 17:08:57 -04:00
Chris
3922b3ac8c fix sandbox cleanup (#8421) 2018-03-08 14:19:56 +00:00
Chris
98e1231fcc respect plugin manifest webapp bundle_path (#8393) 2018-03-07 13:57:59 -06:00
Chris
e4ddad16bf plugin sandbox fixes (#8418) 2018-03-07 13:43:26 -05:00
Chris
a434fe7637 register additional gob types to support arrays and dicts in post props (#8412) 2018-03-06 21:01:18 -05:00
Chris
5503a1351a add arch linux sandboxing mount points (#8147) 2018-01-25 08:18:45 -08:00
Chris
f5c8a71698 ABC-22: Plugin sandboxing for linux/amd64 (#8068)
* plugin sandboxing

* remove unused type

* better symlink handling, better remounting, better test, whitespace
fixes, and comment on the remounting

* fix test compile error

* big simplification for getting mount flags

* mask statfs flags to the ones we're interested in
2018-01-15 09:21:06 -08:00
Chris
4c17bdff1b
Add plugin slash command support (#7941)
* add plugin slash command support

* remove unused string

* rebase
2017-12-08 13:55:41 -06:00
Chris
eb027c0d3b make slack attachments gobable (#7948) 2017-12-05 15:34:10 -08:00
Chris
3c7b40063d call OnActivate after plugin crash, update example (#7940) 2017-12-05 09:19:32 -05:00
Joram Wilander
7a1f81cd52
Add GetChannelMember method to plugin API (#7930) 2017-12-05 09:14:03 -05:00
Chris
739d91f213
better plugin LoadConfiguration mock (#7928) 2017-12-01 11:26:05 -06:00
Chris
d0d9ba4a7e expose vendored mock package with plugintest/mock (#7914) 2017-11-29 10:54:14 -08:00
Joram Wilander
6176bcff69
PLT-8131 (part2) Add plugin key value store support (#7902)
* Add plugin key value store support

* Add localization strings

* Updates per feedback
2017-11-27 17:23:35 -05:00
Chris
6eb4b4604c
improve rpcplugin tests (#7837) 2017-11-15 16:08:02 -06:00
Chris
1d1998c668 add a few docs for plugin testing (#7798)
* add a few docs for plugin testing

* fix typo
2017-11-07 11:12:38 -08:00