Skip to content

Commit

Permalink
[Review] Request from 'schubi2' @ 'yast/yast-installation/review_1605…
Browse files Browse the repository at this point in the history
…24_autoyast_support' (#380)

* autoyast support

* syntax

* fixed errors

* fixed makefile pathes

* typo

* typo

* setting global variables corretly

* fixes in exporting settings

* packaging

* autoyast ui for ssh_import

* Add unit tests for SSHImportAutoClient

* removed auto_ssh_import due Knut's nice UI changes

* Move client logic from SshImporter to SSHImportAutoClient

* Updates from code review

* additional changes for the UI

* take setting from module

* added description

* Fix ssh_import_auto test

* Move the debugger invocation to ruby-bindings (FATE#318421) (#386)

* Move the debugger invocation to ruby-bindings (FATE#318421)

... to use the same implementation at run time.

- 3.1.190

* revert also the dependency

* cleanup

* we are taking the second one suggestion :-)

* Revert SshImportProposalClient#make_proposal

* Updates from code review

* Move SshImporter presentation responsability to a new class

* Make rubocop happy

* ssh_importer_presenter added

* missing \

* added SshImporter

* added logging

* added more logging

* making rubokop happy

* normal mode is a configuration mode too

* rubocop

* rubocop

* Updates from code review

* removed back stuff

* moving config to copy_config

* moving config to copy_config

* added logging
  • Loading branch information
schubi2 committed Jun 3, 2016
1 parent ef50436 commit fd94cd1
Show file tree
Hide file tree
Showing 19 changed files with 577 additions and 23 deletions.
3 changes: 2 additions & 1 deletion autoyast_desktop/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Makefile.am for installation/src/config

modconfigdir = $(prefix)/share/autoinstall/modules
modconfig_DATA = deploy_image.desktop
modconfig_DATA = deploy_image.desktop \
ssh_import.desktop

EXTRA_DIST = $(modconfig_DATA)

Expand Down
26 changes: 26 additions & 0 deletions autoyast_desktop/ssh_import.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[Desktop Entry]
Type=Application
Categories=Settings;System;Qt;X-SuSE-YaST;X-SuSE-YaST-Misc;

X-KDE-ModuleType=Library
X-KDE-HasReadOnlyMode=false
X-SuSE-YaST-Call=ssh_import

X-SuSE-YaST-Group=Security
X-SuSE-YaST-Argument=
X-SuSE-YaST-RootOnly=true
X-SuSE-YaST-AutoInst=configure
X-SuSE-YaST-Geometry=
X-SuSE-YaST-SortKey=
X-SuSE-YaST-AutoInstResource=
X-SuSE-YaST-AutoInstPath=install
X-SuSE-YaST-AutoInstSchema=ssh_import.rnc
X-SuSE-YaST-AutoInstClonable=true

Icon=yast-ssh_import
Exec=

Name=SSH Key Import
GenericName=Importing SSH keys from a previous installation

StartupNotify=true
7 changes: 7 additions & 0 deletions package/yast2-installation.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Thu Jun 2 11:09:33 UTC 2016 - schubi@suse.de

- Adapt AutoYaST to support import of SSH server keys/configuration
(fate#319624)
- 3.1.193

-------------------------------------------------------------------
Thu Jun 2 10:09:33 UTC 2016 - igonzalezsosa@suse.com

Expand Down
2 changes: 1 addition & 1 deletion package/yast2-installation.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-installation
Version: 3.1.192
Version: 3.1.193
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
3 changes: 3 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ client_DATA = \
clients/save_hw_status_finish.rb \
clients/snapshots_finish.rb \
clients/ssh_import_proposal.rb \
clients/ssh_import_auto.rb \
clients/ssh_settings_finish.rb \
clients/stroj-casu.rb \
clients/switch_scr_finish.rb \
Expand Down Expand Up @@ -122,6 +123,7 @@ ylib_DATA = \
lib/installation/ssh_config.rb \
lib/installation/ssh_key.rb \
lib/installation/ssh_config_file.rb \
lib/installation/ssh_importer_presenter.rb \
lib/installation/ssh_importer.rb

ylibtransferdir = "${yast2dir}/lib/transfer"
Expand Down Expand Up @@ -189,6 +191,7 @@ ylibclient_DATA = \
lib/installation/clients/umount_finish.rb \
lib/installation/clients/update_wizard_steps.rb \
lib/installation/clients/x11_finish.rb \
lib/installation/clients/ssh_import_auto.rb \
lib/installation/clients/yast_inf_finish.rb

ylibdialogdir = "${yast2dir}/lib/installation/dialogs"
Expand Down
3 changes: 3 additions & 0 deletions src/clients/ssh_import_auto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require "installation/clients/ssh_import_auto"

::Installation::SSHImportAutoClient.run
154 changes: 154 additions & 0 deletions src/lib/installation/clients/ssh_import_auto.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
require "yast"

require "installation/auto_client"
require "installation/ssh_importer"
require "installation/ssh_importer_presenter"

Yast.import "Progress"
Yast.import "Mode"
Yast.import "Popup"

module Installation
# AutoYaST client for ssh_import
class SSHImportAutoClient < ::Installation::AutoClient
class << self
attr_accessor :changed
end

def run
progress_orig = Yast::Progress.set(false)
ret = super
Yast::Progress.set(progress_orig)

ret
end

# Importing data from the AutoYaST configuration module
# AutoYaST data format:
#
# <ssh_import>
# <import config:type="boolean">true</import>
# <copy_config config:type="boolean">true</copy_config>
# <device>/dev/sda4</device>
# </ssh_import>
#
# @param data [Hash] AutoYaST specification.
# @option data [Boolean] :import Import SSH keys
# @option data [Boolean] :copy_config Import SSH server configuration
# in addition to keys.
# @option data [Boolean] :device Device to import the keys/configuration from.
def import(data)
if !data["import"]
log.info "Do not import ssh keys/configuration"
ssh_importer.device = nil # do not copy ssh keys into the installed system
return true
end

log.info "Importing AutoYaST data: #{data}"
ssh_importer.copy_config = data["copy_config"] == true
if data["device"] && !data["device"].empty?
if ssh_importer.configurations.key?(data["device"])
ssh_importer.device = data["device"]
else
Yast::Report.Warning(
# TRANSLATORS: both %s are device names like /dev/sda0
_(format("Device %s not found. Using data from %s.",
data["device"], ssh_importer.device)))
end
end
true
end

# Returns a human readable summary
#
# @see ::Installation::SshImporterPresenter
def summary
::Installation::SshImporterPresenter.new(ssh_importer).summary
end

def modified?
self.class.changed
end

def modified
self.class.changed = true
end

def reset
ssh_importer.reset
end

def change
# If this module has been called and do not
# depends on the installed system we would like to
# have this section in the exported AutoYaST file
# regardless if the entries have been changed nor not.
modified

begin
args = {
"enable_back" => false,
"enable_next" => false,
"going_back" => false
}
Yast::Wizard.OpenAcceptDialog
WFM.CallFunction("inst_ssh_import", [args])
ensure
Yast::Wizard.CloseDialog
end
end

# Exporting data to the AutoYaST configuration module.
# That's are default entries.
def export
ret = {}
if Mode.config
# Taking values from AutoYast configuration module
if ssh_importer.device && !ssh_importer.device.empty?
ret["import"] = true
ret["copy_config"] = ssh_importer.copy_config
if !ssh_importer.device.empty? && ssh_importer.device != "default"
ret["device"] = ssh_importer.device
end
else
ret["import"] = false
ret["copy_config"] = false
end
else
# Taking default values
ret = { "import" => true, "copy_config" => false }
# Device will not be set because it is optional and the
# most-recently-accessed device (biggest keys_atime)
# will be used for.
# ret["device"] = device
end
ret
end

# Writes the SSH keys from the selected device (and also other
# configuration files if #copy_config? is true) in the target
# filesystem
def write
if Mode.config || Mode.normal # normal=configuration in an installed system
Popup.Notify _("It makes no sense to write these settings to system.")
true
else
ssh_importer.write(::Installation.destdir)
end
end

def read
# It is a user decision only. Not depending on system
true
end

protected

# Helper method to access to the SshImporter
#
# @return [::Installation::SshImporter] SSH importer
def ssh_importer
@ssh_importer ||= ::Installation::SshImporter.instance
end
end
end
22 changes: 3 additions & 19 deletions src/lib/installation/clients/ssh_import_proposal.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "installation/proposal_client"
require "installation/ssh_importer"
require "installation/ssh_importer_presenter"

module Yast
# Proposal client for SSH keys import
Expand Down Expand Up @@ -37,25 +38,8 @@ def importer
end

def preformatted_proposal
if importer.configurations.empty?
return Yast::HTML.List([_("No previous Linux installation found")])
end
if importer.device.nil?
res = _("No existing SSH host keys will be copied")
else
ssh_config = importer.configurations[importer.device]
partition = ssh_config.system_name
if importer.copy_config?
# TRANSLATORS: %s is the name of a Linux system found in the hard
# disk, like 'openSUSE 13.2'
res = _("SSH host keys and configuration will be copied from %s") % partition
else
# TRANSLATORS: %s is the name of a Linux system found in the hard
# disk, like 'openSUSE 13.2'
res = _("SSH host keys will be copied from %s") % partition
end
end
Yast::HTML.List([res])
::Installation::SshImporterPresenter.new(
::Installation::SshImporter.instance).summary
end

def ask_user(param)
Expand Down
10 changes: 8 additions & 2 deletions src/lib/installation/dialogs/ssh_import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def initialize

Yast.import "UI"
Yast.import "Label"
Yast.import "Mode"

textdomain "installation"
end
Expand Down Expand Up @@ -66,13 +67,13 @@ def dialog_content
CheckBoxFrame(
Id(:import_ssh_key),
_("I would like to import SSH keys from a previous installation"),
true,
!(importer.device.nil? || importer.device.empty?),
VBox(
HStretch(),
VSpacing(1),
HBox(
HSpacing(2),
partitions_list_widget
Mode.config ? device_name : partitions_list_widget
),
VSpacing(3),
HBox(
Expand Down Expand Up @@ -102,6 +103,11 @@ def help_text
)
end

def device_name
# AutoYaST configuration mode. The user can input the device e.b. /dev/sda0
TextEntry(Id(:device), _("&Device"), importer.device || "default")
end

def partitions_list_widget
sorted_partitions = partitions.to_a.sort_by(&:first)
part_widgets = sorted_partitions.map do |device, partition|
Expand Down
3 changes: 3 additions & 0 deletions src/lib/installation/ssh_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Installation
class SshConfig
extend Yast::I18n
textdomain "installation"
include Yast::Logger

class << self
# Creates a new object with the information read from a filesystem
Expand Down Expand Up @@ -133,6 +134,8 @@ def read_files(dir)
# @param write_keys [Boolean] whether to copy the keys
# @param write_config_files [Boolean] whether to copy the config files
def write_files(root_dir, write_keys: true, write_config_files: true)
log.info "Writing SSH keys and/or configuration: " \
"keys: #{write_keys}, config: #{write_config_files}"
dir = self.class.ssh_dir(root_dir)
::FileUtils.mkdir_p(dir)

Expand Down
8 changes: 8 additions & 0 deletions src/lib/installation/ssh_config_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ module Installation
#
# Used by the SSH configuration importing functionality.
class SshConfigFile
include Yast::Logger

BACKUP_SUFFIX = ".yast.orig"

# @return [String] file name
Expand All @@ -46,12 +48,18 @@ def read(path)
end

def write(dir)
log.info "Write SSH config file #{dir} to #{name}"
path = File.join(dir, name)
backup(path)
IO.write(path, content)
File.chmod(permissions, path)
end

# Override to_s method for logging.
def to_s
"#{name}"
end

protected

def backup(filename)
Expand Down
1 change: 1 addition & 0 deletions src/lib/installation/ssh_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Installation
# in the hard disk and to copy its files to the target system
class SshImporter
include Singleton
include Yast::Logger

# @return [String] device name of the source filesystem (i.e. the
# SshConfig to copy the keys from)
Expand Down
Loading

0 comments on commit fd94cd1

Please sign in to comment.