-
Notifications
You must be signed in to change notification settings - Fork 5
/
gist.go
74 lines (58 loc) · 1.35 KB
/
gist.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"bytes"
"encoding/json"
"io/ioutil"
"net/http"
"regexp"
log "github.com/Sirupsen/logrus"
)
type entry struct {
Content string `json:"content"`
}
type gist struct {
Description string `json:"description"`
Public bool `json:"public"`
Files map[string]entry `json:"files"`
}
type gistResponse struct {
HTML_URL string `json:"html_url"`
}
var (
apiURL = "https://api.github.com/gists"
)
var re = regexp.MustCompile("/\\+[0-9]+")
// filterLogs removes potentially sensitive information from the logfile about to be submitted as part of a bug report.
func filterLogs(logs string) string {
return re.ReplaceAllString(logs, "/+XXXXXXXXX")
}
func (api *textsecureAPI) SubmitDebugLog() (string, error) {
b, err := ioutil.ReadFile(logFile)
if err != nil {
return "", err
}
content := filterLogs(string(b))
f := make(map[string]entry)
f["fname"] = entry{content}
g := gist{
Description: "Debug log",
Public: true,
Files: f,
}
b, err = json.MarshalIndent(&g, "", " ")
if err != nil {
log.Fatal(err)
}
resp, err := http.Post(apiURL, "application/json", bytes.NewReader(b))
if err != nil {
return "", err
}
defer resp.Body.Close()
dec := json.NewDecoder(resp.Body)
r := gistResponse{}
err = dec.Decode(&r)
if err != nil {
return "", err
}
return r.HTML_URL, nil
}