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

Only Cleanup!! v3 #295

Merged
merged 4 commits into from
Sep 11, 2017
Merged

Only Cleanup!! v3 #295

merged 4 commits into from
Sep 11, 2017

Conversation

sgreen-r7
Copy link
Contributor

@sgreen-r7 sgreen-r7 commented Sep 6, 2017

This time for real, only cleanup/formatting fixes.

Link to %Q{ converting to %( info

@loginURL = loginURL
@name = name
@baseURL = baseURL
@loginURL = loginURL

Choose a reason for hiding this comment

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

Use snake_case for variable names.

@baseURL = baseURL
@loginURL = loginURL
@name = name
@baseURL = baseURL

Choose a reason for hiding this comment

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

Use snake_case for variable names.

@baseURL = baseURL
@headers = {}
@name = name
@baseURL = baseURL

Choose a reason for hiding this comment

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

Use snake_case for variable names.

@@ -4,22 +4,21 @@ module Nexpose
module WebCredentials

module WebAppAuthType
HTML_FORM = 'htmlform' # Represent HTML form credentials.
HTML_FORM = 'htmlform' # Represent HTML form credentials.

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

ALL_INSTANCES_IN_A_SPECIFIC_SITE = 'All Instances in a Specific Site'
ALL_INSTANCES = 'All Instances'
ALL_INSTANCES_ON_A_SPECIFIC_ASSET = 'All Instances on a Specific Asset'
ALL_INSTANCES_IN_A_SPECIFIC_SITE = 'All Instances in a Specific Site'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

DELETED = 'Deleted'
APPROVED = 'Approved'
REJECTED = 'Rejected'
DELETED = 'Deleted'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

REJECTED = 'Rejected'
DELETED = 'Deleted'
APPROVED = 'Approved'
REJECTED = 'Rejected'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

APPROVED = 'Approved'
REJECTED = 'Rejected'
DELETED = 'Deleted'
APPROVED = 'Approved'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

Nexpose::VulnException::Status.const_get(name).to_s.downcase==status.downcase || status.to_sym.downcase == name.downcase
end
def status_string_to_constant(status)
Nexpose::VulnException::Status.constants.find do |name|

Choose a reason for hiding this comment

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

Prefer detect over find.

valid_status << Nexpose::VulnException::Status.constants.map(&:to_s).map(&:downcase)
valid_status.flatten.map(&:downcase).include?(status.downcase)
end
def is_valid_vuln_exception_status?(status)

Choose a reason for hiding this comment

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

Rename is_valid_vuln_exception_status? to valid_vuln_exception_status?.

end
end

unless @restricted_report_sections.empty?
sections = xml.add_element('RestrictedReportSections')
@restricted_report_sections.each do |section|
sections.add_element('RestrictedReportSection', {'name' => section})
sections.add_element('RestrictedReportSection', { 'name' => section })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

end
end

unless @restricted_report_formats.empty?
formats = xml.add_element('RestrictedReportFormats')
@restricted_report_formats.each do |format|
formats.add_element('RestrictedReportFormat', {'name' => format})
formats.add_element('RestrictedReportFormat', { 'name' => format })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

end
end

unless @licensed_modules.empty?
licensed_modules = xml.add_element('LicensedModules')
@licensed_modules.each do |licensed_module|
licensed_modules.add_element('LicensedModule', {'name' => licensed_module})
licensed_modules.add_element('LicensedModule', { 'name' => licensed_module })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

end
end

unless @global_scan_templates.empty?
templates = xml.add_element('GlobalScanTemplates')
@global_scan_templates.each do |template|
templates.add_element('GlobalScanTemplate', {'name' => template})
templates.add_element('GlobalScanTemplate', { 'name' => template })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

end
end

unless @global_scan_engines.empty?
engines = xml.add_element('GlobalScanEngines')
@global_scan_engines.each do |engine|
engines.add_element('GlobalScanEngine', {'name' => engine})
engines.add_element('GlobalScanEngine', { 'name' => engine })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

xml.add_attributes({'payment-application' => @payment_application, 'payment-version' => @payment_version, 'petroleum' => @petroleum, 'retail' => @retail, 'telecommunication' => @telecommunication, 'travel' => @travel})
xml.add_attributes({ 'acquirer-relationship' => @acquirer_relationship, 'agent-relationship' => @agent_relationship,
'ecommerce' => @ecommerce, 'grocery' => @grocery, 'mail-order' => @mail_order })
xml.add_attributes({ 'payment-application' => @payment_application, 'payment-version' => @payment_version,

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -284,20 +283,22 @@ def self.parse(xml)
def as_xml
xml = super
xml.name = 'Merchant'
xml.add_attributes({'acquirer-relationship' => @acquirer_relationship, 'agent-relationship' => @agent_relationship, 'ecommerce' => @ecommerce, 'grocery' => @grocery, 'mail-order' => @mail_order})
xml.add_attributes({'payment-application' => @payment_application, 'payment-version' => @payment_version, 'petroleum' => @petroleum, 'retail' => @retail, 'telecommunication' => @telecommunication, 'travel' => @travel})
xml.add_attributes({ 'acquirer-relationship' => @acquirer_relationship, 'agent-relationship' => @agent_relationship,

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

end

def as_xml
xml = REXML::Element.new('Organization')
xml.add_attributes({'company' => @company, 'email-address' => @email, 'first-name' => @first_name, 'last-name' => @last_name, 'phone-number' => @phone, 'title' => @title, 'url' => @url})
xml.add_attributes({ 'company' => @company, 'email-address' => @email, 'first-name' => @first_name,

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

address.country = xml.attributes['country']
end
end

def as_xml
xml = REXML::Element.new('Address')
xml.add_attributes({'city' => @city, 'country' => @country, 'line1' => @line1, 'line2' => @line2, 'state' => @state, 'zip' => @zip})
xml.add_attributes({ 'city' => @city, 'country' => @country, 'line1' => @line1, 'line2' => @line2, 'state' => @state, 'zip' => @zip })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -118,7 +116,8 @@ def delete(connection)

def as_xml
xml = REXML::Element.new('SiloConfig')
xml.add_attributes({'description' => @description, 'name' => @name, 'id' => @id, 'silo-profile-id' => @profile_id, 'max-assets' => @max_assets, 'max-users' => @max_users, 'max-hosted-assets' => @max_hosted_assets})
xml.add_attributes({ 'description' => @description, 'name' => @name, 'id' => @id, 'silo-profile-id' => @profile_id,

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -54,8 +53,8 @@ def update_engine(engine_id)
# each active scan on the engine.
#
def engine_activity(engine_id)
xml = make_xml('EngineActivityRequest', {'engine-id' => engine_id})
r = execute(xml)
xml = make_xml('EngineActivityRequest', { 'engine-id' => engine_id })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -10,8 +10,7 @@ class Connection
# @return [Boolean] true if engine successfully deleted.
#
def delete_engine(engine_id, scope = 'silo')
xml = make_xml('EngineDeleteRequest',
{'engine-id' => engine_id, 'scope' => scope})
xml = make_xml('EngineDeleteRequest', { 'engine-id' => engine_id, 'scope' => scope })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

ON = 'poweredOn'
OFF = 'poweredOff'
ON = 'poweredOn'
OFF = 'poweredOff'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

end

module Value
module PowerState
ON = 'poweredOn'
OFF = 'poweredOff'
ON = 'poweredOn'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

@@ -45,7 +45,7 @@ module Field
INSTANCE_TYPE = 'INSTANCE_TYPE'

# Valid Operators: IN, NOT_IN
REGION ='REGION'
REGION = 'REGION'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

@@ -10,11 +10,11 @@ class Connection
# @return [Boolean] Whether group deletion succeeded.
#
def delete_asset_group(id)
r = execute(make_xml('AssetGroupDeleteRequest', {'group-id' => id}))
r = execute(make_xml('AssetGroupDeleteRequest', { 'group-id' => id }))

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -18,8 +18,7 @@ def save(nsc)

def to_h
{
blackouts:
(@blackout || []).map { |blackout| blackout.to_h }
blackouts: (@blackout || []).map { |blackout| blackout.to_h }

Choose a reason for hiding this comment

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

Pass &:to_h as an argument to map instead of a block.

# TODO: A problem in Nexpose causes these values to not be constant.
METASPLOIT = 'type:"exploit_source_type", name:"2"'
DATABASE = 'type:"exploit_source_type", name:"1"'
DATABASE = 'type:"exploit_source_type", name:"1"'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

end

# Constants for filtering on vulnerability exposure.
module VulnerabilityExposure
MALWARE = 'type:"malware_type", name:"malwarekit"'
MALWARE = 'type:"malware_type", name:"malwarekit"'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

UNKNOWN = '0'
VIRTUAL = '1'
UNKNOWN = '0'
VIRTUAL = '1'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

@@ -54,8 +53,8 @@ def update_engine(engine_id)
# each active scan on the engine.
#
def engine_activity(engine_id)
xml = make_xml('EngineActivityRequest', {'engine-id' => engine_id})
r = execute(xml)
xml = make_xml('EngineActivityRequest', { 'engine-id' => engine_id })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -10,8 +10,7 @@ class Connection
# @return [Boolean] true if engine successfully deleted.
#
def delete_engine(engine_id, scope = 'silo')
xml = make_xml('EngineDeleteRequest',
{'engine-id' => engine_id, 'scope' => scope})
xml = make_xml('EngineDeleteRequest', { 'engine-id' => engine_id, 'scope' => scope })

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

ON = 'poweredOn'
OFF = 'poweredOff'
ON = 'poweredOn'
OFF = 'poweredOff'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

end

module Value
module PowerState
ON = 'poweredOn'
OFF = 'poweredOff'
ON = 'poweredOn'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

@@ -45,7 +45,7 @@ module Field
INSTANCE_TYPE = 'INSTANCE_TYPE'

# Valid Operators: IN, NOT_IN
REGION ='REGION'
REGION = 'REGION'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

@@ -10,11 +10,11 @@ class Connection
# @return [Boolean] Whether group deletion succeeded.
#
def delete_asset_group(id)
r = execute(make_xml('AssetGroupDeleteRequest', {'group-id' => id}))
r = execute(make_xml('AssetGroupDeleteRequest', { 'group-id' => id }))

Choose a reason for hiding this comment

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

Redundant curly braces around a hash parameter.

@@ -18,8 +18,7 @@ def save(nsc)

def to_h
{
blackouts:
(@blackout || []).map { |blackout| blackout.to_h }
blackouts: (@blackout || []).map { |blackout| blackout.to_h }

Choose a reason for hiding this comment

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

Pass &:to_h as an argument to map instead of a block.

# TODO: A problem in Nexpose causes these values to not be constant.
METASPLOIT = 'type:"exploit_source_type", name:"2"'
DATABASE = 'type:"exploit_source_type", name:"1"'
DATABASE = 'type:"exploit_source_type", name:"1"'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

end

# Constants for filtering on vulnerability exposure.
module VulnerabilityExposure
MALWARE = 'type:"malware_type", name:"malwarekit"'
MALWARE = 'type:"malware_type", name:"malwarekit"'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

UNKNOWN = '0'
VIRTUAL = '1'
UNKNOWN = '0'
VIRTUAL = '1'

Choose a reason for hiding this comment

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

Freeze mutable objects assigned to constants.

end

def integration_status_proc(nexpose_connection:, scan_id:, status:)
Proc.new { nexpose_connection.scan_status(scan_id).downcase == status.downcase }
proc { nexpose_connection.scan_status(scan_id).downcase == status.downcase }

Choose a reason for hiding this comment

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

Use casecmp instead of downcase ==.

end
def status_string_to_constant(status)
Nexpose::VulnException::Status.constants.find do |name|
Nexpose::VulnException::Status.const_get(name).to_s.downcase == status.downcase || status.to_sym.downcase == name.downcase

Choose a reason for hiding this comment

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

Use casecmp instead of downcase ==.

@sgreen-r7 sgreen-r7 merged commit 88d1bcd into master Sep 11, 2017
@sgreen-r7 sgreen-r7 deleted the cleanup_v3 branch September 11, 2017 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants