-
Notifications
You must be signed in to change notification settings - Fork 2
/
confluence.go
61 lines (51 loc) · 1.49 KB
/
confluence.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
package common
import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"time"
)
type confluenceProgressResponse struct {
Result string `json:"fileName"`
Progress string `json:"alternativePercentage"`
Message string `json:"currentStatus"`
}
// ConfluenceWaitForBackupReadyness check status of a backup
// and loops until it's ready
func ConfluenceWaitForBackupReadyness(client http.Client, host string) (string, error) {
downloadURL, fileName, status, progress := "", "", "", ""
var err error
for fileName == "" {
downloadURL, fileName, status, progress, err = confluenceCheckBackupProgress(client, host)
if err != nil {
return "", err
}
if fileName == "" {
fmt.Println("Backup is still in progress, status:",
status,
"Progreass:",
progress,
"Retrying in 10s")
time.Sleep(10 * time.Second)
}
}
return downloadURL, nil
}
func confluenceCheckBackupProgress(client http.Client, host string) (string, string, string, string, error) {
var respJSON = new(confluenceProgressResponse)
url := host + "/wiki/rest/obm/1.0/getprogress"
resp, _ := client.Get(url)
body, _ := ioutil.ReadAll(resp.Body)
json.Unmarshal(body, &respJSON)
resp.Body.Close()
if resp.StatusCode != 200 {
return "", "", "", "", errors.New(string(body))
}
return confluenceDownloadURL(respJSON.Result, host), respJSON.Result, respJSON.Message, respJSON.Progress, nil
}
func confluenceDownloadURL(path string, host string) string {
url := host + "/wiki/download/" + path
return url
}