Skip to content

Instantly share code, notes, and snippets.

@dannysofftie
Last active September 7, 2021 15:58
Show Gist options
  • Save dannysofftie/2e03b0db7a66a289f4b7d9245339225d to your computer and use it in GitHub Desktop.
Save dannysofftie/2e03b0db7a66a289f4b7d9245339225d to your computer and use it in GitHub Desktop.
Validate Minio Bucket names.
function isValidBucketName(bucketName) {
if (typeof bucketName !== 'string') return false
// bucket length should be less than and no more than 63
// characters long.
if (bucketName.length < 3 || bucketName.length > 63) {
return false
}
// bucket with successive periods is invalid.
if (bucketName.indexOf('..') > -1) {
return false
}
// bucket cannot have ip address style.
if (bucketName.match(/[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/)) {
return false
}
// bucket should begin with alphabet/number and end with alphabet/number,
// with alphabet/number/.- in the middle.
if (bucketName.match(/^[a-z0-9][a-z0-9.-]+[a-z0-9]$/)) {
return true
}
return false
}
@dannysofftie
Copy link
Author

dannysofftie commented Sep 7, 2021

Rules:

  1. Length should be between 3 and 69 characters,
  2. Names with successive periods are invalid (..),
  3. Cannot have IP address style,
  4. Should begin with alphabet/number and end with alphabet/number (No uppercase)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment