-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a validator for ELB names #615
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 |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
from troposphere.validators import positive_integer, network_port | ||
from troposphere.validators import s3_bucket_name, encoding, status | ||
from troposphere.validators import iam_path, iam_names, iam_role_name | ||
from troposphere.validators import iam_group_name, iam_user_name | ||
from troposphere.validators import iam_group_name, iam_user_name, elb_name | ||
|
||
|
||
class TestValidators(unittest.TestCase): | ||
|
@@ -73,6 +73,14 @@ def test_s3_bucket_name(self): | |
with self.assertRaises(ValueError): | ||
s3_bucket_name(b) | ||
|
||
def test_elb_name(self): | ||
for b in ['a', 'a'*32, 'wick3d-elb-name', 'Wick3d-ELB-Name']: | ||
elb_name(b) | ||
for b in ['a'*63, 'invalid_elb', '-invalid-elb', | ||
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. Probably want 'a'*33 instead of 63. Add 'a-' as well. 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. Good catch. Copy pasta. Fixed and expanded in 9b55342 |
||
'invalid-elb-', '-elb-']: | ||
with self.assertRaises(ValueError): | ||
elb_name(b) | ||
|
||
def test_encoding(self): | ||
for e in ['plain', 'base64']: | ||
encoding(e) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,14 @@ def s3_bucket_name(b): | |
raise ValueError("%s is not a valid s3 bucket name" % b) | ||
|
||
|
||
def elb_name(b): | ||
elb_name_re = compile(r'^[a-zA-Z0-9][a-zA-Z0-9\-]{0,30}[a-zA-Z0-9]{1}$') | ||
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. Try something like this:
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. This worked! Nice call. I've added it here: 9b55342 I tested manually a bit on http://pythex.org/ just for context. |
||
if elb_name_re.match(b): | ||
return b | ||
else: | ||
raise ValueError("%s is not a valid elb name" % b) | ||
|
||
|
||
def encoding(encoding): | ||
valid_encodings = ['plain', 'base64'] | ||
if encoding not in valid_encodings: | ||
|
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.
Given the regex you might want to add:
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.
Added in 9b55342