Skip to content

Commit 75de507

Browse files
committed
fix: change to new joi syntax
1 parent cee570e commit 75de507

7 files changed

+494
-97
lines changed

lib/deploy/stepFunctions/compileAlarms.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const _ = require('lodash');
44
const BbPromise = require('bluebird');
5-
const Joi = require('joi');
65
const schema = require('./compileAlarms.schema');
76
const logger = require('../../utils/logger');
87

@@ -142,17 +141,17 @@ function validateConfig(serverless, stateMachineName, alarmsObj) {
142141
return false;
143142
}
144143

145-
Joi.validate(alarmsObj, schema, { allowUnknown: false }, (err) => {
146-
if (err) {
147-
logger.log(
148-
`State machine [${stateMachineName}] : alarms config is malformed. `
149-
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
150-
+ `${err}`,
151-
);
152-
return false;
153-
}
154-
return true;
155-
});
144+
const { error } = schema.validate(alarmsObj, { allowUnknown: false });
145+
146+
if (error) {
147+
logger.log(
148+
`State machine [${stateMachineName}] : alarms config is malformed. `
149+
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
150+
+ `${error}`,
151+
);
152+
return false;
153+
}
154+
156155
return true;
157156
}
158157

lib/deploy/stepFunctions/compileAlarms.schema.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const arn = Joi.alternatives().try(
1515
),
1616
}),
1717
Joi.object().keys({
18-
'Fn::Join': Joi.array().items([
18+
'Fn::Join': Joi.array().items(
1919
Joi.string(),
20-
Joi.array().items([
20+
Joi.array().items(
2121
Joi.string(),
2222
Joi.object().keys({
2323
Ref: Joi.string(),
2424
}),
25-
]),
26-
]),
25+
),
26+
),
2727
}),
2828
);
2929

lib/deploy/stepFunctions/compileNotifications.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const _ = require('lodash');
4-
const Joi = require('joi');
54
const crypto = require('crypto');
65
const BbPromise = require('bluebird');
76
const schema = require('./compileNotifications.schema');
@@ -326,18 +325,18 @@ function validateConfig(serverless, stateMachineName, stateMachineObj, notificat
326325
return false;
327326
}
328327

329-
Joi.validate(notificationsObj, schema, { allowUnknown: false }, (err) => {
330-
if (err) {
331-
logger.log(
332-
`State machine [${stateMachineName}] : notifications config is malformed. `
333-
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
334-
+ `${err}`,
335-
);
336-
return false;
337-
}
328+
const { error } = schema.validate(
329+
notificationsObj, { allowUnknown: false },
330+
);
338331

339-
return true;
340-
});
332+
if (error) {
333+
logger.log(
334+
`State machine [${stateMachineName}] : notifications config is malformed. `
335+
+ 'Please see https://github.com/horike37/serverless-step-functions for examples. '
336+
+ `${error}`,
337+
);
338+
return false;
339+
}
341340

342341
return true;
343342
}

lib/deploy/stepFunctions/compileNotifications.schema.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const arn = Joi.alternatives().try(
99
'Fn::GetAtt': Joi.array().items(Joi.string()),
1010
}),
1111
Joi.object().keys({
12-
'Fn::Join': Joi.array().items([
12+
'Fn::Join': Joi.array().items(
1313
Joi.string(),
14-
Joi.array().items([
14+
Joi.array().items(
1515
Joi.string(),
1616
Joi.object().keys({
1717
Ref: Joi.string(),
1818
}),
19-
]),
20-
]),
19+
),
20+
),
2121
}),
2222
);
2323

lib/deploy/stepFunctions/compileStateMachines.js

+12-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict';
22

33
const _ = require('lodash');
4-
const Joi = require('joi');
54
const aslValidator = require('asl-validator');
65
const BbPromise = require('bluebird');
76
const crypto = require('crypto');
@@ -107,17 +106,13 @@ module.exports = {
107106
} else {
108107
Tags = toTags(this.serverless.service.provider.tags);
109108
}
110-
let validationValue;
111-
Joi.validate(stateMachineObj, schema, { allowUnknown: false }, (err, value) => {
112-
if (err) {
113-
const errorMessage = `State machine [${stateMachineName}] is malformed. `
109+
const { error, value } = schema.validate(stateMachineObj, { allowUnknown: false });
110+
if (error) {
111+
const errorMessage = `State machine [${stateMachineName}] is malformed. `
114112
+ 'Please check the README for more info. '
115-
+ `${err}`;
116-
throw new this.serverless.classes.Error(errorMessage);
117-
} else {
118-
validationValue = value;
119-
}
120-
});
113+
+ `${error}`;
114+
throw new this.serverless.classes.Error(errorMessage);
115+
}
121116

122117
if (stateMachineObj.definition) {
123118
if (this.serverless.service.stepFunctions.validate) {
@@ -204,23 +199,23 @@ module.exports = {
204199
_.forEach(stateMachineTags, tag => Tags.push(tag));
205200
}
206201

207-
if (validationValue.loggingConfig) {
208-
const Destinations = (validationValue.loggingConfig.destinations || [])
202+
if (value.loggingConfig) {
203+
const Destinations = (value.loggingConfig.destinations || [])
209204
.map(arn => ({
210205
CloudWatchLogsLogGroup: {
211206
LogGroupArn: arn,
212207
},
213208
}));
214209
LoggingConfiguration = {
215-
Level: validationValue.loggingConfig.level,
216-
IncludeExecutionData: validationValue.loggingConfig.includeExecutionData,
210+
Level: value.loggingConfig.level,
211+
IncludeExecutionData: value.loggingConfig.includeExecutionData,
217212
Destinations,
218213
};
219214
}
220215

221-
if (validationValue.tracingConfig) {
216+
if (value.tracingConfig) {
222217
TracingConfiguration = {
223-
Enabled: validationValue.tracingConfig.enabled,
218+
Enabled: value.tracingConfig.enabled,
224219
};
225220
}
226221

lib/deploy/stepFunctions/compileStateMachines.schema.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ const arn = Joi.alternatives().try(
1515
),
1616
}),
1717
Joi.object().keys({
18-
'Fn::Join': Joi.array().items([
18+
'Fn::Join': Joi.array().items(
1919
Joi.string(),
20-
Joi.array().items([
20+
Joi.array().items(
2121
Joi.string(),
2222
Joi.object().keys({
2323
Ref: Joi.string(),
2424
}),
25-
]),
26-
]),
25+
),
26+
),
2727
}),
2828
);
2929

0 commit comments

Comments
 (0)