-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
108 lines (93 loc) · 2.58 KB
/
main.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package main
import (
"dashboard_scripts/folder"
"dashboard_scripts/search"
"log"
"net/http"
"os"
"path/filepath"
"time"
)
var (
endPoint = "http://localhost:3000/api/"
getFolderResultFile = "get_folder_result.json"
getDashboardResultFile = "get_dashboard_result.json"
dashboardDataFolder = "data"
)
func httpClient() *http.Client {
client := &http.Client{Timeout: 10 * time.Second}
return client
}
func getDashboard(c *http.Client, UIDs []string, folderName string) error {
return nil
}
func main() {
// clean up the dashboard folder
err := recreateDataFolder()
if err != nil {
log.Fatalf("Error recreating data folder for dashboards %+v", err)
os.Exit(1)
}
// create http client for sending requests
c := httpClient()
// search folders and store the map of folder UID <-> folder name
var folders *folder.GetResponse
folders, err = folder.GetFolders(c, getFolderResultFile, endPoint)
if err != nil {
log.Fatalf("Error occurred during get folders. %+v", err)
os.Exit(1)
}
// create folders in data according to API response
err = createFoldersInDataRepository(folders, dashboardDataFolder)
if err != nil {
log.Fatalf("Error occurred during create folders in data repository. %+v", err)
os.Exit(1)
}
// get dashboards in folders
for _, folder := range *folders {
var dbsInFolder *search.GetDBsResponse
dbsInFolder, err := search.GetDashboardsInFolder(c, getDashboardResultFile, folder, endPoint, dashboardDataFolder)
if err != nil {
log.Fatalf("Error occurred during search dashboards. %+v", err)
}
for _, dashboard := range *dbsInFolder {
err := getDashboard(c, dashboardDataFolder, folder, dashboard)
if err != nil {
log.Fatalf("Error occurred during get dashboard. %+v", err)
}
}
}
}
func createFoldersInDataRepository(folders *folder.GetResponse, dataFolder string) error {
pwd, err := os.Getwd()
if err != nil {
log.Fatalf("Can't get current repository. %+v", err)
return err
}
for _, folder := range *folders {
err = os.Mkdir(filepath.Join(pwd, dataFolder, folder.UID), 0755)
if err != nil {
log.Fatalf("Can't create folder. %+v", err)
return err
}
}
return nil
}
func recreateDataFolder() error {
pwd, err := os.Getwd()
if err != nil {
log.Fatalf("Can't get current repository. %+v", err)
return err
}
err = os.RemoveAll(filepath.Join(pwd, dashboardDataFolder))
if err != nil {
log.Fatalf("Can't remove folder. %+v", err)
return err
}
err = os.Mkdir(filepath.Join(pwd, dashboardDataFolder), 0755)
if err != nil {
log.Fatalf("Can't create folder. %+v", err)
return err
}
return nil
}