Added additional validation for slack attachment format on server (#5680)

This commit is contained in:
Harrison Healey
2017-03-08 04:15:33 -05:00
committed by George Goldberg
parent f3a266ee5d
commit 5d62b3661b
6 changed files with 152 additions and 86 deletions

View File

@@ -29,13 +29,13 @@ type IncomingWebhook struct {
}
type IncomingWebhookRequest struct {
Text string `json:"text"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
ChannelName string `json:"channel"`
Props StringInterface `json:"props"`
Attachments interface{} `json:"attachments"`
Type string `json:"type"`
Text string `json:"text"`
Username string `json:"username"`
IconURL string `json:"icon_url"`
ChannelName string `json:"channel"`
Props StringInterface `json:"props"`
Attachments []*SlackAttachment `json:"attachments"`
Type string `json:"type"`
}
func (o *IncomingWebhook) ToJson() string {
@@ -212,31 +212,15 @@ func expandAnnouncement(text string) string {
func expandAnnouncements(i *IncomingWebhookRequest) {
i.Text = expandAnnouncement(i.Text)
if i.Attachments != nil {
attachments := i.Attachments.([]interface{})
for _, attachment := range attachments {
a := attachment.(map[string]interface{})
for _, attachment := range i.Attachments {
attachment.Pretext = expandAnnouncement(attachment.Pretext)
attachment.Text = expandAnnouncement(attachment.Text)
attachment.Title = expandAnnouncement(attachment.Title)
if a["pretext"] != nil {
a["pretext"] = expandAnnouncement(a["pretext"].(string))
}
if a["text"] != nil {
a["text"] = expandAnnouncement(a["text"].(string))
}
if a["title"] != nil {
a["title"] = expandAnnouncement(a["title"].(string))
}
if a["fields"] != nil {
fields := a["fields"].([]interface{})
for _, field := range fields {
f := field.(map[string]interface{})
if f["value"] != nil {
f["value"] = expandAnnouncement(fmt.Sprintf("%v", f["value"]))
}
}
for _, field := range attachment.Fields {
if field.Value != nil {
// Ensure the value is set to a string if it is set
field.Value = expandAnnouncement(fmt.Sprintf("%v", field.Value))
}
}
}