Commit 8e0a558d authored by marcus.hardt's avatar marcus.hardt

Merge branch 'add-credentials' into 'master'

add credentials dict to user and provide necessary output

See merge request !36
parents 55317b1d efd8abaa
......@@ -10,6 +10,7 @@ import logging
import regex
from unidecode import unidecode
from ..config import CONFIG
from ..results import Failure
logger = logging.getLogger(__name__)
......@@ -23,7 +24,8 @@ class User:
self.name = make_shadow_compatible(userinfo.username)
self.unique_id = userinfo.unique_id
self.ssh_keys = [key['value'] for key in userinfo.ssh_keys]
self.primary_group = Group(userinfo.primary_group)
self.primary_group = Group(userinfo.primary_group)
self.credentials = {}
def exists(self):
return bool(self.__passwd_entry)
......@@ -34,7 +36,9 @@ class User:
def create(self):
try:
# TODO this should consider self.primary_group
subprocess.run(['useradd', '--comment', self.unique_id, self.name],
subprocess.run(['useradd', '--comment', self.unique_id,
'-g', self.primary_group.name,
self.name],
capture_output=True, check=True)
except CalledProcessError as e:
msg = (e.stderr or e.stdout or b'').decode('utf-8').strip()
......@@ -42,7 +46,10 @@ class User:
raise Failure(message='Cannot create user')
def update(self):
pass
self.credentials['ssh_user'] = self.name
self.credentials['ssh_host'] = CONFIG['backend.local_unix.login_info'].get('ssh_host', 'undefined')
self.credentials['commandline'] = "ssh {}@{}".format(
self.credentials['ssh_user'], self.credentials['ssh_host'])
def delete(self):
name = self.__passwd_entry['login']
......@@ -88,12 +95,6 @@ class User:
def __authorized_keys(self):
return Path(self.__passwd_entry['home'])/'.ssh'/'authorized_keys'
@property
def credentials(self):
return {
'login_name': self.__passwd_entry.get('login', self.name)
}
@property
def __passwd_entry(self):
return User.__all_passwd_entries().get(self.unique_id, {})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment