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

Refactor/Extract Common Credential Module #98

Merged
merged 11 commits into from
Dec 29, 2014
Merged
Prev Previous commit
Next Next commit
rename Type to Service for Credential::Service, added new type PBRUN …
…to ElevationType, changed test method signature to accept siteid.
  • Loading branch information
sgreen-r7 committed Dec 29, 2014
commit 574f722fbc670342200f9237cdcade06989e45b3
17 changes: 9 additions & 8 deletions lib/nexpose/credential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Credential
'db2' => 50000 }


# Credential type options.
module Type
# Credential Service/Type Options.
module Service
CVS = 'cvs' # Concurrent Versioning System (CVS)
FTP = 'ftp' # File Transfer Protocol (FTP)
HTTP = 'http' # Web Site HTTP Authentication
Expand Down Expand Up @@ -58,6 +58,7 @@ module ElevationType
SUDO = 'SUDO'
SUDOSU = 'SUDOSU'
SU = 'SU'
PBRUN = 'PBRUN'
end


Expand All @@ -70,22 +71,22 @@ module ElevationType
# @param [Fixnum] engine_id ID of the engine to use for testing credentials.
# Will default to the local engine if none is provided.
#
def test(nsc, target, engine_id = nil)
def test(nsc, target, engine_id = nil, siteid = -1)
unless engine_id
engine_id = nsc.engines.find { |e| e.name == 'Local scan engine' }.id
end
@port = Credential::DEFAULT_PORTS[@type] if @port.nil?
parameters = _to_param(target, engine_id, @port)
@port = Credential::DEFAULT_PORTS[@service] if @port.nil?
parameters = _to_param(target, engine_id, @port, siteid)
xml = AJAX.form_post(nsc, '/ajax/test_admin_credentials.txml', parameters)
result = REXML::XPath.first(REXML::Document.new(xml), 'TestAdminCredentialsResult')
result.attributes['success'].to_i == 1
end


def _to_param(target, engine_id, port)
def _to_param(target, engine_id, port, siteid)
{ engineid: engine_id,
sc_creds_dev: target,
sc_creds_svc: @type,
sc_creds_svc: @service,
sc_creds_database: @database,
sc_creds_domain: @domain,
sc_creds_uname: @username,
Expand All @@ -98,7 +99,7 @@ def _to_param(target, engine_id, port)
sc_creds_snmpv3authtype: @auth_type,
sc_creds_snmpv3privtype: @privacy_type,
sc_creds_snmpv3privpassword: @privacy_password,
siteid: -1 }
siteid: siteid }
end

end
Expand Down
6 changes: 4 additions & 2 deletions lib/nexpose/shared_credential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ class SharedCredentialSummary < Credential
attr_accessor :id
# Name to identify this credential.
attr_accessor :name
# The credential type. See Nexpose::Credential::Type.
attr_accessor :type
# The credential service/type. See Nexpose::Credential::Service.
attr_accessor :service
alias :type :service
alias :type= :service=
# Domain or realm.
attr_accessor :domain
# User name.
Expand Down
3 changes: 0 additions & 3 deletions lib/nexpose/site_credential.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class SiteCredential < Credential
# The privacy/encryption pass phrase to use with SNMP v3 credentials
attr_accessor :privacy_password


# The site credential type. See Nexpose::Credential::Type.
attr_accessor :type
# Permission elevation type. See Nexpose::Credential::ElevationType.
attr_accessor :privilege_type
# The User ID or Username
Expand Down