MCPcopy
hub / github.com/evilsocket/opensnitch / Serialize

Method Serialize

daemon/rule/rule.go:133–177  ·  view source on GitHub ↗

Serialize translates a Rule to the protocol object

()

Source from the content-addressed store, hash-verified

131
132// Serialize translates a Rule to the protocol object
133func (r *Rule) Serialize() *protocol.Rule {
134 if r == nil {
135 return nil
136 }
137 r.Operator.Lock()
138 defer r.Operator.Unlock()
139
140 created, err := time.Parse(time.RFC3339, r.Created)
141 if err != nil {
142 log.Warning("Error parsing rule Created date (it should be in RFC3339 format): %s (%s)", err, string(r.Name))
143 log.Warning("using current time instead: %s", created)
144 created = time.Now()
145 }
146
147 protoRule := &protocol.Rule{
148 Created: created.Unix(),
149 Name: string(r.Name),
150 Description: string(r.Description),
151 Enabled: bool(r.Enabled),
152 Precedence: bool(r.Precedence),
153 Nolog: bool(r.Nolog),
154 Action: string(r.Action),
155 Duration: string(r.Duration),
156 Operator: &protocol.Operator{
157 Type: string(r.Operator.Type),
158 Sensitive: bool(r.Operator.Sensitive),
159 Operand: string(r.Operator.Operand),
160 Data: string(r.Operator.Data),
161 },
162 }
163 if r.Operator.Type == List {
164 r.Operator.Data = ""
165 for i := 0; i < len(r.Operator.List); i++ {
166 protoRule.Operator.List = append(protoRule.Operator.List,
167 &protocol.Operator{
168 Type: string(r.Operator.List[i].Type),
169 Sensitive: bool(r.Operator.List[i].Sensitive),
170 Operand: string(r.Operator.List[i].Operand),
171 Data: string(r.Operator.List[i].Data),
172 })
173 }
174 }
175
176 return protoRule
177}

Callers

nothing calls this directly

Calls 2

LockMethod · 0.80
UnlockMethod · 0.80

Tested by

no test coverage detected