heimdall-api-platform 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/lib/clients/http-client.js +296 -0
- package/lib/commons-cache.js +185 -0
- package/lib/commons-const.js +203 -0
- package/lib/commons-elasticsearch.js +49 -0
- package/lib/commons-errors.js +278 -0
- package/lib/commons-opensearch.js +37 -0
- package/lib/commons-splunk.js +105 -0
- package/lib/commons-util.js +669 -0
- package/lib/default-routes-docs.js +141 -0
- package/lib/default-routes-pos.js +111 -0
- package/lib/default-routes-pre.js +151 -0
- package/lib/environment.js +81 -0
- package/lib/factory/api-gateway.js +12 -0
- package/lib/factory/client-factory.js +41 -0
- package/lib/factory/function-factory.js +40 -0
- package/lib/factory/operation-flow-factory.js +64 -0
- package/lib/factory/server-factory.js +15 -0
- package/lib/factory/transformation-function-factory.js +47 -0
- package/lib/handle-route.js +472 -0
- package/lib/index.js +50 -0
- package/lib/jwt-util.js +38 -0
- package/lib/license/license-service.js +27 -0
- package/lib/models/base-context.js +77 -0
- package/lib/models/elastic-index-data.js +76 -0
- package/lib/models/flow-context.js +58 -0
- package/lib/models/flow-indexed.js +62 -0
- package/lib/models/operation-function-indexed.js +22 -0
- package/lib/models/operation-function-transformation-indexed.js +23 -0
- package/lib/models/operation-http-indexed.js +38 -0
- package/lib/models/operation-mock-indexed.js +22 -0
- package/lib/models/route-context.js +69 -0
- package/lib/models/security-route.js +41 -0
- package/lib/models/service-context.js +65 -0
- package/lib/models/service-group.js +15 -0
- package/lib/models/service-route.js +23 -0
- package/lib/models/splunk-data.js +70 -0
- package/lib/operations/abstract-operation.js +73 -0
- package/lib/operations/function.js +143 -0
- package/lib/operations/http.js +286 -0
- package/lib/operations/mock.js +34 -0
- package/lib/operations/monitor-check.js +151 -0
- package/lib/orchestration-flow.js +323 -0
- package/lib/public/redoc.html +152 -0
- package/lib/public/swagger.html +143 -0
- package/lib/router.js +29 -0
- package/lib/security-validation.js +46 -0
- package/lib/services/server.js +211 -0
- package/lib/services/template-monitorcheck-route.js +61 -0
- package/package.json +90 -0
@@ -0,0 +1,77 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Const = require('../commons-const');
|
4
|
+
const { performance } = require('perf_hooks');
|
5
|
+
const Util = require('../commons-util');
|
6
|
+
const _ = require('underscore')
|
7
|
+
|
8
|
+
class BaseContext {
|
9
|
+
|
10
|
+
constructor(uuid, context) {
|
11
|
+
this.uuid = uuid;
|
12
|
+
this.context = context || {};
|
13
|
+
this.statusCode = Const.HTTP_STATUS.OK;
|
14
|
+
//InfoTime
|
15
|
+
this.timers = {
|
16
|
+
created: {
|
17
|
+
at: new Date().toISOString(),
|
18
|
+
ms: performance.now()
|
19
|
+
},
|
20
|
+
started: {
|
21
|
+
at: Util.defaultDateISOString(),
|
22
|
+
ms: 0
|
23
|
+
},
|
24
|
+
finished: {
|
25
|
+
at: Util.defaultDateISOString(),
|
26
|
+
ms: 0
|
27
|
+
},
|
28
|
+
duration: 0
|
29
|
+
};
|
30
|
+
this.error = false;
|
31
|
+
this.executed = false;
|
32
|
+
//Result (Error|Success)
|
33
|
+
this.inputData = {};
|
34
|
+
this.responseHeaders = {};
|
35
|
+
this.result = {};
|
36
|
+
};
|
37
|
+
|
38
|
+
setContext(context) {
|
39
|
+
this.context = context;
|
40
|
+
};
|
41
|
+
|
42
|
+
init() {
|
43
|
+
this.timers.started.ms = performance.now();
|
44
|
+
this.timers.started.at = new Date().toISOString();
|
45
|
+
};
|
46
|
+
|
47
|
+
end() {
|
48
|
+
this.executed = true;
|
49
|
+
this.timers.finished.ms = performance.now();
|
50
|
+
this.timers.finished.at = new Date().toISOString();
|
51
|
+
this.timers.duration = parseFloat((this.timers.finished.ms - this.timers.started.ms).toFixed(4));
|
52
|
+
};
|
53
|
+
|
54
|
+
getResult() {
|
55
|
+
return this.result;
|
56
|
+
};
|
57
|
+
|
58
|
+
//Return JSON to Client
|
59
|
+
getResultJSON() {
|
60
|
+
return Util.stringifyInfo(this.result);
|
61
|
+
}
|
62
|
+
|
63
|
+
setResult(result) {
|
64
|
+
this.result = result || {};
|
65
|
+
};
|
66
|
+
|
67
|
+
addResult(result) {
|
68
|
+
this.result = _.extend(this.result, result);
|
69
|
+
};
|
70
|
+
|
71
|
+
hasResult() {
|
72
|
+
return !(Object.keys(this.result).length === 0 && this.result.constructor === Object);
|
73
|
+
};
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
module.exports = BaseContext;
|
@@ -0,0 +1,76 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
const FlowIndexed = require('./flow-indexed');
|
5
|
+
|
6
|
+
class ElasticIndexData {
|
7
|
+
|
8
|
+
constructor(context) {
|
9
|
+
this.uuid = context.uuid;
|
10
|
+
this.request = {
|
11
|
+
url: {
|
12
|
+
protocol: context.request.secure ? "https:" : "http:",
|
13
|
+
hostname: context.request.hostname,
|
14
|
+
port: context.request.connection.localPort,
|
15
|
+
path: context.request.path,
|
16
|
+
full: `${context.request.secure ? "https:" : "http:"}//${context.request.hostname}${context.request.path}`
|
17
|
+
},
|
18
|
+
socket: {
|
19
|
+
remoteAddress: context.request.socket.remoteAddress,
|
20
|
+
encrypted: context.request.secure
|
21
|
+
},
|
22
|
+
httpVersion: context.request.httpVersion,
|
23
|
+
method: context.request.method,
|
24
|
+
body: Util.stringifyInfo(context.request.body || {}),
|
25
|
+
query: Util.stringifyInfo(context.query || {}),
|
26
|
+
params: Util.stringifyInfo(context.params || {}),
|
27
|
+
headers: context.headers || {}
|
28
|
+
};
|
29
|
+
this.service = {
|
30
|
+
name: context.service.name,
|
31
|
+
description: context.service.description,
|
32
|
+
method: context.service.method,
|
33
|
+
security: context.service.security,
|
34
|
+
indexedResult: context.service.indexedResult,
|
35
|
+
authorizationToken: context.security.authorizationToken || {},
|
36
|
+
responseHeaders: Util.stringifyInfo(context.service.responseHeaders),
|
37
|
+
totalFlows: context.service.flow.length,
|
38
|
+
};
|
39
|
+
|
40
|
+
if (context.service.indexedResult == true ||
|
41
|
+
context.error == true) {
|
42
|
+
this.service.flows = this.generateFlow(context.service.flow, context.service.indexedResult);
|
43
|
+
};
|
44
|
+
|
45
|
+
let result = '';
|
46
|
+
|
47
|
+
if (context.service.indexedResult == true ||
|
48
|
+
context.error == true) {
|
49
|
+
if (context.hasResult())
|
50
|
+
result = Util.stringifyInfo(context.result);
|
51
|
+
};
|
52
|
+
|
53
|
+
this.response = {
|
54
|
+
statusCode: context.response.statusCode,
|
55
|
+
headers: Util.stringifyInfo(context.response.getHeaders()),
|
56
|
+
result: result
|
57
|
+
};
|
58
|
+
|
59
|
+
this.timers = context.timers;
|
60
|
+
};
|
61
|
+
|
62
|
+
generateFlow(flows, indexedResult) {
|
63
|
+
|
64
|
+
let objectFlow = {};
|
65
|
+
|
66
|
+
flows.map((flow, index) => {
|
67
|
+
objectFlow[index + 1] = new FlowIndexed(flow, indexedResult);
|
68
|
+
});
|
69
|
+
|
70
|
+
return objectFlow;
|
71
|
+
|
72
|
+
}
|
73
|
+
|
74
|
+
};
|
75
|
+
|
76
|
+
module.exports = ElasticIndexData;
|
@@ -0,0 +1,58 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const OperationFlowFactory = require('../factory/operation-flow-factory');
|
4
|
+
const BaseContext = require('./base-context');
|
5
|
+
const { v4: uuidv4 } = require('uuid');
|
6
|
+
const Const = require('../commons-const');
|
7
|
+
class FlowContext extends BaseContext {
|
8
|
+
|
9
|
+
constructor(options, context) {
|
10
|
+
|
11
|
+
super(uuidv4(), context);
|
12
|
+
this.resultVariable = options.resultVariable || '.';
|
13
|
+
this.skipErrors = options.skipErrors || false;
|
14
|
+
this.propagateResult = options.propagateResult || false;
|
15
|
+
this.cacheEnable = options.cacheEnable || false;
|
16
|
+
this.condition = this.generateCondition(options);
|
17
|
+
this.validation = options.validation || "true";
|
18
|
+
this.cacheTtl = options.cacheTtl || 0;
|
19
|
+
this.cacheTtlExpression = options.cacheTtlExpression || '';
|
20
|
+
this.cacheName = options.cacheName || '';
|
21
|
+
this.cacheKey = options.cacheKey || '';
|
22
|
+
this.operation = OperationFlowFactory.createOperationByType(options.operation, this);
|
23
|
+
};
|
24
|
+
|
25
|
+
generateCondition(options) {
|
26
|
+
|
27
|
+
let condition = (options.condition || '');
|
28
|
+
|
29
|
+
if (condition.constructor.name == Const.OBJECT_TYPE.OBJECT) {
|
30
|
+
|
31
|
+
condition.whenFail = condition.whenFail || {};
|
32
|
+
|
33
|
+
return {
|
34
|
+
compileExpression: options.condition.compileExpression || "true",
|
35
|
+
whenFail: {
|
36
|
+
responseHeaders: options.condition.whenFail.responseHeaders || {},
|
37
|
+
error: options.condition.whenFail.error || false,
|
38
|
+
result: options.condition.whenFail.result || {},
|
39
|
+
statusCode: options.condition.whenFail.statusCode || 200
|
40
|
+
}
|
41
|
+
};
|
42
|
+
};
|
43
|
+
|
44
|
+
return {
|
45
|
+
compileExpression: condition || "true",
|
46
|
+
whenFail: {
|
47
|
+
responseHeaders: {},
|
48
|
+
error: false,
|
49
|
+
result: {},
|
50
|
+
statusCode: 200
|
51
|
+
}
|
52
|
+
};
|
53
|
+
|
54
|
+
}
|
55
|
+
|
56
|
+
};
|
57
|
+
|
58
|
+
module.exports = FlowContext;
|
@@ -0,0 +1,62 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
const Const = require('../commons-const');
|
5
|
+
const OperationHttpIndexed = require('./operation-http-indexed');
|
6
|
+
const OperationFunctionIndexed = require('./operation-function-indexed');
|
7
|
+
const OperationMockIndexed = require('./operation-mock-indexed');
|
8
|
+
|
9
|
+
class FlowIndexed {
|
10
|
+
|
11
|
+
constructor(flow, indexedResult) {
|
12
|
+
//DADOS GERAIS
|
13
|
+
this.uuid = flow.uuid;
|
14
|
+
this.hasError = flow.error;
|
15
|
+
this.executed = flow.executed;
|
16
|
+
this.statusCode = flow.statusCode;
|
17
|
+
//COMPORTAMENTO
|
18
|
+
this.behavior = {
|
19
|
+
propagateResultToBody: flow.propagateResult,
|
20
|
+
skipErrors: flow.skipErrors,
|
21
|
+
resultVariable: flow.resultVariable,
|
22
|
+
executeConditions: {
|
23
|
+
condition: flow.condition,
|
24
|
+
validation: flow.validation
|
25
|
+
}
|
26
|
+
};
|
27
|
+
//CACHE
|
28
|
+
this.configCache = {
|
29
|
+
enable: flow.cacheEnable,
|
30
|
+
key: flow.cacheKey || '',
|
31
|
+
name: flow.cacheName || '',
|
32
|
+
ttl: flow.cacheTtl
|
33
|
+
};
|
34
|
+
//OPERACAO DO FLOW
|
35
|
+
this.generateType(flow.operation, indexedResult);
|
36
|
+
//RESULTADO
|
37
|
+
this.result = indexedResult ? Util.stringifyInfo(flow.result) : '';
|
38
|
+
//TIMERS
|
39
|
+
this.duration = flow.timers.duration
|
40
|
+
};
|
41
|
+
|
42
|
+
generateType(operation, indexedResult) {
|
43
|
+
|
44
|
+
switch (operation.type) {
|
45
|
+
case Const.FLOW_OPERATION_TYPE.HTTP:
|
46
|
+
this.operationHttp = new OperationHttpIndexed(operation, indexedResult);
|
47
|
+
break
|
48
|
+
case Const.FLOW_OPERATION_TYPE.FUNCTION:
|
49
|
+
this.operationFunction = new OperationFunctionIndexed(operation, indexedResult);
|
50
|
+
break
|
51
|
+
case Const.FLOW_OPERATION_TYPE.MOCK:
|
52
|
+
this.operationMock = new OperationMockIndexed(operation, indexedResult);
|
53
|
+
break
|
54
|
+
default:
|
55
|
+
break;
|
56
|
+
};
|
57
|
+
|
58
|
+
};
|
59
|
+
|
60
|
+
};
|
61
|
+
|
62
|
+
module.exports = FlowIndexed;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
|
5
|
+
class OperationFunctionIndexed {
|
6
|
+
|
7
|
+
constructor(operation, indexedResult) {
|
8
|
+
//DADOS GERAIS
|
9
|
+
this.uuid = operation.uuid;
|
10
|
+
this.name = operation.name;
|
11
|
+
this.type = operation.type;
|
12
|
+
this.sourceCode = operation.sourceCode;
|
13
|
+
this.hasError = operation.error;
|
14
|
+
this.executed = operation.executed;
|
15
|
+
this.statusCode = operation.statusCode;
|
16
|
+
this.result = (indexedResult || operation.error) ? Util.stringifyInfo(operation.result) : '';
|
17
|
+
this.duration = operation.timers.duration
|
18
|
+
};
|
19
|
+
|
20
|
+
};
|
21
|
+
|
22
|
+
module.exports = OperationFunctionIndexed;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
|
5
|
+
class OperationFunctionTransformationIndexed {
|
6
|
+
|
7
|
+
constructor(operation, indexedResult) {
|
8
|
+
//DADOS GERAIS
|
9
|
+
this.uuid = operation.uuid;
|
10
|
+
this.name = operation.name;
|
11
|
+
this.type = operation.type;
|
12
|
+
this.sourceCode = operation.sourceCode;
|
13
|
+
this.hasError = operation.error;
|
14
|
+
this.executed = operation.executed;
|
15
|
+
this.statusCode = operation.statusCode;
|
16
|
+
this.inputData = indexedResult ? Util.stringifyInfo(operation.inputData) : '';
|
17
|
+
this.result = (indexedResult || operation.error) ? Util.stringifyInfo(operation.result) : '';
|
18
|
+
this.duration = operation.timers.duration
|
19
|
+
};
|
20
|
+
|
21
|
+
};
|
22
|
+
|
23
|
+
module.exports = OperationFunctionTransformationIndexed;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
const Const = require('../commons-const');
|
5
|
+
const OperationFuncTransIndexed = require('./operation-function-transformation-indexed');
|
6
|
+
|
7
|
+
class OperationHttpIndexed {
|
8
|
+
|
9
|
+
constructor(operation, indexedResult) {
|
10
|
+
//DADOS GERAIS
|
11
|
+
this.uuid = operation.uuid;
|
12
|
+
this.name = operation.name;
|
13
|
+
this.type = operation.type;
|
14
|
+
this.method = operation.method;
|
15
|
+
this.path = operation.path;
|
16
|
+
this.hasError = operation.error;
|
17
|
+
this.executed = operation.executed;
|
18
|
+
this.statusCode = operation.statusCode;
|
19
|
+
this.headers = operation.headers
|
20
|
+
this.mergedHeaders = operation.mergedHeaders;
|
21
|
+
this.httpConfigClient = Util.stringifyInfo(operation.httpClient);
|
22
|
+
|
23
|
+
this.functions = {
|
24
|
+
headersTransformation: new OperationFuncTransIndexed(operation.headersTransformation, indexedResult),
|
25
|
+
requestTransformation: new OperationFuncTransIndexed(operation.requestTransformation, indexedResult),
|
26
|
+
responseTransformation: new OperationFuncTransIndexed(operation.responseTransformation, indexedResult),
|
27
|
+
onError: new OperationFuncTransIndexed(operation.onError, indexedResult),
|
28
|
+
onSuccess: new OperationFuncTransIndexed(operation.onSuccess, indexedResult),
|
29
|
+
};
|
30
|
+
|
31
|
+
this.result = (indexedResult || operation.error) ? Util.stringifyInfo(operation.result) : '';
|
32
|
+
this.duration = operation.timers.duration
|
33
|
+
|
34
|
+
};
|
35
|
+
|
36
|
+
};
|
37
|
+
|
38
|
+
module.exports = OperationHttpIndexed;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
|
5
|
+
class OperationMockIndexed {
|
6
|
+
|
7
|
+
constructor(operation, indexedResult) {
|
8
|
+
//DADOS GERAIS
|
9
|
+
this.uuid = operation.uuid;
|
10
|
+
this.description = operation.description || '';
|
11
|
+
this.type = operation.type;
|
12
|
+
this.file = operation.file;
|
13
|
+
this.hasError = operation.error;
|
14
|
+
this.executed = operation.executed;
|
15
|
+
this.statusCode = operation.statusCode;
|
16
|
+
this.result = (indexedResult || operation.error) ? Util.stringifyInfo(operation.result) : '';
|
17
|
+
this.duration = operation.timers.duration
|
18
|
+
};
|
19
|
+
|
20
|
+
};
|
21
|
+
|
22
|
+
module.exports = OperationMockIndexed;
|
@@ -0,0 +1,69 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const { v4: uuidv4 } = require('uuid');
|
4
|
+
const _ = require('underscore');
|
5
|
+
const SecurityRoute = require('./security-route');
|
6
|
+
const Const = require('../commons-const');
|
7
|
+
const BaseContext = require('./base-context');
|
8
|
+
const ServiceContext = require('./service-context');
|
9
|
+
const Util = require('../commons-util');
|
10
|
+
|
11
|
+
class RouteContext extends BaseContext {
|
12
|
+
|
13
|
+
//Request e response devem manter a referencia
|
14
|
+
constructor(request, response, next, serviceOptions, orchestrator) {
|
15
|
+
super(uuidv4(), {});
|
16
|
+
this.next = next;
|
17
|
+
this.orchestrator = orchestrator;
|
18
|
+
this.service = new ServiceContext(serviceOptions, this);
|
19
|
+
this.statusCode = this.service.statusCode || Const.HTTP_STATUS.OK;
|
20
|
+
this.security = new SecurityRoute();
|
21
|
+
this.request = request;
|
22
|
+
this.response = response;
|
23
|
+
this.body = Util.underscore().clone(request.body) || {};
|
24
|
+
this.query = Util.underscore().clone(request.query) || {};
|
25
|
+
this.params = _.omit(request.params, Object.keys(request.query)) || {};
|
26
|
+
this.headers = Util.underscore().clone(request.headers) || {};
|
27
|
+
this.attemptsIndex = 0;
|
28
|
+
this.statusCode = Const.HTTP_STATUS.OK
|
29
|
+
};
|
30
|
+
|
31
|
+
setBody(body) {
|
32
|
+
this.body = body;
|
33
|
+
};
|
34
|
+
|
35
|
+
getBody() {
|
36
|
+
return this.body;
|
37
|
+
};
|
38
|
+
|
39
|
+
getHeaders() {
|
40
|
+
this.headers;
|
41
|
+
};
|
42
|
+
|
43
|
+
setHeaders(headers) {
|
44
|
+
_.extend(this.headers, headers);
|
45
|
+
};
|
46
|
+
|
47
|
+
getResponseHeaders() {
|
48
|
+
this.responseHeaders;
|
49
|
+
};
|
50
|
+
|
51
|
+
setResponseHeaders(headers) {
|
52
|
+
_.extend(this.responseHeaders, headers);
|
53
|
+
};
|
54
|
+
|
55
|
+
setParams(params) {
|
56
|
+
_.extend(this.params, params);
|
57
|
+
};
|
58
|
+
|
59
|
+
setQuery(query) {
|
60
|
+
_.extend(this.query, query);
|
61
|
+
};
|
62
|
+
|
63
|
+
getQuery() {
|
64
|
+
return this.query;
|
65
|
+
};
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
module.exports = RouteContext;
|
@@ -0,0 +1,41 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
class SecurityRoute {
|
4
|
+
constructor() {
|
5
|
+
this.encryptionKey = null;
|
6
|
+
this.publicKey = null;
|
7
|
+
this.customerUUID = null;
|
8
|
+
this.devicePublicKeyDisgest = null;
|
9
|
+
this.accessToken = null;
|
10
|
+
this.deviceDNA = null;
|
11
|
+
|
12
|
+
}
|
13
|
+
|
14
|
+
setCustomerUUID(customerUUID) {
|
15
|
+
this.customerUUID = customerUUID;
|
16
|
+
};
|
17
|
+
|
18
|
+
setEncryptionKey(encryptionKey) {
|
19
|
+
this.encryptionKey = encryptionKey;
|
20
|
+
};
|
21
|
+
|
22
|
+
setPublicKey(publicKey) {
|
23
|
+
this.publicKey = publicKey;
|
24
|
+
};
|
25
|
+
|
26
|
+
setDevicePublicKeyDisgest(devicePublicKeyDisgest) {
|
27
|
+
this.devicePublicKeyDisgest = devicePublicKeyDisgest;
|
28
|
+
};
|
29
|
+
|
30
|
+
setAccessToken(accessToken) {
|
31
|
+
this.accessToken = accessToken;
|
32
|
+
};
|
33
|
+
|
34
|
+
setDeviceDNA(deviceDNA) {
|
35
|
+
this.deviceDNA = deviceDNA;
|
36
|
+
};
|
37
|
+
|
38
|
+
}
|
39
|
+
|
40
|
+
|
41
|
+
module.exports = SecurityRoute;
|
@@ -0,0 +1,65 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const FlowContext = require('./flow-context');
|
4
|
+
const BaseContext = require('./base-context');
|
5
|
+
const { v4: uuidv4 } = require('uuid');
|
6
|
+
const _ = require('underscore');
|
7
|
+
|
8
|
+
class ServiceContext extends BaseContext {
|
9
|
+
|
10
|
+
constructor(options, context) {
|
11
|
+
super(uuidv4(), context);
|
12
|
+
this.name = options.name || '';
|
13
|
+
this.description = options.description || '';
|
14
|
+
this.route = options.route || '';
|
15
|
+
this.scope = options.scope;
|
16
|
+
this.method = options.method.toLowerCase() || 'get';
|
17
|
+
this.security = options.security || false;
|
18
|
+
this.responseHeaders = options.responseHeaders || {};
|
19
|
+
this.flow = createFlows(options.flow, this);
|
20
|
+
this.previousFlow = {};
|
21
|
+
this.currentFlow = {
|
22
|
+
getResult: function () { return null }
|
23
|
+
};
|
24
|
+
this.indexedResult = options.indexedResult || false;
|
25
|
+
this.headers = {};
|
26
|
+
this.responseHeaders = options.responseHeaders || {};
|
27
|
+
this.rawOptions = options;
|
28
|
+
this.authScheme = options.authScheme || {};
|
29
|
+
this.parameters = options.parameters || {};
|
30
|
+
this.requestBody = options.requestBody || {};
|
31
|
+
this.responses = options.responses || {};
|
32
|
+
};
|
33
|
+
|
34
|
+
setCurrentFlow(currentFlow) {
|
35
|
+
this.previousFlow = this.currentFlow;
|
36
|
+
this.currentFlow = currentFlow;
|
37
|
+
}
|
38
|
+
|
39
|
+
getCurrentFlow() {
|
40
|
+
return this.currentFlow;
|
41
|
+
};
|
42
|
+
|
43
|
+
getPreviousFlow() {
|
44
|
+
return this.previousFlow;
|
45
|
+
};
|
46
|
+
|
47
|
+
getTotalFlow() {
|
48
|
+
return this.flow.length;
|
49
|
+
};
|
50
|
+
|
51
|
+
addHeaders(headers) {
|
52
|
+
this.headers = _.extend(this.headers, headers);
|
53
|
+
};
|
54
|
+
|
55
|
+
};
|
56
|
+
|
57
|
+
function createFlows(flows, context) {
|
58
|
+
|
59
|
+
return flows.map(flow => {
|
60
|
+
return new FlowContext(flow, context);
|
61
|
+
});
|
62
|
+
|
63
|
+
};
|
64
|
+
|
65
|
+
module.exports = ServiceContext;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
class ServiceGroup {
|
4
|
+
|
5
|
+
constructor(options) {
|
6
|
+
this.description = options.description;
|
7
|
+
this.basePath = options.basePath;
|
8
|
+
this.validatePath = options.validatePath === undefined ? true : false;
|
9
|
+
this.services = options.services;
|
10
|
+
this.version = options.version;
|
11
|
+
};
|
12
|
+
|
13
|
+
}
|
14
|
+
|
15
|
+
module.exports = ServiceGroup;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
class ServiceRoute {
|
4
|
+
|
5
|
+
constructor(options) {
|
6
|
+
//Validate path windows
|
7
|
+
this.path = process.platform === "win32" ? options.path.replace(/\\/g, "/") : options.path;
|
8
|
+
this.security = options.security || false;
|
9
|
+
this.method = options.method.toLowerCase();
|
10
|
+
this.enableUploader = options.enableUploader || false;
|
11
|
+
this.uploadFieldName = options.uploadFieldName || 'file';
|
12
|
+
}
|
13
|
+
|
14
|
+
getPath() {
|
15
|
+
return this.path;
|
16
|
+
};
|
17
|
+
|
18
|
+
getMethod() {
|
19
|
+
return this.method;
|
20
|
+
};
|
21
|
+
}
|
22
|
+
|
23
|
+
module.exports = ServiceRoute;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
const Util = require('../commons-util');
|
4
|
+
const X_AUTHORIZATION = 'x-authorization';
|
5
|
+
|
6
|
+
class SplunkData {
|
7
|
+
|
8
|
+
constructor(context) {
|
9
|
+
this.uuid = context.uuid;
|
10
|
+
this.request = {
|
11
|
+
url: {
|
12
|
+
protocol: context.request.isSecure() ? "https:" : "http:",
|
13
|
+
hostname: context.request.headers.host,
|
14
|
+
port: context.request.connection.localPort,
|
15
|
+
path: context.request.getPath(),
|
16
|
+
full: `${context.request.isSecure() ? "https:" : "http:"}//${context.request.headers.host}${context.request.getPath()}`
|
17
|
+
},
|
18
|
+
socket: {
|
19
|
+
remoteAddress: context.request.socket.remoteAddress,
|
20
|
+
encrypted: context.request.isSecure()
|
21
|
+
},
|
22
|
+
httpVersion: context.request.httpVersion,
|
23
|
+
method: context.request.method,
|
24
|
+
body: Util.stringifyInfo(context.request.body || {}),
|
25
|
+
query: Util.stringifyInfo(context.query || {}),
|
26
|
+
params: Util.stringifyInfo(context.params || {}),
|
27
|
+
headers: this.hideSensitiveHeaders(context.headers) || {}
|
28
|
+
};
|
29
|
+
this.service = {
|
30
|
+
name: context.service.name,
|
31
|
+
description: context.service.description,
|
32
|
+
authorizationToken: context.security.authorizationToken || {}
|
33
|
+
};
|
34
|
+
|
35
|
+
let result = '';
|
36
|
+
if (context.error == true) {
|
37
|
+
|
38
|
+
if (context.hasResult()) {
|
39
|
+
result = Util.stringifyInfo(context.result);
|
40
|
+
}
|
41
|
+
|
42
|
+
};
|
43
|
+
|
44
|
+
this.response = {
|
45
|
+
statusCode: context.response.statusCode,
|
46
|
+
headers: Util.stringifyInfo(context.response.getHeaders()),
|
47
|
+
result: result
|
48
|
+
};
|
49
|
+
|
50
|
+
this.timers = context.timers;
|
51
|
+
};
|
52
|
+
|
53
|
+
hideSensitiveHeaders(headers) {
|
54
|
+
try {
|
55
|
+
|
56
|
+
if (headers.hasOwnProperty(X_AUTHORIZATION)) {
|
57
|
+
let splited_authorization = headers[X_AUTHORIZATION].split(" ");
|
58
|
+
headers[X_AUTHORIZATION] = splited_authorization[0] + " " + Util.replaceCharsForAsterisks(splited_authorization[1]);
|
59
|
+
}
|
60
|
+
|
61
|
+
} catch (error) {
|
62
|
+
Util.error(`Error on hode sensitive headers: ${JSON.stringify(error)}`)
|
63
|
+
}
|
64
|
+
|
65
|
+
return headers;
|
66
|
+
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
module.exports = SplunkData;
|