Skip to content
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

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Rakefile
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
5 changes: 5 additions & 0 deletions package/yast2-security.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-------------------------------------------------------------------
Thu Sep 1 11:39:37 UTC 2016 - vpereira@suse.com

- Refactoring autoconverted ruby code into ruby dialect

-------------------------------------------------------------------
Wed Aug 31 11:37:52 UTC 2016 - jreidinger@suse.com

Expand Down
141 changes: 141 additions & 0 deletions rubocop_yast_style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# 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
inherit_from:
/usr/share/YaST2/data/devtools/data/rubocop_yast_style.yml

Style/IfInsideElse:
Enabled: false

Style/MultilineTernaryOperator:
Enabled: false

Lint/UnderscorePrefixedVariableName:
Enabled: false


Metrics/AbcSize:
Max: 129
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/AbcSize:
Max: 30
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/BlockNesting:
Max: 5
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/BlockNesting:
Max: 2
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib


# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 385
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 200
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/ModuleLength:
Max: 385
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/ModuleLength:
Max: 100
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/CyclomaticComplexity:
Max: 29
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/CyclomaticComplexity:
Max: 10
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 299
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# Configuration parameters: AllowURI, URISchemes.
Metrics/LineLength:
Max: 100 # TODO this should be lower for new code
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 160
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 30 # TODO this should be lower for new code
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/PerceivedComplexity:
Max: 34
Exclude:
- 'src/lib/**/*.rb' # be more strict for new code in lib

Metrics/PerceivedComplexity:
Max: 10
Include:
- 'src/lib/**/*.rb' # be more strict for new code in lib

# be more strict then rubocop, 5 is too much
Metrics/ParameterLists:
Max: 4

# Configuration parameters: EnforcedStyle, SupportedStyles.
Style/AndOr:
EnforcedStyle: conditionals

Style/Documentation:
Include:
- 'src/lib/**/*.rb' # force well documented code only for new code

Style/FileName:
Include:
- 'src/lib/**/*.rb' # force correct names on new code

Style/HashSyntax:
Include:
- 'src/lib/**/*.rb' # force new hash style only for new code

# JR: I found lambda easier to read and understand then ->()
Style/Lambda:
Enabled: false

Style/MethodName:
Include:
- 'src/lib/**/*.rb' # force correct names on new code

Style/VariableName:
Include:
- 'src/lib/**/*.rb' # force known variables only for new code

# alias method is more convenient method for method aliasing
Style/Alias:
EnforcedStyle: prefer_alias_method
105 changes: 39 additions & 66 deletions src/clients/security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -50,8 +51,6 @@ def main

Yast.include self, "security/wizards.rb"



# the command line description map
@cmdline = {
"id" => "security",
Expand Down Expand Up @@ -89,7 +88,7 @@ def main
}
},
"options" => {
"workstation" => {
"workstation" => {
# command line help text for 'level workstation' option
"help" => _(
"Workstation security level"
Expand Down Expand Up @@ -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",
Expand All @@ -158,7 +157,7 @@ def main
# Finish
Builtins.y2milestone("Security module finished")
Builtins.y2milestone("----------------------------------------")
deep_copy(@ret)
deep_copy(@ret)

# EOF
end
Expand All @@ -168,34 +167,32 @@ def main

# Print security summary
# @return [Boolean] false
def SecuritySummaryHandler(options)
options = deep_copy(options)
def SecuritySummaryHandler(_options)
sum = Security.Summary
CommandLine.Print(Ops.get_string(sum, 0, ""))
false # do not call Write...
end

# Set security level
# @return [Boolean] successfully modified?
# @return [Boolean] false
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"
end

current = @Levels.select { |_key, level| level == Security.Settings }.keys.last || :custom

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?
end

if current != lvl
Security.Settings = Ops.get(@Levels, lvl, {})
Security.Settings = @Levels.fetch(lvl, {})
Security.modified = true
return true
end
false
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it valid? what is reason for this change?

Expand All @@ -204,61 +201,37 @@ def SecurityLevelHandler(options)
# @return [Boolean] false
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"] # as string not int
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
end
Security.modified
false
end
end
end
Expand Down