-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] refactoring autoconverted ruby code into ruby code #40
Changes from 3 commits
37c8b03
8aa8cf5
a5ce056
e7a1a07
7aed7c3
d9e8a4f
8b37930
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
require "yast/rake" | ||
|
||
Yast::Tasks.configuration do |conf| | ||
#lets ignore license check for now | ||
# lets ignore license check for now | ||
conf.skip_license_check << /.*/ | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Rubocop style configuration | ||
# | ||
# Following | ||
# https://github.com/SUSE/style-guides/blob/master/Ruby.md | ||
|
||
# https://github.com/SUSE/style-guides/blob/master/Ruby.md#strings | ||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
|
||
Style/StringLiteralsInInterpolation: | ||
EnforcedStyle: double_quotes | ||
|
||
# Is there any justification for "aligned" which is the default? | ||
Style/MultilineOperationIndentation: | ||
EnforcedStyle: indented | ||
|
||
# https://github.com/SUSE/style-guides/blob/master/Ruby.md#arrays | ||
Style/WordArray: | ||
Enabled: false | ||
|
||
# align arrows: | ||
# "foo" => true | ||
# "foo_bar" => false | ||
# and also colons: | ||
# foo: true | ||
# foo_bar: false | ||
Style/AlignHash: | ||
EnforcedHashRocketStyle: table | ||
EnforcedColonStyle: table | ||
|
||
# no extra indentation for multiline function calls | ||
Style/AlignParameters: | ||
EnforcedStyle: with_fixed_indentation | ||
|
||
# no extra indentation for case | ||
Style/CaseIndentation: | ||
IndentWhenRelativeTo: end | ||
|
||
# "unless" has a different connotation than "if not" | ||
Style/NegatedIf: | ||
Enabled: false | ||
|
||
# use "raise" instead of "fail" | ||
Style/SignalException: | ||
EnforcedStyle: only_raise | ||
|
||
# do not force %r | ||
Style/RegexpLiteral: | ||
Enabled: false | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,13 @@ | |
# only some calls to the basic functions. The settings are | ||
# initialized, main dialog is called and then settings are | ||
# saved. | ||
|
||
module Yast | ||
class SecurityClient < Client | ||
def main | ||
Yast.import "UI" | ||
|
||
#** | ||
# ** | ||
# <h3> Security configuration | ||
|
||
textdomain "security" | ||
|
@@ -50,8 +51,6 @@ def main | |
|
||
Yast.include self, "security/wizards.rb" | ||
|
||
|
||
|
||
# the command line description map | ||
@cmdline = { | ||
"id" => "security", | ||
|
@@ -89,7 +88,7 @@ def main | |
} | ||
}, | ||
"options" => { | ||
"workstation" => { | ||
"workstation" => { | ||
# command line help text for 'level workstation' option | ||
"help" => _( | ||
"Workstation security level" | ||
|
@@ -142,7 +141,7 @@ def main | |
"mappings" => { | ||
"summary" => [], | ||
"level" => ["workstation", "roaming", "server"], | ||
#FIXME 1,2,3 aliases | ||
# FIXME: 1,2,3 aliases | ||
"set" => [ | ||
"passwd", | ||
"crack", | ||
|
@@ -158,7 +157,7 @@ def main | |
# Finish | ||
Builtins.y2milestone("Security module finished") | ||
Builtins.y2milestone("----------------------------------------") | ||
deep_copy(@ret) | ||
deep_copy(@ret) | ||
|
||
# EOF | ||
end | ||
|
@@ -180,83 +179,66 @@ def SecuritySummaryHandler(options) | |
def SecurityLevelHandler(options) | ||
options = deep_copy(options) | ||
current = :custom | ||
Builtins.maplist(@Levels) do |key, level| | ||
current = key if level == Security.Settings | ||
end | ||
lvl = "" | ||
if options.key?("workstation") | ||
lvl = "Level1" | ||
elsif options.key?("roaming") | ||
lvl = "Level2" | ||
elsif options.key?("server") | ||
lvl = "Level3" | ||
|
||
levels = @Levels.select { |_key, level| level == Security.Settings } | ||
|
||
current = if levels.empty? | ||
:custom | ||
else | ||
levels.last # mimic the old implementation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is in fact wrong, as levels contain pair of
|
||
end | ||
|
||
lvl = if options.key?("workstation") | ||
"Level1" | ||
elsif options.key?("roaming") | ||
"Level2" | ||
elsif options.key?("server") | ||
"Level3" | ||
else | ||
:custom # shouldnt :custom and levels all same type string or symbol? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it valid? what is reason for this change? |
||
end | ||
|
||
if current != lvl | ||
Security.Settings = Ops.get(@Levels, lvl, {}) | ||
Security.Settings = @Levels.fetch(lvl, {}) | ||
Security.modified = true | ||
return true | ||
end | ||
false | ||
Security.modified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this in fact is not same as previous code as it can return true, when something else set Security.modified to true and here it is not set There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and why we return always false? there is a reason for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expect that logic is that we return false to indicate that this action do not change anything. |
||
end | ||
|
||
# Set value of specific security option | ||
# @return [Boolean] false | ||
# @return [Boolean] successfully modified? | ||
def SecuritySetHandler(options) | ||
options = deep_copy(options) | ||
if Builtins.haskey(options, "passwd") && | ||
Ops.get_string(options, "passwd", "") != | ||
Ops.get(Security.Settings, "PASSWD_ENCRYPTION", "") | ||
Ops.set( | ||
Security.Settings, | ||
"PASSWD_ENCRYPTION", | ||
Ops.get_string(options, "passwd", "des") | ||
) | ||
|
||
if options.key?("password") && | ||
Security.Settings["PASSWD_ENCRYPTION"] != options["password"] | ||
Security.Settings["PASSWD_ENCRYPTION"] = options.fetch("password", "des") | ||
Security.modified = true | ||
end | ||
if Builtins.haskey(options, "crack") && | ||
Ops.get_string(options, "crack", "") != | ||
Ops.get(Security.Settings, "PASSWD_USE_CRACKLIB", "") | ||
Ops.set( | ||
Security.Settings, | ||
"PASSWD_USE_CRACKLIB", | ||
Ops.get_string(options, "crack", "yes") | ||
) | ||
|
||
if options_has_key?("crack") && | ||
Security.Settings["PASSWD_USE_CRACKLIB"] != options["crack"] | ||
Security.Settings["PASSWD_USE_CRACKLIB"] = options.fetch("crack", "yes") | ||
Security.modified = true | ||
end | ||
if Builtins.haskey(options, "permissions") && | ||
!Builtins.issubstring( | ||
Ops.get(Security.Settings, "PERMISSION_SECURITY", ""), | ||
Ops.get_string(options, "permissions", "") | ||
) | ||
Ops.set( | ||
Security.Settings, | ||
"PERMISSION_SECURITY", | ||
Ops.add(Ops.get_string(options, "permissions", ""), " local") | ||
) | ||
|
||
if options.key?("permissions") && | ||
Security.Settings["PERMISSION_SECURITY"] != options["permissions"] | ||
Security.Settings["PERMISSION_SECURITY"] = options.fetch("permissions", "local") | ||
Security.modified = true | ||
end | ||
|
||
if Builtins.haskey(options, "remember") && | ||
Ops.get(Security.Settings, "PASSWD_REMEMBER_HISTORY", "0") != | ||
Ops.get_string(options, "remember", "0") | ||
to_remember = Builtins.tointeger( | ||
Ops.get_string(options, "remember", "0") | ||
) | ||
if to_remember == nil || Ops.less_than(to_remember, 0) || | ||
Ops.greater_than(to_remember, 400) | ||
# error message | ||
if options.key?("remember") && | ||
Security.Settings["PASSWD_REMEMBER_HISTORY"] != options["remember"] | ||
if options["remember"].to_i.between?(0, 400) | ||
Security.Settings["PASSWD_REMEMBER_HISTORY"] = options["remember"].to_i | ||
Security.modified = true | ||
else | ||
Report.Error( | ||
_("The number of passwords to remember must be between 0 an 400.") | ||
) | ||
return false | ||
end | ||
Ops.set( | ||
Security.Settings, | ||
"PASSWD_REMEMBER_HISTORY", | ||
Ops.get_string(options, "remember", "0") | ||
) | ||
Security.modified = true | ||
Security.modified | ||
end | ||
Security.modified | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,30 +56,30 @@ def main | |
@param = {} | ||
|
||
# Check arguments | ||
if Ops.greater_than(Builtins.size(WFM.Args), 0) && | ||
Ops.is_string?(WFM.Args(0)) | ||
@func = Convert.to_string(WFM.Args(0)) | ||
if Ops.greater_than(Builtins.size(WFM.Args), 1) && | ||
Ops.is_map?(WFM.Args(1)) | ||
@param = Convert.to_map(WFM.Args(1)) | ||
if !Yast::WFM.Args.empty? | ||
@func = Yast::WFM.Args[0] | ||
if Yast::WFM.Args.length > 1 && Yast::WFM.Args[1].is_a?(Hash) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in fact second option is enough, because if length is 1 or less, then |
||
@param = WFM.Args[1] | ||
end | ||
end | ||
|
||
Builtins.y2debug("func=%1", @func) | ||
Builtins.y2debug("param=%1", @param) | ||
|
||
# Create a summary | ||
if @func == "Summary" | ||
case @func | ||
when "Summary" | ||
@summary = Security.Summary | ||
@ret = Ops.get_string(@summary, 0, "") | ||
# Reset configuration | ||
elsif @func == "Reset" | ||
when "Reset" | ||
Security.Import({}) | ||
@ret = {} | ||
# Change configuration (run AutoSequence) | ||
elsif @func == "Change" | ||
when "Change" | ||
@ret = SecurityAutoSequence() | ||
# Import Data | ||
elsif @func == "Import" | ||
when "Import" | ||
# Compat | ||
if Builtins.haskey(@param, "encryption") | ||
Ops.set( | ||
|
@@ -90,37 +90,37 @@ def main | |
end | ||
@ret = Security.Import( | ||
Map.KeysToUpper( | ||
Convert.convert(@param, :from => "map", :to => "map <string, any>") | ||
Convert.convert(@param, from: "map", to: "map <string, any>") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in fact whole this convert can be dropeed as implementation do not distinct between map and specialized map. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so simple |
||
) | ||
) | ||
# Return required packages | ||
elsif @func == "Packages" | ||
when "Packages" | ||
@ret = {} | ||
# Return actual state | ||
elsif @func == "Export" | ||
when "Export" | ||
@ret = Map.KeysToLower( | ||
Convert.convert( | ||
Security.Export, | ||
:from => "map", | ||
:to => "map <string, any>" | ||
from: "map", | ||
to: "map <string, any>" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here |
||
) | ||
) | ||
# Read current state | ||
elsif @func == "Read" | ||
when "Read" | ||
Yast.import "Progress" | ||
Progress.off | ||
@ret = Security.Read | ||
Progress.on | ||
# Write givven settings | ||
elsif @func == "Write" | ||
when "Write" | ||
Yast.import "Progress" | ||
Security.write_only = true | ||
Progress.off | ||
@ret = Security.Write | ||
Progress.on | ||
elsif @func == "SetModified" | ||
when "SetModified" | ||
@ret = Security.SetModified | ||
elsif @func == "GetModified" | ||
when "GetModified" | ||
@ret = Security.GetModified | ||
else | ||
Builtins.y2error("Unknown function: %1", @func) | ||
|
@@ -131,8 +131,8 @@ def main | |
Builtins.y2milestone("Security auto finished") | ||
Builtins.y2milestone("----------------------------------------") | ||
|
||
deep_copy(@ret) | ||
|
||
# is it needed? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no, it is not needed as @ret is always assigned and from fresh copy. |
||
deep_copy(@ret) | ||
# EOF | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is in fact wrong as you kill return value. I just said that deep_copy is not needed, so still you need to have here |
||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for you ruby style guide, but better to reference it. See how other modules do it: e.g. https://github.com/yast/yast-bootloader/blob/master/.rubocop.yml#L3