When trying to update the order of execution of rules validation fails if a previous version of a rule used the same order of a different rule in the new deployment.
2016-06-28T23:45:55.282Z - Updating rules...
2016-06-28T23:45:56.424Z - Existing rules: [
{
"id": "rul_TwHwyUjWKAGf6Cug",
"name": "set-country",
"stage": "login_success",
"order": 1
},
{
"id": "rul_WSRAraMQOsTbNWbl",
"name": "log-to-console",
"stage": "login_success",
"order": 2
},
{
"id": "rul_3lbUoWicsc07nUx0",
"name": "require-complex-password",
"stage": "user_registration",
"order": 1
}
]
2016-06-28T23:45:56.425Z - Processing rule 'log-to-console'
2016-06-28T23:45:56.425Z - Updating rule log-to-console (rul_WSRAraMQOsTbNWbl): {
"enabled": true,
"order": 1,
"script": "function (user, context, callback) {\n console.log(JSON.stringify({ user: user, context: context }, null, 2));\n callback(null, user, context);\n}\n"
}
2016-06-28T23:45:56.426Z - Processing rule 'require-complex-password'
2016-06-28T23:45:56.426Z - Updating rule require-complex-password (rul_3lbUoWicsc07nUx0): {
"enabled": false,
"script": "function (ctx, cb) {\n\tif (!ctx.user.password || ctx.user.password.length < 8) {\n\t\treturn cb(new UnauthorizedError('Password does not match the password policy.'));\n\t};\n\n\tcb(null, ctx);\n}\n"
}
2016-06-28T23:45:56.428Z - Processing rule 'set-country'
2016-06-28T23:45:56.428Z - Updating rule set-country (rul_TwHwyUjWKAGf6Cug): {
"enabled": false,
"order": 2,
"script": "function (user, context, callback) {\n\tif (context.request.geoip) {\n\t\tuser.country = context.request.geoip.country_name;\n\t}\n\tcallback(null, user, context);\n}\n"
}
2016-06-28T23:45:57.372Z - Error: A rule with the same order already exists
This error comes from the management API and because rules are updated one at a time with previous rules still being active.
The simple thign to do is delete all existing rules before creating the ones present in the repo since trying to solve order before updating the rules may be too complicated.