|
1 | 1 | 'use strict';
|
2 | 2 | const _ = require('lodash');
|
3 | 3 | const BbPromise = require('bluebird');
|
| 4 | +const Joi = require('@hapi/joi'); |
| 5 | +const schema = require('./compileAlarms.schema'); |
4 | 6 |
|
5 | 7 | const cloudWatchMetricNames = {
|
6 | 8 | executionsTimeOut: 'ExecutionsTimeOut',
|
@@ -85,29 +87,13 @@ function validateConfig(serverless, stateMachineName, alarmsObj) {
|
85 | 87 | return false;
|
86 | 88 | }
|
87 | 89 |
|
88 |
| - // metrics can be either short form (e.g. "executionsTimeOut") or |
89 |
| - // long form, which allows you to optionally specify treatMissingData override, e.g. |
90 |
| - // { "metric": "executionsTimeOut", "treatMissingData": "ignore" } |
91 |
| - const validateMetric = x => |
92 |
| - _.isString(x) || |
93 |
| - (_.isObject(x) && _.has(x, 'metric') && _.isString(x.metric)); |
| 90 | + const { error } = Joi.validate(alarmsObj, schema, { allowUnknown: false }); |
94 | 91 |
|
95 |
| - if (!_.isObject(alarmsObj.topics) || |
96 |
| - !_.isArray(alarmsObj.metrics) || |
97 |
| - !_.every(alarmsObj.metrics, validateMetric)) { |
| 92 | + if (error) { |
98 | 93 | serverless.cli.consoleLog(
|
99 |
| - `state machine [${stateMachineName}] : alarms config is malformed. ` + |
100 |
| - 'Please see https://github.com/horike37/serverless-step-functions for examples'); |
101 |
| - return false; |
102 |
| - } |
103 |
| - |
104 |
| - if (!_.has(alarmsObj.topics, 'ok') && |
105 |
| - !_.has(alarmsObj.topics, 'alarm') && |
106 |
| - !_.has(alarmsObj.topics, 'insufficientData')) { |
107 |
| - serverless.cli.consoleLog( |
108 |
| - `state machine [${stateMachineName}] : alarms config is malformed. ` + |
109 |
| - "alarms.topics must specify 'ok', 'alarms' or 'insufficientData'" |
110 |
| - ); |
| 94 | + `State machine [${stateMachineName}] : alarms config is malformed. ` + |
| 95 | + 'Please see https://github.com/horike37/serverless-step-functions for examples. ' + |
| 96 | + `${error}`); |
111 | 97 | return false;
|
112 | 98 | }
|
113 | 99 |
|
|
0 commit comments