-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathjob_update_logs.go
67 lines (55 loc) · 1.1 KB
/
job_update_logs.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
package jobs
import (
"encoding/json"
"errors"
"log"
"net/http"
"github.com/bgentry/que-go"
"github.com/jackc/pgx"
)
const (
StateActive = 0
StateIgnore = 1
)
const (
KeyUpdateLogs = "cron_update_logs"
KnownLogsURL = "https://www.gstatic.com/ct/log_list/all_logs_list.json"
)
type CTLog struct {
URL string `json:"url"`
DisqualifiedAt int64 `json:"disqualified_at"`
FinalSTH *struct {
TreeSize int64 `json:"tree_size"`
} `json:"final_sth"`
}
func UpdateCTLogList(qc *que.Client, logger *log.Logger, job *que.Job, tx *pgx.Tx) error {
resp, err := http.Get(KnownLogsURL)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return errors.New("bad status code")
}
var logData struct {
Logs []*CTLog `json:"logs"`
}
err = json.NewDecoder(resp.Body).Decode(&logData)
if err != nil {
return err
}
for _, l := range logData.Logs {
bb, err := json.Marshal(l)
if err != nil {
return err
}
err = qc.EnqueueInTx(&que.Job{
Type: KeyNewLogMetadata,
Args: bb,
}, tx)
if err != nil {
return err
}
}
return nil
}