]> ruderich.org/simon Gitweb - safcm/safcm.git/blob - types.go
Use SPDX license identifiers
[safcm/safcm.git] / types.go
1 // RPC primitives for safcm: message and additional types
2
3 // SPDX-License-Identifier: GPL-3.0-or-later
4 // Copyright (C) 2021-2024  Simon Ruderich
5
6 package safcm
7
8 import (
9         "encoding/gob"
10         "io/fs"
11 )
12
13 // Messages
14
15 type Msg interface {
16         msg() // unused, only to implement interface
17 }
18
19 type MsgLog struct {
20         Level LogLevel
21         Text  string
22 }
23
24 type MsgInfoReq struct {
25         LogLevel LogLevel
26
27         DetectGroups []string
28 }
29 type MsgInfoResp struct {
30         Goos   string
31         Goarch string
32
33         Output []string
34         Error  string
35 }
36
37 type MsgSyncReq struct {
38         DryRun bool
39         Groups []string // for commands
40
41         Files    map[string]*File
42         Packages []string
43         Services []string
44         Commands []*Command
45 }
46 type MsgSyncResp struct {
47         FileChanges    []FileChange
48         PackageChanges []PackageChange
49         ServiceChanges []ServiceChange
50         CommandChanges []CommandChange
51
52         Error string
53 }
54
55 type MsgQuitReq struct {
56 }
57 type MsgQuitResp struct {
58 }
59
60 func (MsgLog) msg()      {}
61 func (MsgInfoReq) msg()  {}
62 func (MsgInfoResp) msg() {}
63 func (MsgSyncReq) msg()  {}
64 func (MsgSyncResp) msg() {}
65 func (MsgQuitReq) msg()  {}
66 func (MsgQuitResp) msg() {}
67
68 func init() {
69         // Necessary to receive "into" an interface type
70         gob.Register(MsgLog{})
71         gob.Register(MsgInfoReq{})
72         gob.Register(MsgInfoResp{})
73         gob.Register(MsgSyncReq{})
74         gob.Register(MsgSyncResp{})
75         gob.Register(MsgQuitReq{})
76         gob.Register(MsgQuitResp{})
77 }
78
79 // Types used in messages
80
81 type File struct {
82         OrigGroup string // group which provided this file
83
84         Path string
85
86         Mode  fs.FileMode
87         User  string
88         Uid   int //lint:ignore ST1003 UID is too ugly
89         Group string
90         Gid   int //lint:ignore ST1003 GID is too ugly
91
92         Data []byte
93
94         TriggerCommands []string
95 }
96
97 type Command struct {
98         OrigGroup string // group which provided this command
99         Cmd       string
100 }
101
102 type FileChange struct {
103         Path     string
104         Created  bool
105         Old      FileChangeInfo
106         New      FileChangeInfo
107         DataDiff string
108 }
109 type FileChangeInfo struct {
110         Mode  fs.FileMode
111         User  string
112         Uid   int //lint:ignore ST1003 UID is too ugly
113         Group string
114         Gid   int //lint:ignore ST1003 GID is too ugly
115 }
116
117 type PackageChange struct {
118         Name string
119 }
120
121 type ServiceChange struct {
122         Name    string
123         Started bool
124         Enabled bool
125 }
126
127 type CommandChange struct {
128         Command string
129         Trigger string // path which triggered this command (optional)
130         Output  string // stdout and stderr combined
131         Error   string
132 }