diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-06-25 12:33:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-25 12:33:13 -0700 |
commit | 1e5c432e1029601a664454388ae366ef69618d62 (patch) | |
tree | cb9e8bfb66640ac3b29c934bb2c3202d25aeb368 /app/plugin/ldapextras/plugin.go | |
parent | ecefa6cdd1e7376046bbec82c1b47f7756fea646 (diff) | |
download | chat-1e5c432e1029601a664454388ae366ef69618d62.tar.gz chat-1e5c432e1029601a664454388ae366ef69618d62.tar.bz2 chat-1e5c432e1029601a664454388ae366ef69618d62.zip |
MM-10702 Moving plugins to use hashicorp go-plugin. (#8978)
* Moving plugins to use hashicorp go-plugin.
* Tweaks from feedback.
Diffstat (limited to 'app/plugin/ldapextras/plugin.go')
-rw-r--r-- | app/plugin/ldapextras/plugin.go | 71 |
1 files changed, 0 insertions, 71 deletions
diff --git a/app/plugin/ldapextras/plugin.go b/app/plugin/ldapextras/plugin.go deleted file mode 100644 index e0645b68e..000000000 --- a/app/plugin/ldapextras/plugin.go +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. -// See License.txt for license information. - -package ldapextras - -import ( - "fmt" - "net/http" - "sync/atomic" - - "github.com/gorilla/mux" - - "github.com/mattermost/mattermost-server/app/plugin" - "github.com/mattermost/mattermost-server/mlog" - "github.com/mattermost/mattermost-server/model" -) - -type Plugin struct { - plugin.Base - api plugin.API - configuration atomic.Value -} - -func (p *Plugin) Initialize(api plugin.API) { - p.api = api - p.OnConfigurationChange() - api.PluginRouter().HandleFunc("/users/{user_id:[A-Za-z0-9]+}/attributes", p.handleGetAttributes).Methods("GET") -} - -func (p *Plugin) config() *Configuration { - return p.configuration.Load().(*Configuration) -} - -func (p *Plugin) OnConfigurationChange() { - var configuration Configuration - if err := p.api.LoadPluginConfiguration(&configuration); err != nil { - mlog.Error(err.Error()) - } - p.configuration.Store(&configuration) -} - -func (p *Plugin) handleGetAttributes(w http.ResponseWriter, r *http.Request) { - config := p.config() - if !config.Enabled || len(config.Attributes) == 0 { - http.Error(w, "This plugin is not configured", http.StatusNotImplemented) - return - } - - session, err := p.api.GetSessionFromRequest(r) - - if session == nil || err != nil { - http.Error(w, "Invalid session", http.StatusUnauthorized) - return - } - - // Only requires a valid session, no other permission checks required - - params := mux.Vars(r) - id := params["user_id"] - - if len(id) != 26 { - http.Error(w, "Invalid user id", http.StatusUnauthorized) - } - - attributes, err := p.api.GetLdapUserAttributes(id, config.Attributes) - if err != nil { - http.Error(w, fmt.Sprintf("Errored getting attributes: %v", err.Error()), http.StatusInternalServerError) - } - - w.Write([]byte(model.MapToJson(attributes))) -} |