Update libjuju
[osm/N2VC.git] / juju / user.py
1 import logging
2 from dateutil.parser import parse as parse_date
3
4 from . import tag
5
6 log = logging.getLogger(__name__)
7
8
9 class User(object):
10 def __init__(self, controller, user_info):
11 self.controller = controller
12 self._user_info = user_info
13
14 @property
15 def tag(self):
16 return tag.user(self.username)
17
18 @property
19 def username(self):
20 return self._user_info.username
21
22 @property
23 def display_name(self):
24 return self._user_info.display_name
25
26 @property
27 def last_connection(self):
28 return parse_date(self._user_info.last_connection)
29
30 @property
31 def access(self):
32 return self._user_info.access
33
34 @property
35 def date_created(self):
36 return self._user_info.date_created
37
38 @property
39 def enabled(self):
40 return not self._user_info.disabled
41
42 @property
43 def disabled(self):
44 return self._user_info.disabled
45
46 @property
47 def created_by(self):
48 return self._user_info.created_by
49
50 async def set_password(self, password):
51 """Update this user's password.
52 """
53 await self.controller.change_user_password(self.username, password)
54 self._user_info.password = password
55
56 async def grant(self, acl='login'):
57 """Set access level of this user on the controller.
58
59 :param str acl: Access control ('login', 'add-model', or 'superuser')
60 """
61 await self.controller.grant(self.username, acl)
62 self._user_info.access = acl
63
64 async def revoke(self):
65 """Removes all access rights for this user from the controller.
66 """
67 await self.controller.revoke(self.username)
68 self._user_info.access = ''
69
70 async def disable(self):
71 """Disable this user.
72 """
73 await self.controller.disable_user(self.username)
74 self._user_info.disabled = True
75
76 async def enable(self):
77 """Re-enable this user.
78 """
79 await self.controller.enable_user(self.username)
80 self._user_info.disabled = False