very bare SSH model/controller/view

This commit is contained in:
Michael Hudson-Doyle 2018-11-29 16:03:15 +13:00
parent e8bd1b8eb7
commit be16f4433c
7 changed files with 135 additions and 3 deletions

View File

@ -23,6 +23,7 @@ from .mirror import MirrorController
from subiquitycore.controllers.login import LoginController
from subiquitycore.controllers.network import NetworkController
from .snaplist import SnapListController
from .ssh import SSHController
from .welcome import WelcomeController
__all__ = [
'FilesystemController',
@ -35,5 +36,6 @@ __all__ = [
'LoginController',
'NetworkController',
'SnapListController',
'SSHController',
'WelcomeController',
]

View File

@ -122,5 +122,4 @@ class IdentityController(BaseController):
safe_spec['password'] = '<REDACTED>'
log.debug("User input: {}".format(safe_spec))
self.model.add_user(user_spec)
self.signal.emit_signal('installprogress:identity-config-done')
self.signal.emit_signal('next-screen')

View File

@ -0,0 +1,44 @@
# Copyright 2018 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from subiquitycore.controller import BaseController
from subiquity.ui.views.ssh import SSHView
log = logging.getLogger('subiquity.controllers.ssh')
class SSHController(BaseController):
def __init__(self, common):
super().__init__(common)
self.model = self.base_model.ssh
self.answers = self.all_answers.get('SSH', {})
def default(self):
self.ui.set_body(SSHView(self.model, self))
#if self.answers:
# self.done(self.answers)
def cancel(self):
self.signal.emit_signal('prev-screen')
def done(self, result):
#self.model.install_server = result['install_server']
#self.model.authorized_keys = result['authorized_keys']
#self.model.pwauth = result['pwauth']
self.signal.emit_signal('installprogress:identity-config-done')
self.signal.emit_signal('next-screen')

View File

@ -39,6 +39,7 @@ class Subiquity(Application):
"Mirror",
"Filesystem",
"Identity",
"SSH",
"SnapList",
"InstallProgress",
]

27
subiquity/models/ssh.py Normal file
View File

@ -0,0 +1,27 @@
# Copyright 2018 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
log = logging.getLogger("subiquity.models.ssh")
class SSHModel:
def __init__(self):
self.install_server = False
self.authorized_keys = None
self.pwauth = True

View File

@ -30,6 +30,7 @@ from .locale import LocaleModel
from .proxy import ProxyModel
from .mirror import MirrorModel
from .snaplist import SnapListModel
from .ssh import SSHModel
def setup_yaml():
@ -65,6 +66,7 @@ class SubiquityModel:
self.proxy = ProxyModel()
self.mirror = MirrorModel()
self.snaplist = SnapListModel()
self.ssh = SSHModel()
def get_target_groups(self):
command = ['chroot', self.target, 'getent', 'group']
@ -96,8 +98,8 @@ class SubiquityModel:
'groups': groups,
'lock-passwd': False,
}
if user.ssh_keys:
user_info['ssh_authorized_keys'] = user.ssh_keys
if self.ssh.authorized_keys:
user_info['ssh_authorized_keys'] = self.ssh.authorized_keys
config = {
'growpart': {
'mode': 'off',
@ -107,6 +109,8 @@ class SubiquityModel:
'resize_rootfs': False,
'users': [user_info],
}
if self.ssh.install_server:
config['ssh_pwauth'] = self.ssh.install_server
if self.snaplist.to_install:
cmds = []
for snap_name, selection in sorted(

55
subiquity/ui/views/ssh.py Normal file
View File

@ -0,0 +1,55 @@
# Copyright 2018 Canonical, Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from urwid import connect_signal
from subiquitycore.view import BaseView
from subiquitycore.ui.form import (
Form,
)
log = logging.getLogger('subiquity.ui.ssh')
class SSHForm(Form):
cancel_label = _("Back")
class SSHView(BaseView):
title = _("SSH Setup")
excerpt = _("You can choose to install the OpenSSH server package to "
"enable secure remote access to your server.")
def __init__(self, model, controller):
self.model = model
self.controller = controller
self.form = SSHForm(initial={})
connect_signal(self.form, 'submit', self.done)
connect_signal(self.form, 'cancel', self.cancel)
super().__init__(self.form.as_screen(excerpt=_(self.excerpt)))
def done(self, sender):
log.debug("User input: {}".format(self.form.as_data()))
self.controller.done(self.form.as_data())
def cancel(self, result=None):
self.controller.cancel()