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