-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MI-814: Render a template for atlassian-connect.json file. (#19)
* Use a template for atlassian-connect.json file. * Fix formatting * Fix plugin url path * Code refactoring * Add a slash command to show URL for atlassian-connect.json file. * Update the list of available commands * Add help commands. * Use constants * Fix lint * Fix failing test - Update .gitignore
- Loading branch information
1 parent
33ed4de
commit 737d5bb
Showing
13 changed files
with
372 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,4 +75,4 @@ vendor/ | |
coverage.txt | ||
|
||
# webapp test cases | ||
build/test-results.xml | ||
webapp/build/test-results.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"key": "{{ .PluginKey }}", | ||
"name": "Mattermost Plugin ({{ .ExternalURL }})", | ||
"description": "Publish confluence cloud notifications to Mattermost.", | ||
"vendor": { | ||
"name": "Mattermost", | ||
"url": "https://github.com/mattermost" | ||
}, | ||
"baseUrl": "{{ .BaseURL }}", | ||
"links": { | ||
"self": "{{ .BaseURL }}{{ .RouteACJSON }}", | ||
"homepage": "https://www.mattermost.com" | ||
}, | ||
"authentication": { | ||
"type": "none" | ||
}, | ||
"scopes": [ | ||
"READ" | ||
], | ||
"modules": { | ||
"webhooks": [ | ||
{ | ||
"event": "comment_created", | ||
"url": "/cloud/comment_created?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "comment_deleted", | ||
"url": "/cloud/comment_deleted?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "comment_updated", | ||
"url": "/cloud/comment_updated?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "comment_removed", | ||
"url": "/cloud/comment_removed?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "page_created", | ||
"url": "/cloud/page_created?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "page_removed", | ||
"url": "/cloud/page_removed?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "page_restored", | ||
"url": "/cloud/page_restored?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "page_trashed", | ||
"url": "/cloud/page_trashed?secret={{ .SharedSecret }}" | ||
}, | ||
{ | ||
"event": "page_updated", | ||
"url": "/cloud/page_updated?secret={{ .SharedSecret }}" | ||
} | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package controller | ||
|
||
import ( | ||
"html/template" | ||
"net/http" | ||
"net/url" | ||
"path" | ||
"path/filepath" | ||
|
||
"github.com/Brightscout/mattermost-plugin-confluence/server/config" | ||
"github.com/Brightscout/mattermost-plugin-confluence/server/util" | ||
) | ||
|
||
var atlassianConnectJSON = &Endpoint{ | ||
Path: "/atlassian-connect.json", | ||
Method: http.MethodGet, | ||
Execute: renderAtlassianConnectJSON, | ||
RequiresAuth: false, | ||
} | ||
|
||
func renderAtlassianConnectJSON(w http.ResponseWriter, r *http.Request) { | ||
conf := config.GetConfig() | ||
if status, err := verifyHTTPSecret(conf.Secret, r.FormValue("secret")); err != nil { | ||
http.Error(w, err.Error(), status) | ||
return | ||
} | ||
|
||
bundlePath, err := config.Mattermost.GetBundlePath() | ||
if err != nil { | ||
config.Mattermost.LogWarn("Failed to get bundle path.", "Error", err.Error()) | ||
return | ||
} | ||
|
||
templateDir := filepath.Join(bundlePath, "assets", "templates") | ||
tmplPath := path.Join(templateDir, "atlassian-connect.json") | ||
values := map[string]string{ | ||
"BaseURL": util.GetPluginURL(), | ||
"RouteACJSON": util.GetAtlassianConnectURLPath(), | ||
"ExternalURL": util.GetSiteURL(), | ||
"PluginKey": util.GetPluginKey(), | ||
"SharedSecret": url.QueryEscape(conf.Secret), | ||
} | ||
tmpl, err := template.ParseFiles(tmplPath) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.Header().Set("Content-Type", "application/json") | ||
if err = tmpl.Execute(w, values); err != nil { | ||
http.Error(w, "failed to write response: "+err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.