-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
42 lines (31 loc) · 876 Bytes
/
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
package main
import (
"encoding/json"
"github.com/gate-nss-cache/config"
"github.com/gate-nss-cache/gate"
"github.com/gate-nss-cache/nss_cache"
)
const PasswdCacheFilePath = "/etc/passwd.cache"
const GroupCacheFilePath = "/etc/group.cache"
func main() {
config.Load()
usersData, err := gate.GetResponse(config.UserURL())
handleError(err)
users := make([]nss_cache.User, 0)
err = json.Unmarshal([]byte(usersData), &users)
handleError(err)
err = nss_cache.UpdatePasswdCacheFile(PasswdCacheFilePath, users)
handleError(err)
groupsData, err := gate.GetResponse(config.GroupURL())
handleError(err)
groups := make([]nss_cache.Group, 0)
err = json.Unmarshal([]byte(groupsData), &groups)
handleError(err)
err = nss_cache.UpdateGroupCacheFile(GroupCacheFilePath, groups)
handleError(err)
}
func handleError(err error) {
if err != nil {
panic(err)
}
}