1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | var metrics_1 = require("./metrics");
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | var SecurityService = (function () {
|
12 | function SecurityService(metrics) {
|
13 | this.metrics = metrics;
|
14 | }
|
15 | |
16 |
|
17 |
|
18 |
|
19 |
|
20 | SecurityService.prototype.check = function (check) {
|
21 | return check.check();
|
22 | };
|
23 | |
24 |
|
25 |
|
26 |
|
27 |
|
28 | SecurityService.prototype.checkAndPublishMetric = function (check) {
|
29 | var _this = this;
|
30 | return this.check(check)
|
31 | .then(function (checkResult) { return _this.publishCheckResultMetrics(checkResult); })
|
32 | .then(function (checkMetrics) { return checkMetrics[0]; });
|
33 | };
|
34 | |
35 |
|
36 |
|
37 |
|
38 |
|
39 | SecurityService.prototype.checkMany = function () {
|
40 | var checks = [];
|
41 | for (var _i = 0; _i < arguments.length; _i++) {
|
42 | checks[_i] = arguments[_i];
|
43 | }
|
44 | return Promise.all(checks.map(function (check) { return check.check(); }));
|
45 | };
|
46 | |
47 |
|
48 |
|
49 |
|
50 |
|
51 | SecurityService.prototype.checkManyAndPublishMetric = function () {
|
52 | var _this = this;
|
53 | var checks = [];
|
54 | for (var _i = 0; _i < arguments.length; _i++) {
|
55 | checks[_i] = arguments[_i];
|
56 | }
|
57 | return this.checkMany.apply(this, checks).then(function (checkResults) { return _this.publishCheckResultMetrics.apply(_this, checkResults); });
|
58 | };
|
59 | |
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 | SecurityService.prototype.publishCheckResultMetrics = function () {
|
67 | var results = [];
|
68 | for (var _i = 0; _i < arguments.length; _i++) {
|
69 | results[_i] = arguments[_i];
|
70 | }
|
71 | if (!results || results.length === 0) {
|
72 | return Promise.resolve([]);
|
73 | }
|
74 | var checkResultMetrics = new metrics_1.CheckResultMetrics(results);
|
75 | if (!this.metrics) {
|
76 | return Promise.reject(new Error("Metrics configuration is not available."));
|
77 | }
|
78 | return this.metrics.publish(SecurityService.METRICS_KEY, [checkResultMetrics])
|
79 | .then(function () { return checkResultMetrics.collect(); });
|
80 | };
|
81 | SecurityService.METRICS_KEY = "security";
|
82 | return SecurityService;
|
83 | }());
|
84 | exports.SecurityService = SecurityService;
|
85 |
|
\ | No newline at end of file |