|
1 | 1 | 'use strict'; |
2 | 2 |
|
3 | | -const _ = require('lodash'); |
4 | | -const error = require('../lib/error'); |
5 | | -const proxyHostModel = require('../models/proxy_host'); |
6 | | -const internalHost = require('./host'); |
| 3 | +const _ = require('lodash'); |
| 4 | +const error = require('../lib/error'); |
| 5 | +const proxyHostModel = require('../models/proxy_host'); |
| 6 | +const internalHost = require('./host'); |
| 7 | +const internalAuditLog = require('./audit-log'); |
7 | 8 |
|
8 | 9 | function omissions () { |
9 | 10 | return ['is_deleted']; |
@@ -49,7 +50,16 @@ const internalProxyHost = { |
49 | 50 | .insertAndFetch(data); |
50 | 51 | }) |
51 | 52 | .then(row => { |
52 | | - return _.omit(row, omissions()); |
| 53 | + // Add to audit log |
| 54 | + return internalAuditLog.add(access, { |
| 55 | + action: 'created', |
| 56 | + object_type: 'proxy-host', |
| 57 | + object_id: row.id, |
| 58 | + meta: data |
| 59 | + }) |
| 60 | + .then(() => { |
| 61 | + return _.omit(row, omissions()); |
| 62 | + }); |
53 | 63 | }); |
54 | 64 | }, |
55 | 65 |
|
@@ -97,7 +107,17 @@ const internalProxyHost = { |
97 | 107 | .patchAndFetchById(row.id, data) |
98 | 108 | .then(saved_row => { |
99 | 109 | saved_row.meta = internalHost.cleanMeta(saved_row.meta); |
100 | | - return _.omit(saved_row, omissions()); |
| 110 | + |
| 111 | + // Add to audit log |
| 112 | + return internalAuditLog.add(access, { |
| 113 | + action: 'updated', |
| 114 | + object_type: 'proxy-host', |
| 115 | + object_id: row.id, |
| 116 | + meta: data |
| 117 | + }) |
| 118 | + .then(() => { |
| 119 | + return _.omit(saved_row, omissions()); |
| 120 | + }); |
101 | 121 | }); |
102 | 122 | }); |
103 | 123 | }, |
@@ -171,6 +191,17 @@ const internalProxyHost = { |
171 | 191 | .where('id', row.id) |
172 | 192 | .patch({ |
173 | 193 | is_deleted: 1 |
| 194 | + }) |
| 195 | + .then(() => { |
| 196 | + // Add to audit log |
| 197 | + row.meta = internalHost.cleanMeta(row.meta); |
| 198 | + |
| 199 | + return internalAuditLog.add(access, { |
| 200 | + action: 'deleted', |
| 201 | + object_type: 'proxy-host', |
| 202 | + object_id: row.id, |
| 203 | + meta: _.omit(row, omissions()) |
| 204 | + }); |
174 | 205 | }); |
175 | 206 | }) |
176 | 207 | .then(() => { |
@@ -200,7 +231,15 @@ const internalProxyHost = { |
200 | 231 | }); |
201 | 232 | }) |
202 | 233 | .then(row => { |
203 | | - return _.pick(row.meta, internalHost.allowed_ssl_files); |
| 234 | + return internalAuditLog.add(access, { |
| 235 | + action: 'updated', |
| 236 | + object_type: 'proxy-host', |
| 237 | + object_id: row.id, |
| 238 | + meta: data |
| 239 | + }) |
| 240 | + .then(() => { |
| 241 | + return _.pick(row.meta, internalHost.allowed_ssl_files); |
| 242 | + }); |
204 | 243 | }); |
205 | 244 | }, |
206 | 245 |
|
|
0 commit comments