Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First version of the ssh_import proposal
- Loading branch information
Showing
5 changed files
with
255 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "installation/clients/ssh_import_proposal" | ||
Yast::SshImportProposalClient.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
require "installation/proposal_client" | ||
require "installation/dialogs/ssh_import" | ||
require "installation/ssh_config" | ||
|
||
module Yast | ||
# Proposal client for bootloader configuration | ||
class SshImportProposalClient < ::Installation::ProposalClient | ||
include Yast::I18n | ||
|
||
@@calculated = false | ||
|
||
def initialize | ||
Yast.import "UI" | ||
textdomain "installation" | ||
end | ||
|
||
protected | ||
|
||
def description | ||
{ | ||
# proposal part - bootloader label | ||
"rich_text_title" => _("Import SSH Configuration and Keys"), | ||
# menubutton entry | ||
"menu_title" => _("&Import SSH Configuration and Keys"), | ||
"id" => "ssh_import" | ||
} | ||
end | ||
|
||
def make_proposal(attrs) | ||
if !@@calculated || attrs["force_reset"] | ||
@@calculated = true | ||
set_default_values | ||
end | ||
update_ssh_configs | ||
{ | ||
"preformatted_proposal" => preformatted_proposal, | ||
"links" => ["ssh_import"] | ||
} | ||
end | ||
|
||
# To ensure backwards compatibility, the default proposal is to copy all | ||
# the ssh keys in the most recently accessed config and to not copy any | ||
# additional config file | ||
def set_default_values | ||
@@device = default_ssh_config.device | ||
@@copy_config = false | ||
end | ||
|
||
# Syncs the status of SshConfig.all with the settings in the proposal | ||
# | ||
# It updates the #to_export flag for all the SSH keys and config files. | ||
def update_ssh_configs | ||
all_ssh_configs.each do |config| | ||
selected = config.device == @@device | ||
config.config_files.each { |f| f.to_export = (selected && @@copy_config) } | ||
config.keys.each { |k| k.to_export = selected } | ||
end | ||
end | ||
|
||
def default_ssh_config | ||
@default_ssh_config ||= all_ssh_configs.select(&:keys_atime).max_by(&:keys_atime) | ||
end | ||
|
||
def all_ssh_configs | ||
@all_ssh_configs ||= ::Installation::SshConfig.all | ||
end | ||
|
||
def preformatted_proposal | ||
if all_ssh_configs.empty? | ||
return _("No previous Linux installation found - not importing any SSH Key") | ||
end | ||
if @@device.nil? | ||
res = _("No existing SSH keys will be copied") | ||
else | ||
ssh_config = all_ssh_configs.detect { |c| c.device == @@device } | ||
partition = ssh_config.system_name | ||
if @@copy_config | ||
# TRANSLATORS: %s is the name of a Linux system found in the hard | ||
# disk, like 'openSUSE 13.2' | ||
res = _("SSH 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 keys will be copied from %s") % partition | ||
end | ||
end | ||
res += " " + _("(<a href=%s>change</a>)") % '"ssh_import"' | ||
res | ||
end | ||
|
||
def ask_user(param) | ||
log.info "Asking user which SSH keys to import" | ||
user_input = Yast::SshImportDialog.new(@@device, @@copy_config).run | ||
if user_input | ||
log.info "SshImportDialog result: #{user_input}" | ||
@@device = user_input[:device] | ||
@@copy_config = user_input[:copy_config] | ||
end | ||
|
||
{ "workflow_sequence" => :next } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright (c) 2016 SUSE LLC. | ||
# All Rights Reserved. | ||
|
||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of version 2 or 3 of the GNU General | ||
# Public License as published by the Free Software Foundation. | ||
|
||
# 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 General Public License for more details. | ||
|
||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, contact SUSE LLC. | ||
|
||
# To contact SUSE about this file by physical or electronic mail, | ||
# you may find current contact information at www.suse.com | ||
|
||
require "yast" | ||
require "ui/dialog" | ||
require "installation/ssh_config" | ||
|
||
module Yast | ||
class SshImportDialog < ::UI::Dialog | ||
def initialize(device, copy_config) | ||
super() | ||
|
||
Yast.import "UI" | ||
Yast.import "Label" | ||
|
||
textdomain "installation" | ||
|
||
@device = device | ||
@copy_config = copy_config | ||
end | ||
|
||
# Event callback for the 'ok' button | ||
def ok_handler | ||
partition = UI.QueryWidget(Id(:device), :Value) | ||
partition = nil if partition == :none | ||
copy_config = UI.QueryWidget(Id(:copy_config), :Value) | ||
finish_dialog(device: partition, copy_config: copy_config) | ||
end | ||
|
||
private | ||
|
||
attr_reader :device, :copy_config | ||
|
||
def partitions | ||
@partitions ||= ::Installation::SshConfig.all.reject { |c| c.keys.empty? } | ||
end | ||
|
||
def dialog_content | ||
VBox( | ||
Heading(_("System to Import SSH Keys from")), | ||
HBox( | ||
HStretch(), | ||
VBox( | ||
partitions_list_widget, | ||
VSpacing(0.5), | ||
Left(copy_config_widget) | ||
), | ||
HStretch() | ||
), | ||
VSpacing(0.5), | ||
HBox( | ||
PushButton(Id(:ok), Opt(:default), Label.OKButton), | ||
PushButton(Id(:cancel), Label.CancelButton) | ||
) | ||
) | ||
end | ||
|
||
def dialog_options | ||
Opt(:decorated) | ||
end | ||
|
||
def partitions_list_widget | ||
part_widgets = partitions.map do |partition| | ||
Left(partition_widget(partition)) | ||
end | ||
|
||
RadioButtonGroup( | ||
Id(:device), | ||
VBox( | ||
# TRANSLATORS: option to select no partition for SSH keys import | ||
Left(RadioButton(Id(:none), _("None"), @device.nil?)), | ||
*part_widgets | ||
) | ||
) | ||
end | ||
|
||
def partition_widget(partition) | ||
dev = partition.device | ||
strings = {system_name: partition.system_name, device: dev} | ||
# TRANSLATORS: system_name is a string like "openSUSE 13.2", device | ||
# is a string like /dev/sda1 | ||
name = _("%{system_name} at %{device}") % strings | ||
RadioButton(Id(dev), name, device == dev) | ||
end | ||
|
||
def copy_config_widget | ||
CheckBox(Id(:copy_config), _("Copy whole SSH configuration"), @copy_config) | ||
end | ||
end | ||
end |