-
Notifications
You must be signed in to change notification settings - Fork 0
/
noi-sd-ws.go
69 lines (54 loc) · 1.28 KB
/
noi-sd-ws.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
// SPDX-FileCopyrightText: NOI Techpark <[email protected]>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
package main
import (
"database/sql"
"fmt"
_ "github.com/mattn/go-sqlite3"
"log"
"noi-sd-ws/utils"
"noi-sd-ws/webservices"
"os"
"path/filepath"
)
func main() {
utils.Log("NOI SD webservice 1.00")
// open SQLite DB, load secrets and print jobs table stats
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "usage: %s <SQLlite.db>", filepath.Base(os.Args[0]))
os.Exit(1)
}
webservices.DBName = os.Args[1]
db, err := sql.Open("sqlite3", webservices.DBName)
if err != nil {
log.Fatal(err)
}
rows, err := db.Query("select kind, secret from secrets")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var kind, secret string
err = rows.Scan(&kind, &secret)
if err == nil {
webservices.Secrets[kind] = secret
}
}
utils.Log(fmt.Sprintf("database: %d secrets read", len(webservices.Secrets)))
rows, err = db.Query("select state, count(*) as c from jobs group by state order by state")
if err != nil {
log.Fatal(err)
}
for rows.Next() {
var state string
var c int64
err = rows.Scan(&state, &c)
if err == nil {
utils.Log(fmt.Sprintf("database: %d jobs in state '%s'", c, state))
}
}
db.Close()
// spawn web services
webservices.Spawn()
}