Skip to content

Commit

Permalink
support "UserName" attribute for AWS::IAM::User, as per http://docs.a…
Browse files Browse the repository at this point in the history
  • Loading branch information
hypertext418 authored and covataamos committed Oct 24, 2016
1 parent ca3c780 commit b861b0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion troposphere/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from . import AWSObject, AWSProperty
from .validators import integer, boolean, status
from .validators import iam_path, iam_role_name, iam_group_name
from .validators import iam_path, iam_role_name, iam_group_name, iam_user_name

try:
from awacs.aws import Policy
Expand Down Expand Up @@ -103,6 +103,7 @@ class User(AWSObject):
'ManagedPolicyArns': ([basestring], False),
'LoginProfile': (LoginProfile, False),
'Policies': ([Policy], False),
'UserName': (iam_user_name, False),
}


Expand Down
14 changes: 14 additions & 0 deletions troposphere/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def iam_names(b):
raise ValueError("%s is not a valid iam name" % b)


def iam_user_name(user_name):
if len(user_name) > 64:
raise ValueError(
"AWS::IAM::User property 'UserName' may not exceed 64 characters")

iam_user_name_re = compile(r'^[\w+=,.@-]+$')
if iam_user_name_re.match(user_name):
return user_name
else:
raise ValueError(
"%s is not a valid value for AWS::IAM::User property 'UserName'",
user_name)


def iam_path(path):
if len(path) > 512:
raise ValueError('IAM path %s may not exceed 512 characters', path)
Expand Down

0 comments on commit b861b0b

Please sign in to comment.