Last active
September 7, 2021 15:58
-
-
Save dannysofftie/2e03b0db7a66a289f4b7d9245339225d to your computer and use it in GitHub Desktop.
Validate Minio Bucket names.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Rules: