Skip to content

Commit e1738af

Browse files
authored
Governace rules support (#78)
Governance Rules Support
1 parent 2a75f86 commit e1738af

18 files changed

+815
-60
lines changed

dist/dataUtils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ export function isJsonHeader(msg: any): boolean;
2929
export function appendChunk(buf: any, chunk: any): any;
3030
export function computeBodySize(body: any): number;
3131
export function totalChunkLength(chunk1: any, chunk2: any): any;
32+
export function ensureToString(id: any): any;
3233
export { _getUrlFromRequestOptions as getUrlFromRequestOptions, _getEventModelFromRequestAndResponse as getEventModelFromRequestAndResponse, _safeJsonParse as safeJsonParse, _startWithJson as startWithJson, _bodyToBase64 as bodyToBase64, _hashSensitive as hashSensitive };
3334
//# sourceMappingURL=dataUtils.d.ts.map

dist/dataUtils.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formatEventDataAndSave.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/governanceRulesManager.d.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
declare const _exports: GovernanceRulesManager;
2+
export = _exports;
3+
/**
4+
*
5+
* @type Class
6+
*
7+
* */
8+
declare function GovernanceRulesManager(): void;
9+
declare class GovernanceRulesManager {
10+
_lastUpdate: number;
11+
setLogger(logger: any): void;
12+
_logger: any;
13+
log(message: any, details: any): void;
14+
hasRules(): boolean;
15+
shouldFetch(): boolean;
16+
tryGetRules(): Promise<any>;
17+
_cacheRules(rules: any): void;
18+
regexRules: any;
19+
userRulesHashByRuleId: {};
20+
companyRulesHashByRuleId: {};
21+
unidentifiedUserRules: any;
22+
unidentifiedCompanyRules: any;
23+
_getApplicableRegexRules(requestFields: any, requestBody: any): any;
24+
_getApplicableUnidentifiedUserRules(requestFields: any, requestBody: any): any;
25+
_getApplicableUnidentifiedCompanyRules(requestFields: any, requestBody: any): any;
26+
_getApplicableUserRules(configUserRulesValues: any, requestFields: any, requestBody: any): any[];
27+
_getApplicableCompanyRules(configCompanyRulesValues: any, requestFields: any, requestBody: any): any[];
28+
applyRuleList(applicableRules: any, responseHolder: any, configRuleValues: any): any;
29+
governRequest(config: any, userId: any, companyId: any, request: any): {
30+
status: any;
31+
headers: {};
32+
body: any;
33+
blocked_by: any;
34+
};
35+
tryUpdateHash(response: any): void;
36+
_lastSeenHash: any;
37+
}
38+
//# sourceMappingURL=governanceRulesManager.d.ts.map

dist/governanceRulesManager.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/moesifConfigManager.d.ts.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/dataUtils.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ function _getEventModelFromRequestAndResponse(
276276

277277
logData.response = {};
278278
logData.response.time = responseTime;
279-
logData.response.status = (response && response.statusCode) || 599;
279+
logData.response.status = (response && (response.statusCode || response.status)) || 599;
280280
logData.response.headers = assign({}, (response && response.headers) || {});
281281

282282
if (responseBody) {
@@ -375,6 +375,22 @@ function totalChunkLength(chunk1, chunk2) {
375375
return length1 + length2;
376376
}
377377

378+
function ensureToString(id) {
379+
if (typeof id === 'number') {
380+
return String(id);
381+
}
382+
if (typeof id === 'string') {
383+
return id;
384+
}
385+
if (id === null || id === undefined) {
386+
return id;
387+
}
388+
if (typeof id === 'object') {
389+
return String(id);
390+
}
391+
return id;
392+
}
393+
378394
module.exports = {
379395
getUrlFromRequestOptions: _getUrlFromRequestOptions,
380396
getEventModelFromRequestAndResponse: _getEventModelFromRequestAndResponse,
@@ -388,4 +404,5 @@ module.exports = {
388404
appendChunk: appendChunk,
389405
computeBodySize: computeBodySize,
390406
totalChunkLength: totalChunkLength,
407+
ensureToString: ensureToString,
391408
};

lib/formatEventDataAndSave.js

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,12 @@ var timeTookInSeconds = dataUtils.timeTookInSeconds;
1010
var safeJsonParse = dataUtils.safeJsonParse;
1111
var isJsonHeader = dataUtils.isJsonHeader;
1212
var computeBodySize = dataUtils.computeBodySize;
13+
var ensureToString = dataUtils.ensureToString;
1314

1415
const TRANSACTION_ID_HEADER = 'x-moesif-transaction-id';
1516

1617
var ensureValidLogData = ensureValidUtils.ensureValidLogData;
1718

18-
function ensureToString(id) {
19-
if (typeof id === 'number') {
20-
return String(id);
21-
}
22-
if (typeof id === 'string') {
23-
return id;
24-
}
25-
if (id === null || id === undefined) {
26-
return id;
27-
}
28-
if (typeof id === 'object') {
29-
return String(id);
30-
}
31-
return id;
32-
}
33-
34-
3519
function decodeHeaders(header) {
3620
try {
3721
var keyVal = header.split('\r\n');
@@ -159,9 +143,14 @@ function formatEventDataAndSave(responseBodyBuffer, req, res, options, saveEvent
159143
res._moHeaders = safeGetResponseHeaders(res);
160144
logData.response.headers = res._moHeaders;
161145
logData.response.time = res._endTime;
146+
// if _mo_blocked_by not exist, it will be undefined anyways.
147+
logData.blockedBy = res._mo_blocked_by;
162148

163149
if (options.logBody) {
164-
if (responseBodyBuffer) {
150+
if (res._mo_blocked_by) {
151+
// blocked body is always json
152+
logData.body = res._mo_blocked_body;
153+
} else if (responseBodyBuffer) {
165154
logMessage(options.debug, 'formatEventDataAndSave', 'processing responseBodyBuffer');
166155
if (responseBodyBuffer.length < options.responseMaxBodySize) {
167156
if (isJsonHeader(res) || startWithJson(responseBodyBuffer)) {

0 commit comments

Comments
 (0)