|
4 | 4 | "encoding/json" |
5 | 5 | "fmt" |
6 | 6 | "net/http" |
| 7 | + "strings" |
7 | 8 |
|
8 | 9 | "github.com/jmpsec/osctrl/pkg/nodes" |
9 | 10 | "github.com/jmpsec/osctrl/pkg/types" |
@@ -53,8 +54,9 @@ func (h *HandlersApi) NodeHandler(w http.ResponseWriter, r *http.Request) { |
53 | 54 | } |
54 | 55 | return |
55 | 56 | } |
56 | | - // Serialize and serve JSON |
57 | 57 | log.Debug().Msgf("Returned node %s", nodeVar) |
| 58 | + h.AuditLog.NodeAction(ctx[ctxUser], "viewed node "+nodeVar, strings.Split(r.RemoteAddr, ":")[0], env.ID) |
| 59 | + // Serialize and serve JSON |
58 | 60 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, node) |
59 | 61 | } |
60 | 62 |
|
@@ -93,7 +95,8 @@ func (h *HandlersApi) ActiveNodesHandler(w http.ResponseWriter, r *http.Request) |
93 | 95 | return |
94 | 96 | } |
95 | 97 | // Serialize and serve JSON |
96 | | - log.Debug().Msg("Returned nodes") |
| 98 | + log.Debug().Msg("Returned active nodes") |
| 99 | + h.AuditLog.NodeAction(ctx[ctxUser], "viewed active nodes", strings.Split(r.RemoteAddr, ":")[0], env.ID) |
97 | 100 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, nodes) |
98 | 101 | } |
99 | 102 |
|
@@ -132,7 +135,8 @@ func (h *HandlersApi) InactiveNodesHandler(w http.ResponseWriter, r *http.Reques |
132 | 135 | return |
133 | 136 | } |
134 | 137 | // Serialize and serve JSON |
135 | | - log.Debug().Msg("Returned nodes") |
| 138 | + log.Debug().Msg("Returned inactive nodes") |
| 139 | + h.AuditLog.NodeAction(ctx[ctxUser], "viewed inactive nodes", strings.Split(r.RemoteAddr, ":")[0], env.ID) |
136 | 140 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, nodes) |
137 | 141 | } |
138 | 142 |
|
@@ -171,7 +175,8 @@ func (h *HandlersApi) AllNodesHandler(w http.ResponseWriter, r *http.Request) { |
171 | 175 | return |
172 | 176 | } |
173 | 177 | // Serialize and serve JSON |
174 | | - log.Debug().Msg("Returned nodes") |
| 178 | + log.Debug().Msg("Returned all nodes") |
| 179 | + h.AuditLog.NodeAction(ctx[ctxUser], "viewed all nodes", strings.Split(r.RemoteAddr, ":")[0], env.ID) |
175 | 180 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, nodes) |
176 | 181 | } |
177 | 182 |
|
@@ -213,8 +218,9 @@ func (h *HandlersApi) DeleteNodeHandler(w http.ResponseWriter, r *http.Request) |
213 | 218 | } |
214 | 219 | return |
215 | 220 | } |
| 221 | + log.Debug().Msgf("Deleted node %s", n.UUID) |
| 222 | + h.AuditLog.NodeAction(ctx[ctxUser], "deleted node "+n.UUID, strings.Split(r.RemoteAddr, ":")[0], env.ID) |
216 | 223 | // Serialize and serve JSON |
217 | | - log.Debug().Msgf("Returned node %s", n.UUID) |
218 | 224 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, types.ApiGenericResponse{Message: "node deleted"}) |
219 | 225 | } |
220 | 226 |
|
@@ -262,8 +268,9 @@ func (h *HandlersApi) TagNodeHandler(w http.ResponseWriter, r *http.Request) { |
262 | 268 | apiErrorResponse(w, "error tagging node", http.StatusInternalServerError, err) |
263 | 269 | return |
264 | 270 | } |
265 | | - // Serialize and serve JSON |
266 | 271 | log.Debug().Msgf("Tagged node %s with %s", n.UUID, t.Tag) |
| 272 | + h.AuditLog.NodeAction(ctx[ctxUser], "tagged node "+n.UUID+" with "+t.Tag, strings.Split(r.RemoteAddr, ":")[0], env.ID) |
| 273 | + // Serialize and serve JSON |
267 | 274 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, types.ApiGenericResponse{Message: "node tagged"}) |
268 | 275 | } |
269 | 276 |
|
@@ -298,6 +305,8 @@ func (h *HandlersApi) LookupNodeHandler(w http.ResponseWriter, r *http.Request) |
298 | 305 | } |
299 | 306 | return |
300 | 307 | } |
| 308 | + log.Debug().Msgf("Looked up node %s", l.Identifier) |
| 309 | + h.AuditLog.NodeAction(ctx[ctxUser], "looked up node "+l.Identifier, strings.Split(r.RemoteAddr, ":")[0], n.ID) |
301 | 310 | // Serialize and serve JSON |
302 | 311 | utils.HTTPResponse(w, utils.JSONApplicationUTF8, http.StatusOK, n) |
303 | 312 | } |
0 commit comments