-
Notifications
You must be signed in to change notification settings - Fork 627
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Adding new util function for topics validations #495
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,34 @@ | ||
var assert = require('assert'); | ||
var InvalidConfigError = require('./errors/InvalidConfigError'); | ||
var legalChars = new RegExp('^[a-zA-Z0-9._-]*$'); | ||
var allowedTopicLength = 249; | ||
|
||
function validateConfig (property, value) { | ||
if (!legalChars.test(value)) { | ||
throw new InvalidConfigError([property, value, "is illegal, contains a character other than ASCII alphanumerics, '.', '_' and '-'"].join(' ')); | ||
} | ||
} | ||
|
||
function validateCreateTopics (topics) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe rename this to |
||
// Rewriting same validations done by Apache Kafka team for topics | ||
// iterating over topics | ||
topics.some(function (topic) { | ||
if (topic.length <= 0) { | ||
throw new InvalidConfigError('topic name is illegal, cannot be empty'); | ||
} | ||
if (topic === '.' || topic === '..') { | ||
throw new InvalidConfigError('topic name cannot be . or ..'); | ||
} | ||
if (topic.length > allowedTopicLength) { | ||
throw new InvalidConfigError('topic name is illegal, cannot be longer than ' + allowedTopicLength + ' characters'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind changing to a template literal? We support node 4 now. |
||
} | ||
if (!legalChars.test(topic)) { | ||
throw new InvalidConfigError('topic name ' + topic + 'is illegal, contains a character other than ASCII alphanumerics .,_ and -'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. template literal here as well. |
||
} | ||
}); | ||
return true; | ||
} | ||
|
||
function validateTopics (topics) { | ||
if (topics.some(function (topic) { | ||
if ('partition' in topic) { | ||
|
@@ -79,5 +100,6 @@ module.exports = { | |
validateConfig: validateConfig, | ||
validateTopics: validateTopics, | ||
groupPartitionsByTopic: groupPartitionsByTopic, | ||
createTopicPartitionList: createTopicPartitionList | ||
createTopicPartitionList: createTopicPartitionList, | ||
validateCreateTopics: validateCreateTopics | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
?