some simplifications

This commit is contained in:
Michael Hudson-Doyle 2018-05-09 14:35:47 +12:00
parent 3d5efcaf9c
commit bdf3861e5c
2 changed files with 13 additions and 39 deletions

View File

@ -43,7 +43,6 @@ class IdentityController(BaseController):
'username': self.answers['username'], 'username': self.answers['username'],
'hostname': self.answers['hostname'], 'hostname': self.answers['hostname'],
'password': self.answers['password'], 'password': self.answers['password'],
'confirm_password': self.answers['password'],
'ssh_import_id': self.answers.get('ssh-import-id', ''), 'ssh_import_id': self.answers.get('ssh-import-id', ''),
} }
self.done(d) self.done(d)

View File

@ -14,44 +14,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
import attr
from subiquitycore.utils import crypt_password from subiquitycore.utils import crypt_password
log = logging.getLogger('subiquitycore.models.identity') log = logging.getLogger('subiquitycore.models.identity')
class LocalUser(object): @attr.s
def __init__(self, result): class User(object):
self._realname = result.get('realname') realname = attr.ib()
self._username = result.get('username') username = attr.ib()
self._password = result.get('password') password = attr.ib()
self._cpassword = result.get('confirm_password') ssh_import_id = attr.ib(default=None)
self._ssh_import_id = None
if 'ssh_import_id' in result:
self._ssh_import_id = result.get('ssh_import_id')
@property
def realname(self):
return self._realname
@property
def username(self):
return self._username
@property
def password(self):
return self._password
@property
def cpassword(self):
return self._cpassword
@property
def ssh_import_id(self):
return self._ssh_import_id
def __repr__(self):
return "%s <%s>" % (self._realname, self._username)
class IdentityModel(object): class IdentityModel(object):
@ -63,11 +40,9 @@ class IdentityModel(object):
self._hostname = None self._hostname = None
def add_user(self, result): def add_user(self, result):
if result: result = result.copy()
self._user = LocalUser(result) self._hostname = result.pop('hostname')
self._hostname = result.get('hostname') self._user = User(**result)
else:
self._user = None
@property @property
def hostname(self): def hostname(self):
@ -81,4 +56,4 @@ class IdentityModel(object):
return crypt_password(passinput) return crypt_password(passinput)
def __repr__(self): def __repr__(self):
return "<LocalUser: {}>".format(self.user) return "<LocalUser: {} {}>".format(self.user, self.hostname)