diff options
author | Chris <ccbrown112@gmail.com> | 2017-11-30 14:55:44 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-30 14:55:44 -0600 |
commit | daebd26a2894d88eb4c703b3be75f042cd563fef (patch) | |
tree | 0dfd6d21a1c284271f366c1b8279833fc4e7ed30 /app/plugin/jira/plugin.go | |
parent | eaca461ee35993c07936a5888c003153d9e9b24f (diff) | |
download | chat-daebd26a2894d88eb4c703b3be75f042cd563fef.tar.gz chat-daebd26a2894d88eb4c703b3be75f042cd563fef.tar.bz2 chat-daebd26a2894d88eb4c703b3be75f042cd563fef.zip |
PLT-8018: Bundled jira plugin (#7920)
* bundled jira plugin
* fix generated file formatting, add prepackaged key
* whoops, uploaded wrong file
* whitelist generated files for license check
* make it work for people without go/bin in their path
Diffstat (limited to 'app/plugin/jira/plugin.go')
-rw-r--r-- | app/plugin/jira/plugin.go | 77 |
1 files changed, 4 insertions, 73 deletions
diff --git a/app/plugin/jira/plugin.go b/app/plugin/jira/plugin.go index 55fd3759c..46fc381c4 100644 --- a/app/plugin/jira/plugin.go +++ b/app/plugin/jira/plugin.go @@ -1,79 +1,10 @@ // Copyright (c) 2017-present Mattermost, Inc. All Rights Reserved. // See License.txt for license information. -package jira - -import ( - "crypto/subtle" - "encoding/json" - "net/http" - "sync/atomic" - - l4g "github.com/alecthomas/log4go" - "github.com/mattermost/mattermost-server/app/plugin" - "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("/webhook", p.handleWebhook).Methods("POST") -} +// +build !amd64 !darwin,!linux,!windows -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 { - l4g.Error(err.Error()) - } - p.configuration.Store(&configuration) -} - -func (p *Plugin) handleWebhook(w http.ResponseWriter, r *http.Request) { - config := p.config() - if !config.Enabled || config.Secret == "" || config.UserName == "" { - http.Error(w, "This plugin is not configured.", http.StatusForbidden) - return - } else if subtle.ConstantTimeCompare([]byte(r.URL.Query().Get("secret")), []byte(config.Secret)) != 1 { - http.Error(w, "You must provide the configured secret.", http.StatusForbidden) - return - } - - var webhook Webhook +package jira - if err := json.NewDecoder(r.Body).Decode(&webhook); err != nil { - http.Error(w, err.Error(), http.StatusBadRequest) - } else if attachment, err := webhook.SlackAttachment(); err != nil { - http.Error(w, err.Error(), http.StatusInternalServerError) - } else if attachment == nil { - return - } else if r.URL.Query().Get("channel") == "" { - http.Error(w, "You must provide a channel.", http.StatusBadRequest) - } else if user, err := p.api.GetUserByName(config.UserName); err != nil { - http.Error(w, p.api.I18n(err.Message, r), err.StatusCode) - } else if team, err := p.api.GetTeamByName(r.URL.Query().Get("team")); err != nil { - http.Error(w, p.api.I18n(err.Message, r), err.StatusCode) - } else if channel, err := p.api.GetChannelByName(team.Id, r.URL.Query().Get("channel")); err != nil { - http.Error(w, p.api.I18n(err.Message, r), err.StatusCode) - } else if _, err := p.api.CreatePost(&model.Post{ - ChannelId: channel.Id, - Type: model.POST_SLACK_ATTACHMENT, - UserId: user.Id, - Props: map[string]interface{}{ - "from_webhook": "true", - "use_user_icon": "true", - "attachments": []*model.SlackAttachment{attachment}, - }, - }); err != nil { - http.Error(w, p.api.I18n(err.Message, r), err.StatusCode) - } +func Asset(name string) ([]byte, error) { + return nil, nil } |