]> 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 // Copyright (C) 2021  Simon Ruderich
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18 package safcm
19
20 import (
21         "encoding/gob"
22         "io/fs"
23 )
24
25 // Messages
26
27 type Msg interface {
28         msg() // unused, only to implement interface
29 }
30
31 type MsgLog struct {
32         Level LogLevel
33         Text  string
34 }
35
36 type MsgInfoReq struct {
37         LogLevel LogLevel
38
39         DetectGroups []string
40 }
41 type MsgInfoResp struct {
42         Goos   string
43         Goarch string
44
45         Output []string
46         Error  string
47 }
48
49 type MsgSyncReq struct {
50         DryRun bool
51         Groups []string // for commands
52
53         Files    map[string]*File
54         Packages []string
55         Services []string
56         Commands []*Command
57 }
58 type MsgSyncResp struct {
59         FileChanges    []FileChange
60         PackageChanges []PackageChange
61         ServiceChanges []ServiceChange
62         CommandChanges []CommandChange
63
64         Error string
65 }
66
67 type MsgQuitReq struct {
68 }
69 type MsgQuitResp struct {
70 }
71
72 func (MsgLog) msg()      {}
73 func (MsgInfoReq) msg()  {}
74 func (MsgInfoResp) msg() {}
75 func (MsgSyncReq) msg()  {}
76 func (MsgSyncResp) msg() {}
77 func (MsgQuitReq) msg()  {}
78 func (MsgQuitResp) msg() {}
79
80 func init() {
81         // Necessary to receive "into" an interface type
82         gob.Register(MsgLog{})
83         gob.Register(MsgInfoReq{})
84         gob.Register(MsgInfoResp{})
85         gob.Register(MsgSyncReq{})
86         gob.Register(MsgSyncResp{})
87         gob.Register(MsgQuitReq{})
88         gob.Register(MsgQuitResp{})
89 }
90
91 // Types used in messages
92
93 type File struct {
94         OrigGroup string // group which provided this file
95
96         Path string
97
98         Mode  fs.FileMode
99         User  string
100         Uid   int //lint:ignore ST1003 UID is too ugly
101         Group string
102         Gid   int //lint:ignore ST1003 GID is too ugly
103
104         Data []byte
105
106         TriggerCommands []string
107 }
108
109 type Command struct {
110         OrigGroup string // group which provided this command
111         Cmd       string
112 }
113
114 type FileChange struct {
115         Path     string
116         Created  bool
117         Old      FileChangeInfo
118         New      FileChangeInfo
119         DataDiff string
120 }
121 type FileChangeInfo struct {
122         Mode  fs.FileMode
123         User  string
124         Uid   int //lint:ignore ST1003 UID is too ugly
125         Group string
126         Gid   int //lint:ignore ST1003 GID is too ugly
127 }
128
129 type PackageChange struct {
130         Name string
131 }
132
133 type ServiceChange struct {
134         Name    string
135         Started bool
136         Enabled bool
137 }
138
139 type CommandChange struct {
140         Command string
141         Trigger string // path which triggered this command (optional)
142         Output  string // stdout and stderr combined
143         Error   string
144 }