Implement List user tags
This commit is contained in:
parent
0f67a74d25
commit
1415a93596
4 changed files with 88 additions and 9 deletions
|
|
@ -543,7 +543,7 @@ class Group(BaseModel):
|
|||
|
||||
|
||||
class User(BaseModel):
|
||||
def __init__(self, name, path=None):
|
||||
def __init__(self, name, path=None, tags=None):
|
||||
self.name = name
|
||||
self.id = random_resource_id()
|
||||
self.path = path if path else "/"
|
||||
|
|
@ -556,6 +556,7 @@ class User(BaseModel):
|
|||
self.password = None
|
||||
self.password_reset_required = False
|
||||
self.signing_certificates = {}
|
||||
self.tags = tags
|
||||
|
||||
@property
|
||||
def arn(self):
|
||||
|
|
@ -1421,13 +1422,13 @@ class IAMBackend(BaseBackend):
|
|||
"The group with name {0} cannot be found.".format(group_name)
|
||||
)
|
||||
|
||||
def create_user(self, user_name, path="/"):
|
||||
def create_user(self, user_name, path="/", tags=None):
|
||||
if user_name in self.users:
|
||||
raise IAMConflictException(
|
||||
"EntityAlreadyExists", "User {0} already exists".format(user_name)
|
||||
)
|
||||
|
||||
user = User(user_name, path)
|
||||
user = User(user_name, path, tags)
|
||||
self.users[user_name] = user
|
||||
return user
|
||||
|
||||
|
|
@ -1583,6 +1584,10 @@ class IAMBackend(BaseBackend):
|
|||
user = self.get_user(user_name)
|
||||
return user.policies.keys()
|
||||
|
||||
def list_user_tags(self, user_name):
|
||||
user = self.get_user(user_name)
|
||||
return user.tags
|
||||
|
||||
def put_user_policy(self, user_name, policy_name, policy_json):
|
||||
user = self.get_user(user_name)
|
||||
|
||||
|
|
|
|||
|
|
@ -440,8 +440,8 @@ class IamResponse(BaseResponse):
|
|||
def create_user(self):
|
||||
user_name = self._get_param("UserName")
|
||||
path = self._get_param("Path")
|
||||
|
||||
user = iam_backend.create_user(user_name, path)
|
||||
tags = self._get_multi_param("Tags.member")
|
||||
user = iam_backend.create_user(user_name, path, tags)
|
||||
template = self.response_template(USER_TEMPLATE)
|
||||
return template.render(action="Create", user=user)
|
||||
|
||||
|
|
@ -538,6 +538,12 @@ class IamResponse(BaseResponse):
|
|||
template = self.response_template(LIST_USER_POLICIES_TEMPLATE)
|
||||
return template.render(policies=policies)
|
||||
|
||||
def list_user_tags(self):
|
||||
user_name = self._get_param("UserName")
|
||||
tags = iam_backend.list_user_tags(user_name)
|
||||
template = self.response_template(LIST_USER_TAGS_TEMPLATE)
|
||||
return template.render(user_tags=tags or [])
|
||||
|
||||
def put_user_policy(self):
|
||||
user_name = self._get_param("UserName")
|
||||
policy_name = self._get_param("PolicyName")
|
||||
|
|
@ -1699,6 +1705,23 @@ LIST_USER_POLICIES_TEMPLATE = """<ListUserPoliciesResponse>
|
|||
</ResponseMetadata>
|
||||
</ListUserPoliciesResponse>"""
|
||||
|
||||
LIST_USER_TAGS_TEMPLATE = """<ListUserTagsResponse>
|
||||
<ListUserTagsResult>
|
||||
<Tags>
|
||||
{% for tag in user_tags %}
|
||||
<item>
|
||||
<Key>{{ tag.Key }}</Key>
|
||||
<Value>{{ tag.Value }}</Value>
|
||||
</item>
|
||||
{% endfor %}
|
||||
</Tags>
|
||||
<IsTruncated>false</IsTruncated>
|
||||
</ListUserTagsResult>
|
||||
<ResponseMetadata>
|
||||
<RequestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</RequestId>
|
||||
</ResponseMetadata>
|
||||
</ListUserTagsResponse>"""
|
||||
|
||||
CREATE_ACCESS_KEY_TEMPLATE = """<CreateAccessKeyResponse>
|
||||
<CreateAccessKeyResult>
|
||||
<AccessKey>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue