id
int32 0
24.9k
| repo
stringlengths 5
58
| path
stringlengths 9
168
| func_name
stringlengths 9
130
| original_string
stringlengths 66
10.5k
| language
stringclasses 1
value | code
stringlengths 66
10.5k
| code_tokens
list | docstring
stringlengths 8
16k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 94
266
|
|---|---|---|---|---|---|---|---|---|---|---|---|
18,900
|
rapid7/nexpose-client
|
lib/nexpose/device.rb
|
Nexpose.Connection.list_device_vulns
|
def list_device_vulns(dev_id)
parameters = { 'devid' => dev_id,
'table-id' => 'vulnerability-listing' }
json = DataTable._get_json_table(self,
'/data/vulnerability/asset-vulnerabilities',
parameters)
json.map { |vuln| VulnFinding.new(vuln) }
end
|
ruby
|
def list_device_vulns(dev_id)
parameters = { 'devid' => dev_id,
'table-id' => 'vulnerability-listing' }
json = DataTable._get_json_table(self,
'/data/vulnerability/asset-vulnerabilities',
parameters)
json.map { |vuln| VulnFinding.new(vuln) }
end
|
[
"def",
"list_device_vulns",
"(",
"dev_id",
")",
"parameters",
"=",
"{",
"'devid'",
"=>",
"dev_id",
",",
"'table-id'",
"=>",
"'vulnerability-listing'",
"}",
"json",
"=",
"DataTable",
".",
"_get_json_table",
"(",
"self",
",",
"'/data/vulnerability/asset-vulnerabilities'",
",",
"parameters",
")",
"json",
".",
"map",
"{",
"|",
"vuln",
"|",
"VulnFinding",
".",
"new",
"(",
"vuln",
")",
"}",
"end"
] |
List the vulnerability findings for a given device ID.
@param [Fixnum] dev_id Unique identifier of a device (asset).
@return [Array[VulnFinding]] List of vulnerability findings.
|
[
"List",
"the",
"vulnerability",
"findings",
"for",
"a",
"given",
"device",
"ID",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L85-L92
|
18,901
|
rapid7/nexpose-client
|
lib/nexpose/device.rb
|
Nexpose.Connection.incomplete_assets
|
def incomplete_assets(scan_id)
uri = "/data/asset/scan/#{scan_id}/incomplete-assets"
AJAX.preserving_preference(self, 'scan-incomplete-assets') do
data = DataTable._get_json_table(self, uri, {}, 500, nil, false)
data.map(&IncompleteAsset.method(:parse_json))
end
end
|
ruby
|
def incomplete_assets(scan_id)
uri = "/data/asset/scan/#{scan_id}/incomplete-assets"
AJAX.preserving_preference(self, 'scan-incomplete-assets') do
data = DataTable._get_json_table(self, uri, {}, 500, nil, false)
data.map(&IncompleteAsset.method(:parse_json))
end
end
|
[
"def",
"incomplete_assets",
"(",
"scan_id",
")",
"uri",
"=",
"\"/data/asset/scan/#{scan_id}/incomplete-assets\"",
"AJAX",
".",
"preserving_preference",
"(",
"self",
",",
"'scan-incomplete-assets'",
")",
"do",
"data",
"=",
"DataTable",
".",
"_get_json_table",
"(",
"self",
",",
"uri",
",",
"{",
"}",
",",
"500",
",",
"nil",
",",
"false",
")",
"data",
".",
"map",
"(",
"IncompleteAsset",
".",
"method",
"(",
":parse_json",
")",
")",
"end",
"end"
] |
Retrieve a list of assets which are incomplete in a given scan. If called
during a scan, this method returns currently incomplete assets which may
be in progress.
@param [Fixnum] scan_id Unique identifier of a scan.
@return [Array[IncompleteAsset]] List of incomplete assets.
|
[
"Retrieve",
"a",
"list",
"of",
"assets",
"which",
"are",
"incomplete",
"in",
"a",
"given",
"scan",
".",
"If",
"called",
"during",
"a",
"scan",
"this",
"method",
"returns",
"currently",
"incomplete",
"assets",
"which",
"may",
"be",
"in",
"progress",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L121-L127
|
18,902
|
rapid7/nexpose-client
|
lib/nexpose/alert.rb
|
Nexpose.Alert.delete
|
def delete(nsc, site_id)
uri = "/api/2.1/site_configurations/#{site_id}/alerts/#{id}"
AJAX.delete(nsc, uri, AJAX::CONTENT_TYPE::JSON)
end
|
ruby
|
def delete(nsc, site_id)
uri = "/api/2.1/site_configurations/#{site_id}/alerts/#{id}"
AJAX.delete(nsc, uri, AJAX::CONTENT_TYPE::JSON)
end
|
[
"def",
"delete",
"(",
"nsc",
",",
"site_id",
")",
"uri",
"=",
"\"/api/2.1/site_configurations/#{site_id}/alerts/#{id}\"",
"AJAX",
".",
"delete",
"(",
"nsc",
",",
"uri",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"end"
] |
delete an alert from the given site
|
[
"delete",
"an",
"alert",
"from",
"the",
"given",
"site"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/alert.rb#L114-L117
|
18,903
|
rapid7/nexpose-client
|
lib/nexpose/alert.rb
|
Nexpose.Alert.save
|
def save(nsc, site_id)
validate
uri = "/api/2.1/site_configurations/#{site_id}/alerts"
id = AJAX.put(nsc, uri, self.to_json, AJAX::CONTENT_TYPE::JSON)
@id = id.to_i
end
|
ruby
|
def save(nsc, site_id)
validate
uri = "/api/2.1/site_configurations/#{site_id}/alerts"
id = AJAX.put(nsc, uri, self.to_json, AJAX::CONTENT_TYPE::JSON)
@id = id.to_i
end
|
[
"def",
"save",
"(",
"nsc",
",",
"site_id",
")",
"validate",
"uri",
"=",
"\"/api/2.1/site_configurations/#{site_id}/alerts\"",
"id",
"=",
"AJAX",
".",
"put",
"(",
"nsc",
",",
"uri",
",",
"self",
".",
"to_json",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"@id",
"=",
"id",
".",
"to_i",
"end"
] |
save an alert for a given site
|
[
"save",
"an",
"alert",
"for",
"a",
"given",
"site"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/alert.rb#L120-L125
|
18,904
|
rapid7/nexpose-client
|
lib/nexpose/multi_tenant_user.rb
|
Nexpose.Connection.list_silo_users
|
def list_silo_users
r = execute(make_xml('MultiTenantUserListingRequest'), '1.2')
arr = []
if r.success
r.res.elements.each('MultiTenantUserListingResponse/MultiTenantUserSummaries/MultiTenantUserSummary') do |user|
arr << MultiTenantUserSummary.parse(user)
end
end
arr
end
|
ruby
|
def list_silo_users
r = execute(make_xml('MultiTenantUserListingRequest'), '1.2')
arr = []
if r.success
r.res.elements.each('MultiTenantUserListingResponse/MultiTenantUserSummaries/MultiTenantUserSummary') do |user|
arr << MultiTenantUserSummary.parse(user)
end
end
arr
end
|
[
"def",
"list_silo_users",
"r",
"=",
"execute",
"(",
"make_xml",
"(",
"'MultiTenantUserListingRequest'",
")",
",",
"'1.2'",
")",
"arr",
"=",
"[",
"]",
"if",
"r",
".",
"success",
"r",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'MultiTenantUserListingResponse/MultiTenantUserSummaries/MultiTenantUserSummary'",
")",
"do",
"|",
"user",
"|",
"arr",
"<<",
"MultiTenantUserSummary",
".",
"parse",
"(",
"user",
")",
"end",
"end",
"arr",
"end"
] |
Retrieve a list of all users the user is authorized to view or manage.
@return [Array[MultiTenantUserSummary]] Array of MultiTenantUserSummary objects.
|
[
"Retrieve",
"a",
"list",
"of",
"all",
"users",
"the",
"user",
"is",
"authorized",
"to",
"view",
"or",
"manage",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/multi_tenant_user.rb#L10-L19
|
18,905
|
rapid7/nexpose-client
|
lib/nexpose/engine.rb
|
Nexpose.Connection.delete_engine
|
def delete_engine(engine_id, scope = 'silo')
xml = make_xml('EngineDeleteRequest', { 'engine-id' => engine_id, 'scope' => scope })
response = execute(xml, '1.2')
response.success
end
|
ruby
|
def delete_engine(engine_id, scope = 'silo')
xml = make_xml('EngineDeleteRequest', { 'engine-id' => engine_id, 'scope' => scope })
response = execute(xml, '1.2')
response.success
end
|
[
"def",
"delete_engine",
"(",
"engine_id",
",",
"scope",
"=",
"'silo'",
")",
"xml",
"=",
"make_xml",
"(",
"'EngineDeleteRequest'",
",",
"{",
"'engine-id'",
"=>",
"engine_id",
",",
"'scope'",
"=>",
"scope",
"}",
")",
"response",
"=",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"response",
".",
"success",
"end"
] |
Removes a scan engine from the list of available engines.
@param [Fixnum] engine_id Unique ID of an existing engine to remove.
@param [String] scope Whether the engine is global or silo scoped.
@return [Boolean] true if engine successfully deleted.
|
[
"Removes",
"a",
"scan",
"engine",
"from",
"the",
"list",
"of",
"available",
"engines",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/engine.rb#L12-L16
|
18,906
|
rapid7/nexpose-client
|
lib/nexpose/engine.rb
|
Nexpose.Connection.engine_activity
|
def engine_activity(engine_id)
xml = make_xml('EngineActivityRequest', { 'engine-id' => engine_id })
r = execute(xml)
arr = []
if r.success
r.res.elements.each('//ScanSummary') do |scan_event|
arr << ScanSummary.parse(scan_event)
end
end
arr
end
|
ruby
|
def engine_activity(engine_id)
xml = make_xml('EngineActivityRequest', { 'engine-id' => engine_id })
r = execute(xml)
arr = []
if r.success
r.res.elements.each('//ScanSummary') do |scan_event|
arr << ScanSummary.parse(scan_event)
end
end
arr
end
|
[
"def",
"engine_activity",
"(",
"engine_id",
")",
"xml",
"=",
"make_xml",
"(",
"'EngineActivityRequest'",
",",
"{",
"'engine-id'",
"=>",
"engine_id",
"}",
")",
"r",
"=",
"execute",
"(",
"xml",
")",
"arr",
"=",
"[",
"]",
"if",
"r",
".",
"success",
"r",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'//ScanSummary'",
")",
"do",
"|",
"scan_event",
"|",
"arr",
"<<",
"ScanSummary",
".",
"parse",
"(",
"scan_event",
")",
"end",
"end",
"arr",
"end"
] |
Provide a list of current scan activities for a specific Scan Engine.
@return [Array[ScanSummary]] Array of ScanSummary objects associated with
each active scan on the engine.
|
[
"Provide",
"a",
"list",
"of",
"current",
"scan",
"activities",
"for",
"a",
"specific",
"Scan",
"Engine",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/engine.rb#L55-L65
|
18,907
|
rapid7/nexpose-client
|
lib/nexpose/engine.rb
|
Nexpose.Connection.list_engines
|
def list_engines
response = execute(make_xml('EngineListingRequest'))
arr = []
if response.success
response.res.elements.each('//EngineSummary') do |engine|
arr << EngineSummary.new(engine.attributes['id'].to_i,
engine.attributes['name'],
engine.attributes['address'],
engine.attributes['port'].to_i,
engine.attributes['status'],
engine.attributes['scope'])
end
end
arr
end
|
ruby
|
def list_engines
response = execute(make_xml('EngineListingRequest'))
arr = []
if response.success
response.res.elements.each('//EngineSummary') do |engine|
arr << EngineSummary.new(engine.attributes['id'].to_i,
engine.attributes['name'],
engine.attributes['address'],
engine.attributes['port'].to_i,
engine.attributes['status'],
engine.attributes['scope'])
end
end
arr
end
|
[
"def",
"list_engines",
"response",
"=",
"execute",
"(",
"make_xml",
"(",
"'EngineListingRequest'",
")",
")",
"arr",
"=",
"[",
"]",
"if",
"response",
".",
"success",
"response",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'//EngineSummary'",
")",
"do",
"|",
"engine",
"|",
"arr",
"<<",
"EngineSummary",
".",
"new",
"(",
"engine",
".",
"attributes",
"[",
"'id'",
"]",
".",
"to_i",
",",
"engine",
".",
"attributes",
"[",
"'name'",
"]",
",",
"engine",
".",
"attributes",
"[",
"'address'",
"]",
",",
"engine",
".",
"attributes",
"[",
"'port'",
"]",
".",
"to_i",
",",
"engine",
".",
"attributes",
"[",
"'status'",
"]",
",",
"engine",
".",
"attributes",
"[",
"'scope'",
"]",
")",
"end",
"end",
"arr",
"end"
] |
Retrieve a list of all Scan Engines managed by the Security Console.
@return [Array[EngineSummary]] Array of EngineSummary objects associated
with each engine associated with this security console.
|
[
"Retrieve",
"a",
"list",
"of",
"all",
"Scan",
"Engines",
"managed",
"by",
"the",
"Security",
"Console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/engine.rb#L72-L86
|
18,908
|
rapid7/nexpose-client
|
lib/nexpose/engine.rb
|
Nexpose.Engine.save
|
def save(connection)
xml = '<EngineSaveRequest session-id="' + connection.session_id + '">'
xml << to_xml
xml << '</EngineSaveRequest>'
r = connection.execute(xml, '1.2')
if r.success
r.res.elements.each('EngineSaveResponse/EngineConfig') do |v|
return @id = v.attributes['id'].to_i
end
end
end
|
ruby
|
def save(connection)
xml = '<EngineSaveRequest session-id="' + connection.session_id + '">'
xml << to_xml
xml << '</EngineSaveRequest>'
r = connection.execute(xml, '1.2')
if r.success
r.res.elements.each('EngineSaveResponse/EngineConfig') do |v|
return @id = v.attributes['id'].to_i
end
end
end
|
[
"def",
"save",
"(",
"connection",
")",
"xml",
"=",
"'<EngineSaveRequest session-id=\"'",
"+",
"connection",
".",
"session_id",
"+",
"'\">'",
"xml",
"<<",
"to_xml",
"xml",
"<<",
"'</EngineSaveRequest>'",
"r",
"=",
"connection",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"if",
"r",
".",
"success",
"r",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'EngineSaveResponse/EngineConfig'",
")",
"do",
"|",
"v",
"|",
"return",
"@id",
"=",
"v",
".",
"attributes",
"[",
"'id'",
"]",
".",
"to_i",
"end",
"end",
"end"
] |
Save this engine configuration to the security console.
@param [Connection] connection Connection to console where site exists.
@return [Fixnum] ID assigned to the scan engine.
|
[
"Save",
"this",
"engine",
"configuration",
"to",
"the",
"security",
"console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/engine.rb#L210-L221
|
18,909
|
rapid7/nexpose-client
|
lib/nexpose/vuln_def.rb
|
Nexpose.Connection.all_vulns
|
def all_vulns
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, per_page: 2_147_483_647)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
ruby
|
def all_vulns
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, per_page: 2_147_483_647)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
[
"def",
"all_vulns",
"uri",
"=",
"'/api/2.0/vulnerability_definitions'",
"resp",
"=",
"AJAX",
".",
"get",
"(",
"self",
",",
"uri",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"per_page",
":",
"2_147_483_647",
")",
"json",
"=",
"JSON",
".",
"parse",
"(",
"resp",
",",
"symbolize_names",
":",
"true",
")",
"json",
"[",
":resources",
"]",
".",
"map",
"{",
"|",
"e",
"|",
"VulnerabilityDefinition",
".",
"new",
".",
"object_from_hash",
"(",
"self",
",",
"e",
")",
"}",
"end"
] |
Retrieve all vulnerability definitions currently in a Nexpose console.
Note, this can easily take 30 seconds to complete and will load over
55,000 vulnerability definitions.
@return [Array[VulnerabilityDefinition]] Collection of vulnerability definitions.
|
[
"Retrieve",
"all",
"vulnerability",
"definitions",
"currently",
"in",
"a",
"Nexpose",
"console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_def.rb#L10-L15
|
18,910
|
rapid7/nexpose-client
|
lib/nexpose/vuln_def.rb
|
Nexpose.Connection.find_vulns_by_cve
|
def find_vulns_by_cve(cve)
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, cve: cve)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
ruby
|
def find_vulns_by_cve(cve)
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, cve: cve)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
[
"def",
"find_vulns_by_cve",
"(",
"cve",
")",
"uri",
"=",
"'/api/2.0/vulnerability_definitions'",
"resp",
"=",
"AJAX",
".",
"get",
"(",
"self",
",",
"uri",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"cve",
":",
"cve",
")",
"json",
"=",
"JSON",
".",
"parse",
"(",
"resp",
",",
"symbolize_names",
":",
"true",
")",
"json",
"[",
":resources",
"]",
".",
"map",
"{",
"|",
"e",
"|",
"VulnerabilityDefinition",
".",
"new",
".",
"object_from_hash",
"(",
"self",
",",
"e",
")",
"}",
"end"
] |
Search for any vulnerability definitions which refer to a given CVE.
@param [String] cve A valid CVE.
@return [Array[VulnerabilityDefinition]] A list of vuln definitions which check the CVE.
|
[
"Search",
"for",
"any",
"vulnerability",
"definitions",
"which",
"refer",
"to",
"a",
"given",
"CVE",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_def.rb#L22-L27
|
18,911
|
rapid7/nexpose-client
|
lib/nexpose/vuln_def.rb
|
Nexpose.Connection.find_vulns_by_ref
|
def find_vulns_by_ref(source, id)
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self,
uri,
AJAX::CONTENT_TYPE::JSON,
source: source, id: id)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
ruby
|
def find_vulns_by_ref(source, id)
uri = '/api/2.0/vulnerability_definitions'
resp = AJAX.get(self,
uri,
AJAX::CONTENT_TYPE::JSON,
source: source, id: id)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
[
"def",
"find_vulns_by_ref",
"(",
"source",
",",
"id",
")",
"uri",
"=",
"'/api/2.0/vulnerability_definitions'",
"resp",
"=",
"AJAX",
".",
"get",
"(",
"self",
",",
"uri",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"source",
":",
"source",
",",
"id",
":",
"id",
")",
"json",
"=",
"JSON",
".",
"parse",
"(",
"resp",
",",
"symbolize_names",
":",
"true",
")",
"json",
"[",
":resources",
"]",
".",
"map",
"{",
"|",
"e",
"|",
"VulnerabilityDefinition",
".",
"new",
".",
"object_from_hash",
"(",
"self",
",",
"e",
")",
"}",
"end"
] |
Search for any vulnerability definitions which refer to a given reference
ID.
Examples:
find_vulns_by_ref('oval', 'OVAL10476')
find_vulns_by_ref('bid', 35067)
find_vulns_by_ref('secunia', 35188)
@param [String] source External vulnerability reference source.
@param [String] id Unique vulnerability reference ID.
@return [Array[VulnerabilityDefinition]] A list of vuln definitions which
check the vulnerability.
|
[
"Search",
"for",
"any",
"vulnerability",
"definitions",
"which",
"refer",
"to",
"a",
"given",
"reference",
"ID",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_def.rb#L42-L50
|
18,912
|
rapid7/nexpose-client
|
lib/nexpose/vuln_def.rb
|
Nexpose.Connection.find_vulns_by_title
|
def find_vulns_by_title(title, all_words = true)
uri = '/api/2.0/vulnerability_definitions'
params = { title: title, all_words: all_words }
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, params)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
ruby
|
def find_vulns_by_title(title, all_words = true)
uri = '/api/2.0/vulnerability_definitions'
params = { title: title, all_words: all_words }
resp = AJAX.get(self, uri, AJAX::CONTENT_TYPE::JSON, params)
json = JSON.parse(resp, symbolize_names: true)
json[:resources].map { |e| VulnerabilityDefinition.new.object_from_hash(self, e) }
end
|
[
"def",
"find_vulns_by_title",
"(",
"title",
",",
"all_words",
"=",
"true",
")",
"uri",
"=",
"'/api/2.0/vulnerability_definitions'",
"params",
"=",
"{",
"title",
":",
"title",
",",
"all_words",
":",
"all_words",
"}",
"resp",
"=",
"AJAX",
".",
"get",
"(",
"self",
",",
"uri",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"params",
")",
"json",
"=",
"JSON",
".",
"parse",
"(",
"resp",
",",
"symbolize_names",
":",
"true",
")",
"json",
"[",
":resources",
"]",
".",
"map",
"{",
"|",
"e",
"|",
"VulnerabilityDefinition",
".",
"new",
".",
"object_from_hash",
"(",
"self",
",",
"e",
")",
"}",
"end"
] |
Search for any vulnerability definitions which refer to a given title.
Note: This method will return a maximum of 500 results. If the search
yields a high number of results, consider add more specific words to
the title.
@param [String] title A (partial) title to search for.
@param [Boolean] all_words Whether to include all words from the search
phrase in the search.
@return [Array[VulnerabilityDefinition]] A list of vuln definitions with titles matching
the provided value.
|
[
"Search",
"for",
"any",
"vulnerability",
"definitions",
"which",
"refer",
"to",
"a",
"given",
"title",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_def.rb#L64-L70
|
18,913
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Connection.tags
|
def tags
tag_summary = []
tags = JSON.parse(AJAX.get(self, '/api/2.0/tags', AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
tags['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
ruby
|
def tags
tag_summary = []
tags = JSON.parse(AJAX.get(self, '/api/2.0/tags', AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
tags['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
[
"def",
"tags",
"tag_summary",
"=",
"[",
"]",
"tags",
"=",
"JSON",
".",
"parse",
"(",
"AJAX",
".",
"get",
"(",
"self",
",",
"'/api/2.0/tags'",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"{",
"per_page",
":",
"2_147_483_647",
"}",
")",
")",
"tags",
"[",
"'resources'",
"]",
".",
"each",
"do",
"|",
"json",
"|",
"tag_summary",
"<<",
"TagSummary",
".",
"parse",
"(",
"json",
")",
"end",
"tag_summary",
"end"
] |
Lists all tags
@return [Array[TagSummary]] List of current tags.
|
[
"Lists",
"all",
"tags"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L9-L16
|
18,914
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Connection.asset_tags
|
def asset_tags(asset_id)
tag_summary = []
asset_tag = JSON.parse(AJAX.get(self, "/api/2.0/assets/#{asset_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
asset_tag['resources'].select { |r| r['asset_ids'].find { |i| i == asset_id } }.each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
ruby
|
def asset_tags(asset_id)
tag_summary = []
asset_tag = JSON.parse(AJAX.get(self, "/api/2.0/assets/#{asset_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
asset_tag['resources'].select { |r| r['asset_ids'].find { |i| i == asset_id } }.each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
[
"def",
"asset_tags",
"(",
"asset_id",
")",
"tag_summary",
"=",
"[",
"]",
"asset_tag",
"=",
"JSON",
".",
"parse",
"(",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/api/2.0/assets/#{asset_id}/tags\"",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"{",
"per_page",
":",
"2_147_483_647",
"}",
")",
")",
"asset_tag",
"[",
"'resources'",
"]",
".",
"select",
"{",
"|",
"r",
"|",
"r",
"[",
"'asset_ids'",
"]",
".",
"find",
"{",
"|",
"i",
"|",
"i",
"==",
"asset_id",
"}",
"}",
".",
"each",
"do",
"|",
"json",
"|",
"tag_summary",
"<<",
"TagSummary",
".",
"parse",
"(",
"json",
")",
"end",
"tag_summary",
"end"
] |
Lists all the tags on an asset
@param [Fixnum] asset_id of the asset to list the applied tags for
@return [Array[TagSummary]] list of tags on asset
|
[
"Lists",
"all",
"the",
"tags",
"on",
"an",
"asset"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L32-L39
|
18,915
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Connection.site_tags
|
def site_tags(site_id)
tag_summary = []
site_tag = JSON.parse(AJAX.get(self, "/api/2.0/sites/#{site_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
site_tag['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
ruby
|
def site_tags(site_id)
tag_summary = []
site_tag = JSON.parse(AJAX.get(self, "/api/2.0/sites/#{site_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
site_tag['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
[
"def",
"site_tags",
"(",
"site_id",
")",
"tag_summary",
"=",
"[",
"]",
"site_tag",
"=",
"JSON",
".",
"parse",
"(",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/api/2.0/sites/#{site_id}/tags\"",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"{",
"per_page",
":",
"2_147_483_647",
"}",
")",
")",
"site_tag",
"[",
"'resources'",
"]",
".",
"each",
"do",
"|",
"json",
"|",
"tag_summary",
"<<",
"TagSummary",
".",
"parse",
"(",
"json",
")",
"end",
"tag_summary",
"end"
] |
Lists all the tags on a site
@param [Fixnum] site_id id of the site to get the applied tags
@return [Array[TagSummary]] list of tags on site
|
[
"Lists",
"all",
"the",
"tags",
"on",
"a",
"site"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L56-L63
|
18,916
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Connection.asset_group_tags
|
def asset_group_tags(asset_group_id)
tag_summary = []
asset_group_tag = JSON.parse(AJAX.get(self, "/api/2.0/asset_groups/#{asset_group_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
asset_group_tag['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
ruby
|
def asset_group_tags(asset_group_id)
tag_summary = []
asset_group_tag = JSON.parse(AJAX.get(self, "/api/2.0/asset_groups/#{asset_group_id}/tags", AJAX::CONTENT_TYPE::JSON, { per_page: 2_147_483_647 }))
asset_group_tag['resources'].each do |json|
tag_summary << TagSummary.parse(json)
end
tag_summary
end
|
[
"def",
"asset_group_tags",
"(",
"asset_group_id",
")",
"tag_summary",
"=",
"[",
"]",
"asset_group_tag",
"=",
"JSON",
".",
"parse",
"(",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/api/2.0/asset_groups/#{asset_group_id}/tags\"",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
",",
"{",
"per_page",
":",
"2_147_483_647",
"}",
")",
")",
"asset_group_tag",
"[",
"'resources'",
"]",
".",
"each",
"do",
"|",
"json",
"|",
"tag_summary",
"<<",
"TagSummary",
".",
"parse",
"(",
"json",
")",
"end",
"tag_summary",
"end"
] |
Lists all the tags on an asset_group
@param [Fixnum] asset_group_id id of the group on which tags are listed
@return [Array[TagSummary]] list of tags on asset group
|
[
"Lists",
"all",
"the",
"tags",
"on",
"an",
"asset_group"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L80-L87
|
18,917
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Connection.selected_criticality_tag
|
def selected_criticality_tag(asset_id)
selected_criticality = AJAX.get(self, "/data/asset/#{asset_id}/selected-criticality-tag")
selected_criticality.empty? ? nil : JSON.parse(selected_criticality)['name']
end
|
ruby
|
def selected_criticality_tag(asset_id)
selected_criticality = AJAX.get(self, "/data/asset/#{asset_id}/selected-criticality-tag")
selected_criticality.empty? ? nil : JSON.parse(selected_criticality)['name']
end
|
[
"def",
"selected_criticality_tag",
"(",
"asset_id",
")",
"selected_criticality",
"=",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/data/asset/#{asset_id}/selected-criticality-tag\"",
")",
"selected_criticality",
".",
"empty?",
"?",
"nil",
":",
"JSON",
".",
"parse",
"(",
"selected_criticality",
")",
"[",
"'name'",
"]",
"end"
] |
Returns the criticality value which takes precedent for an asset
@param [Fixnum] asset_id id of asset on which criticality tag is selected
@return [String] selected_criticality string of the relevant criticality; nil if not tagged
|
[
"Returns",
"the",
"criticality",
"value",
"which",
"takes",
"precedent",
"for",
"an",
"asset"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L106-L109
|
18,918
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Tag.color=
|
def color=(hex)
valid_colors = Type::Color.constants.map { |c| Type::Color.const_get(c) }
unless hex.nil? || valid_colors.include?(hex.to_s.downcase)
raise ArgumentError, "Unable to set color to an invalid color.\nUse one of #{valid_colors}"
end
@color = hex
end
|
ruby
|
def color=(hex)
valid_colors = Type::Color.constants.map { |c| Type::Color.const_get(c) }
unless hex.nil? || valid_colors.include?(hex.to_s.downcase)
raise ArgumentError, "Unable to set color to an invalid color.\nUse one of #{valid_colors}"
end
@color = hex
end
|
[
"def",
"color",
"=",
"(",
"hex",
")",
"valid_colors",
"=",
"Type",
"::",
"Color",
".",
"constants",
".",
"map",
"{",
"|",
"c",
"|",
"Type",
"::",
"Color",
".",
"const_get",
"(",
"c",
")",
"}",
"unless",
"hex",
".",
"nil?",
"||",
"valid_colors",
".",
"include?",
"(",
"hex",
".",
"to_s",
".",
"downcase",
")",
"raise",
"ArgumentError",
",",
"\"Unable to set color to an invalid color.\\nUse one of #{valid_colors}\"",
"end",
"@color",
"=",
"hex",
"end"
] |
Set the color but validate it
|
[
"Set",
"the",
"color",
"but",
"validate",
"it"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L218-L225
|
18,919
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Tag.save
|
def save(connection)
params = to_json
if @id == -1
uri = AJAX.post(connection, '/api/2.0/tags', params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
else
AJAX.put(connection, "/api/2.0/tags/#{@id}", params, AJAX::CONTENT_TYPE::JSON)
end
@id
end
|
ruby
|
def save(connection)
params = to_json
if @id == -1
uri = AJAX.post(connection, '/api/2.0/tags', params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
else
AJAX.put(connection, "/api/2.0/tags/#{@id}", params, AJAX::CONTENT_TYPE::JSON)
end
@id
end
|
[
"def",
"save",
"(",
"connection",
")",
"params",
"=",
"to_json",
"if",
"@id",
"==",
"-",
"1",
"uri",
"=",
"AJAX",
".",
"post",
"(",
"connection",
",",
"'/api/2.0/tags'",
",",
"params",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"@id",
"=",
"uri",
".",
"split",
"(",
"'/'",
")",
".",
"last",
".",
"to_i",
"else",
"AJAX",
".",
"put",
"(",
"connection",
",",
"\"/api/2.0/tags/#{@id}\"",
",",
"params",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"end",
"@id",
"end"
] |
Creates and saves a tag to Nexpose console
@param [Connection] connection Nexpose connection
@return [Fixnum] ID of saved tag
|
[
"Creates",
"and",
"saves",
"a",
"tag",
"to",
"Nexpose",
"console"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L267-L276
|
18,920
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Tag.add_to_asset
|
def add_to_asset(connection, asset_id)
params = to_json_for_add
url = "/api/2.0/assets/#{asset_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
ruby
|
def add_to_asset(connection, asset_id)
params = to_json_for_add
url = "/api/2.0/assets/#{asset_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
[
"def",
"add_to_asset",
"(",
"connection",
",",
"asset_id",
")",
"params",
"=",
"to_json_for_add",
"url",
"=",
"\"/api/2.0/assets/#{asset_id}/tags\"",
"uri",
"=",
"AJAX",
".",
"post",
"(",
"connection",
",",
"url",
",",
"params",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"@id",
"=",
"uri",
".",
"split",
"(",
"'/'",
")",
".",
"last",
".",
"to_i",
"end"
] |
Adds a tag to an asset
@param [Connection] connection Nexpose connection
@param [Fixnum] asset_id of the asset to be tagged
@return [Fixnum] ID of applied tag
|
[
"Adds",
"a",
"tag",
"to",
"an",
"asset"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L340-L345
|
18,921
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Tag.add_to_site
|
def add_to_site(connection, site_id)
params = to_json_for_add
url = "/api/2.0/sites/#{site_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
ruby
|
def add_to_site(connection, site_id)
params = to_json_for_add
url = "/api/2.0/sites/#{site_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
[
"def",
"add_to_site",
"(",
"connection",
",",
"site_id",
")",
"params",
"=",
"to_json_for_add",
"url",
"=",
"\"/api/2.0/sites/#{site_id}/tags\"",
"uri",
"=",
"AJAX",
".",
"post",
"(",
"connection",
",",
"url",
",",
"params",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"@id",
"=",
"uri",
".",
"split",
"(",
"'/'",
")",
".",
"last",
".",
"to_i",
"end"
] |
Adds a tag to a site
@param [Connection] connection Nexpose connection
@param [Fixnum] site_id of the site to be tagged
@return [Fixnum] ID of applied tag
|
[
"Adds",
"a",
"tag",
"to",
"a",
"site"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L353-L358
|
18,922
|
rapid7/nexpose-client
|
lib/nexpose/tag.rb
|
Nexpose.Tag.add_to_group
|
def add_to_group(connection, group_id)
params = to_json_for_add
url = "/api/2.0/asset_groups/#{group_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
ruby
|
def add_to_group(connection, group_id)
params = to_json_for_add
url = "/api/2.0/asset_groups/#{group_id}/tags"
uri = AJAX.post(connection, url, params, AJAX::CONTENT_TYPE::JSON)
@id = uri.split('/').last.to_i
end
|
[
"def",
"add_to_group",
"(",
"connection",
",",
"group_id",
")",
"params",
"=",
"to_json_for_add",
"url",
"=",
"\"/api/2.0/asset_groups/#{group_id}/tags\"",
"uri",
"=",
"AJAX",
".",
"post",
"(",
"connection",
",",
"url",
",",
"params",
",",
"AJAX",
"::",
"CONTENT_TYPE",
"::",
"JSON",
")",
"@id",
"=",
"uri",
".",
"split",
"(",
"'/'",
")",
".",
"last",
".",
"to_i",
"end"
] |
Adds a tag to an asset group
@param [Connection] connection Nexpose connection
@param [Fixnum] group_id id of the asset group to be tagged
@return [Fixnum] ID of applied tag
|
[
"Adds",
"a",
"tag",
"to",
"an",
"asset",
"group"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/tag.rb#L366-L371
|
18,923
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.Connection.list_vuln_exceptions
|
def list_vuln_exceptions(status = nil)
unless is_valid_vuln_exception_status?(status)
raise "Unknown Status ~> '#{status}' :: For available options refer to Nexpose::VulnException::Status"
end
status = Nexpose::VulnException::Status.const_get(status_string_to_constant(status)) unless status.nil?
results = []
ajax_data = []
url_size = 500
url_page = 0
req = Nexpose::AJAX.get(self, "/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}")
data = JSON.parse(req, object_class: OpenStruct)
ajax_data << data.resources
if data.links.count > 1
loop do
url_page += 1
req = Nexpose::AJAX.get(self, "/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}")
data = JSON.parse(req, object_class: OpenStruct)
ajax_data << data.resources
links = data.links.select { |ll| ['self', 'last'].include?(ll.rel) }
break if links[0].href == links[1].href
end
end
ajax_data.compact!
ajax_data.flatten!
ajax_data.each do |vuln_excep|
ve = VulnException.new(vuln_excep.scope.vulnerabilityID, vuln_excep.scope.type, vuln_excep.submit.reason, vuln_excep.state)
ve.id = vuln_excep.id
ve.submitter = vuln_excep.submit.name
ve.submitter_comment = vuln_excep.submit.comment
ve.submit_date = Time.parse(vuln_excep.submit.date) unless vuln_excep.submit.date.nil?
ve.asset_id = vuln_excep.scope.assetID
ve.site_id = vuln_excep.scope.siteID
ve.asset_group_id = vuln_excep.scope.assetGroupID
ve.port = vuln_excep.scope.port
ve.vuln_key = vuln_excep.scope.key
ve.expiration = Time.parse(vuln_excep.expires) unless vuln_excep.expires.nil?
unless vuln_excep.review.nil?
ve.reviewer = vuln_excep.review.name
ve.reviewer_comment = vuln_excep.review.comment
ve.review_date = Time.parse(vuln_excep.review.date) unless vuln_excep.review.date.nil?
end
results << ve
end
results.keep_if { |v| v.status == status } unless status.nil?
results
end
|
ruby
|
def list_vuln_exceptions(status = nil)
unless is_valid_vuln_exception_status?(status)
raise "Unknown Status ~> '#{status}' :: For available options refer to Nexpose::VulnException::Status"
end
status = Nexpose::VulnException::Status.const_get(status_string_to_constant(status)) unless status.nil?
results = []
ajax_data = []
url_size = 500
url_page = 0
req = Nexpose::AJAX.get(self, "/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}")
data = JSON.parse(req, object_class: OpenStruct)
ajax_data << data.resources
if data.links.count > 1
loop do
url_page += 1
req = Nexpose::AJAX.get(self, "/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}")
data = JSON.parse(req, object_class: OpenStruct)
ajax_data << data.resources
links = data.links.select { |ll| ['self', 'last'].include?(ll.rel) }
break if links[0].href == links[1].href
end
end
ajax_data.compact!
ajax_data.flatten!
ajax_data.each do |vuln_excep|
ve = VulnException.new(vuln_excep.scope.vulnerabilityID, vuln_excep.scope.type, vuln_excep.submit.reason, vuln_excep.state)
ve.id = vuln_excep.id
ve.submitter = vuln_excep.submit.name
ve.submitter_comment = vuln_excep.submit.comment
ve.submit_date = Time.parse(vuln_excep.submit.date) unless vuln_excep.submit.date.nil?
ve.asset_id = vuln_excep.scope.assetID
ve.site_id = vuln_excep.scope.siteID
ve.asset_group_id = vuln_excep.scope.assetGroupID
ve.port = vuln_excep.scope.port
ve.vuln_key = vuln_excep.scope.key
ve.expiration = Time.parse(vuln_excep.expires) unless vuln_excep.expires.nil?
unless vuln_excep.review.nil?
ve.reviewer = vuln_excep.review.name
ve.reviewer_comment = vuln_excep.review.comment
ve.review_date = Time.parse(vuln_excep.review.date) unless vuln_excep.review.date.nil?
end
results << ve
end
results.keep_if { |v| v.status == status } unless status.nil?
results
end
|
[
"def",
"list_vuln_exceptions",
"(",
"status",
"=",
"nil",
")",
"unless",
"is_valid_vuln_exception_status?",
"(",
"status",
")",
"raise",
"\"Unknown Status ~> '#{status}' :: For available options refer to Nexpose::VulnException::Status\"",
"end",
"status",
"=",
"Nexpose",
"::",
"VulnException",
"::",
"Status",
".",
"const_get",
"(",
"status_string_to_constant",
"(",
"status",
")",
")",
"unless",
"status",
".",
"nil?",
"results",
"=",
"[",
"]",
"ajax_data",
"=",
"[",
"]",
"url_size",
"=",
"500",
"url_page",
"=",
"0",
"req",
"=",
"Nexpose",
"::",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}\"",
")",
"data",
"=",
"JSON",
".",
"parse",
"(",
"req",
",",
"object_class",
":",
"OpenStruct",
")",
"ajax_data",
"<<",
"data",
".",
"resources",
"if",
"data",
".",
"links",
".",
"count",
">",
"1",
"loop",
"do",
"url_page",
"+=",
"1",
"req",
"=",
"Nexpose",
"::",
"AJAX",
".",
"get",
"(",
"self",
",",
"\"/api/3/vulnerability_exceptions?size=#{url_size}&page=#{url_page}\"",
")",
"data",
"=",
"JSON",
".",
"parse",
"(",
"req",
",",
"object_class",
":",
"OpenStruct",
")",
"ajax_data",
"<<",
"data",
".",
"resources",
"links",
"=",
"data",
".",
"links",
".",
"select",
"{",
"|",
"ll",
"|",
"[",
"'self'",
",",
"'last'",
"]",
".",
"include?",
"(",
"ll",
".",
"rel",
")",
"}",
"break",
"if",
"links",
"[",
"0",
"]",
".",
"href",
"==",
"links",
"[",
"1",
"]",
".",
"href",
"end",
"end",
"ajax_data",
".",
"compact!",
"ajax_data",
".",
"flatten!",
"ajax_data",
".",
"each",
"do",
"|",
"vuln_excep",
"|",
"ve",
"=",
"VulnException",
".",
"new",
"(",
"vuln_excep",
".",
"scope",
".",
"vulnerabilityID",
",",
"vuln_excep",
".",
"scope",
".",
"type",
",",
"vuln_excep",
".",
"submit",
".",
"reason",
",",
"vuln_excep",
".",
"state",
")",
"ve",
".",
"id",
"=",
"vuln_excep",
".",
"id",
"ve",
".",
"submitter",
"=",
"vuln_excep",
".",
"submit",
".",
"name",
"ve",
".",
"submitter_comment",
"=",
"vuln_excep",
".",
"submit",
".",
"comment",
"ve",
".",
"submit_date",
"=",
"Time",
".",
"parse",
"(",
"vuln_excep",
".",
"submit",
".",
"date",
")",
"unless",
"vuln_excep",
".",
"submit",
".",
"date",
".",
"nil?",
"ve",
".",
"asset_id",
"=",
"vuln_excep",
".",
"scope",
".",
"assetID",
"ve",
".",
"site_id",
"=",
"vuln_excep",
".",
"scope",
".",
"siteID",
"ve",
".",
"asset_group_id",
"=",
"vuln_excep",
".",
"scope",
".",
"assetGroupID",
"ve",
".",
"port",
"=",
"vuln_excep",
".",
"scope",
".",
"port",
"ve",
".",
"vuln_key",
"=",
"vuln_excep",
".",
"scope",
".",
"key",
"ve",
".",
"expiration",
"=",
"Time",
".",
"parse",
"(",
"vuln_excep",
".",
"expires",
")",
"unless",
"vuln_excep",
".",
"expires",
".",
"nil?",
"unless",
"vuln_excep",
".",
"review",
".",
"nil?",
"ve",
".",
"reviewer",
"=",
"vuln_excep",
".",
"review",
".",
"name",
"ve",
".",
"reviewer_comment",
"=",
"vuln_excep",
".",
"review",
".",
"comment",
"ve",
".",
"review_date",
"=",
"Time",
".",
"parse",
"(",
"vuln_excep",
".",
"review",
".",
"date",
")",
"unless",
"vuln_excep",
".",
"review",
".",
"date",
".",
"nil?",
"end",
"results",
"<<",
"ve",
"end",
"results",
".",
"keep_if",
"{",
"|",
"v",
"|",
"v",
".",
"status",
"==",
"status",
"}",
"unless",
"status",
".",
"nil?",
"results",
"end"
] |
Retrieve all active vulnerability exceptions.
@param [String] status Filter exceptions by the current status.
@see Nexpose::VulnException::Status
@return [Array[VulnException]] List of matching vulnerability exceptions.
|
[
"Retrieve",
"all",
"active",
"vulnerability",
"exceptions",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L12-L64
|
18,924
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.Connection.resubmit_vuln_exception
|
def resubmit_vuln_exception(id, comment, reason = nil)
options = { 'exception-id' => id }
options['reason'] = reason if reason
xml = make_xml('VulnerabilityExceptionResubmitRequest', options)
comment_xml = make_xml('comment', {}, comment, false)
xml.add_element(comment_xml)
r = execute(xml, '1.2')
r.success
end
|
ruby
|
def resubmit_vuln_exception(id, comment, reason = nil)
options = { 'exception-id' => id }
options['reason'] = reason if reason
xml = make_xml('VulnerabilityExceptionResubmitRequest', options)
comment_xml = make_xml('comment', {}, comment, false)
xml.add_element(comment_xml)
r = execute(xml, '1.2')
r.success
end
|
[
"def",
"resubmit_vuln_exception",
"(",
"id",
",",
"comment",
",",
"reason",
"=",
"nil",
")",
"options",
"=",
"{",
"'exception-id'",
"=>",
"id",
"}",
"options",
"[",
"'reason'",
"]",
"=",
"reason",
"if",
"reason",
"xml",
"=",
"make_xml",
"(",
"'VulnerabilityExceptionResubmitRequest'",
",",
"options",
")",
"comment_xml",
"=",
"make_xml",
"(",
"'comment'",
",",
"{",
"}",
",",
"comment",
",",
"false",
")",
"xml",
".",
"add_element",
"(",
"comment_xml",
")",
"r",
"=",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"r",
".",
"success",
"end"
] |
Resubmit a vulnerability exception request with a new comment and reason
after an exception has been rejected.
You can only resubmit a request that has a "Rejected" status; if an
exception is "Approved" or "Under Review" you will receive an error
message stating that the exception request cannot be resubmitted.
@param [Fixnum] id Unique identifier of the exception to resubmit.
@param [String] comment Comment to justify the exception resubmission.
@param [String] reason The reason for the exception status, if changing.
@see Nexpose::VulnException::Reason
@return [Boolean] Whether or not the resubmission was valid.
|
[
"Resubmit",
"a",
"vulnerability",
"exception",
"request",
"with",
"a",
"new",
"comment",
"and",
"reason",
"after",
"an",
"exception",
"has",
"been",
"rejected",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L80-L88
|
18,925
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.VulnException.save
|
def save(connection, comment = nil)
validate
xml = connection.make_xml('VulnerabilityExceptionCreateRequest')
xml.add_attributes({ 'vuln-id' => @vuln_id,
'scope' => @scope,
'reason' => @reason })
case @scope
when Scope::ALL_INSTANCES_ON_A_SPECIFIC_ASSET
xml.add_attributes({ 'device-id' => @asset_id })
when Scope::SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET
xml.add_attributes({ 'device-id' => @asset_id,
'port-no' => @port,
'vuln-key' => @vuln_key })
when Scope::ALL_INSTANCES_IN_A_SPECIFIC_SITE
xml.add_attributes({ 'site-id ' => @site_id })
end
@submitter_comment = comment if comment
if @submitter_comment
comment_elem = REXML::Element.new('comment')
comment_elem.add_text(@submitter_comment)
xml.add_element(comment_elem)
end
response = connection.execute(xml, '1.2')
@id = response.attributes['exception-id'].to_i if response.success
end
|
ruby
|
def save(connection, comment = nil)
validate
xml = connection.make_xml('VulnerabilityExceptionCreateRequest')
xml.add_attributes({ 'vuln-id' => @vuln_id,
'scope' => @scope,
'reason' => @reason })
case @scope
when Scope::ALL_INSTANCES_ON_A_SPECIFIC_ASSET
xml.add_attributes({ 'device-id' => @asset_id })
when Scope::SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET
xml.add_attributes({ 'device-id' => @asset_id,
'port-no' => @port,
'vuln-key' => @vuln_key })
when Scope::ALL_INSTANCES_IN_A_SPECIFIC_SITE
xml.add_attributes({ 'site-id ' => @site_id })
end
@submitter_comment = comment if comment
if @submitter_comment
comment_elem = REXML::Element.new('comment')
comment_elem.add_text(@submitter_comment)
xml.add_element(comment_elem)
end
response = connection.execute(xml, '1.2')
@id = response.attributes['exception-id'].to_i if response.success
end
|
[
"def",
"save",
"(",
"connection",
",",
"comment",
"=",
"nil",
")",
"validate",
"xml",
"=",
"connection",
".",
"make_xml",
"(",
"'VulnerabilityExceptionCreateRequest'",
")",
"xml",
".",
"add_attributes",
"(",
"{",
"'vuln-id'",
"=>",
"@vuln_id",
",",
"'scope'",
"=>",
"@scope",
",",
"'reason'",
"=>",
"@reason",
"}",
")",
"case",
"@scope",
"when",
"Scope",
"::",
"ALL_INSTANCES_ON_A_SPECIFIC_ASSET",
"xml",
".",
"add_attributes",
"(",
"{",
"'device-id'",
"=>",
"@asset_id",
"}",
")",
"when",
"Scope",
"::",
"SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET",
"xml",
".",
"add_attributes",
"(",
"{",
"'device-id'",
"=>",
"@asset_id",
",",
"'port-no'",
"=>",
"@port",
",",
"'vuln-key'",
"=>",
"@vuln_key",
"}",
")",
"when",
"Scope",
"::",
"ALL_INSTANCES_IN_A_SPECIFIC_SITE",
"xml",
".",
"add_attributes",
"(",
"{",
"'site-id '",
"=>",
"@site_id",
"}",
")",
"end",
"@submitter_comment",
"=",
"comment",
"if",
"comment",
"if",
"@submitter_comment",
"comment_elem",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'comment'",
")",
"comment_elem",
".",
"add_text",
"(",
"@submitter_comment",
")",
"xml",
".",
"add_element",
"(",
"comment_elem",
")",
"end",
"response",
"=",
"connection",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"@id",
"=",
"response",
".",
"attributes",
"[",
"'exception-id'",
"]",
".",
"to_i",
"if",
"response",
".",
"success",
"end"
] |
Submit this exception on the security console.
@param [Connection] connection Connection to security console.
@return [Fixnum] Newly assigned exception ID.
|
[
"Submit",
"this",
"exception",
"on",
"the",
"security",
"console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L205-L232
|
18,926
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.VulnException.approve
|
def approve(connection, comment = nil)
xml = connection.make_xml('VulnerabilityExceptionApproveRequest',
{ 'exception-id' => @id })
if comment
cxml = REXML::Element.new('comment')
cxml.add_text(comment)
xml.add_element(cxml)
@reviewer_comment = comment
end
connection.execute(xml, '1.2').success
end
|
ruby
|
def approve(connection, comment = nil)
xml = connection.make_xml('VulnerabilityExceptionApproveRequest',
{ 'exception-id' => @id })
if comment
cxml = REXML::Element.new('comment')
cxml.add_text(comment)
xml.add_element(cxml)
@reviewer_comment = comment
end
connection.execute(xml, '1.2').success
end
|
[
"def",
"approve",
"(",
"connection",
",",
"comment",
"=",
"nil",
")",
"xml",
"=",
"connection",
".",
"make_xml",
"(",
"'VulnerabilityExceptionApproveRequest'",
",",
"{",
"'exception-id'",
"=>",
"@id",
"}",
")",
"if",
"comment",
"cxml",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'comment'",
")",
"cxml",
".",
"add_text",
"(",
"comment",
")",
"xml",
".",
"add_element",
"(",
"cxml",
")",
"@reviewer_comment",
"=",
"comment",
"end",
"connection",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
".",
"success",
"end"
] |
Approve a vulnerability exception request, update comments and expiration
dates on vulnerability exceptions that are "Under Review".
@param [Connection] connection Connection to security console.
@param [String] comment Comment to accompany the approval.
@return [Boolean] Whether or not the approval was accepted by the console.
|
[
"Approve",
"a",
"vulnerability",
"exception",
"request",
"update",
"comments",
"and",
"expiration",
"dates",
"on",
"vulnerability",
"exceptions",
"that",
"are",
"Under",
"Review",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L271-L282
|
18,927
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.VulnException.update_expiration_date
|
def update_expiration_date(connection, new_date)
xml = connection.make_xml('VulnerabilityExceptionUpdateExpirationDateRequest',
{ 'exception-id' => @id,
'expiration-date' => new_date })
connection.execute(xml, '1.2').success
end
|
ruby
|
def update_expiration_date(connection, new_date)
xml = connection.make_xml('VulnerabilityExceptionUpdateExpirationDateRequest',
{ 'exception-id' => @id,
'expiration-date' => new_date })
connection.execute(xml, '1.2').success
end
|
[
"def",
"update_expiration_date",
"(",
"connection",
",",
"new_date",
")",
"xml",
"=",
"connection",
".",
"make_xml",
"(",
"'VulnerabilityExceptionUpdateExpirationDateRequest'",
",",
"{",
"'exception-id'",
"=>",
"@id",
",",
"'expiration-date'",
"=>",
"new_date",
"}",
")",
"connection",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
".",
"success",
"end"
] |
Update the expiration date for this exception.
The expiration time cannot be in the past.
@param [Connection] connection Connection to security console.
@param [String] new_date Date in the format "YYYY-MM-DD".
@return [Boolean] Whether the update was successfully submitted.
|
[
"Update",
"the",
"expiration",
"date",
"for",
"this",
"exception",
".",
"The",
"expiration",
"time",
"cannot",
"be",
"in",
"the",
"past",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L358-L363
|
18,928
|
rapid7/nexpose-client
|
lib/nexpose/vuln_exception.rb
|
Nexpose.VulnException.validate
|
def validate
raise ArgumentError.new('No vuln_id.') unless @vuln_id
raise ArgumentError.new('No scope.') unless @scope
raise ArgumentError.new('No reason.') unless @reason
case @scope
when Scope::ALL_INSTANCES
@asset_id = @port = @vuln_key = nil
when Scope::ALL_INSTANCES_ON_A_SPECIFIC_ASSET
raise ArgumentError.new('No asset_id.') unless @asset_id
@port = @vuln_key = nil
when Scope::SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET
raise ArgumentError.new('No asset_id.') unless @asset_id
raise ArgumentError.new('Port or vuln_key is required.') unless @port || @vuln_key
when Scope::ALL_INSTANCES_IN_A_SPECIFIC_SITE
raise ArgumentError.new('No site_id.') unless @site_id
else
raise ArgumentError.new("Invalid scope: #{@scope}")
end
end
|
ruby
|
def validate
raise ArgumentError.new('No vuln_id.') unless @vuln_id
raise ArgumentError.new('No scope.') unless @scope
raise ArgumentError.new('No reason.') unless @reason
case @scope
when Scope::ALL_INSTANCES
@asset_id = @port = @vuln_key = nil
when Scope::ALL_INSTANCES_ON_A_SPECIFIC_ASSET
raise ArgumentError.new('No asset_id.') unless @asset_id
@port = @vuln_key = nil
when Scope::SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET
raise ArgumentError.new('No asset_id.') unless @asset_id
raise ArgumentError.new('Port or vuln_key is required.') unless @port || @vuln_key
when Scope::ALL_INSTANCES_IN_A_SPECIFIC_SITE
raise ArgumentError.new('No site_id.') unless @site_id
else
raise ArgumentError.new("Invalid scope: #{@scope}")
end
end
|
[
"def",
"validate",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No vuln_id.'",
")",
"unless",
"@vuln_id",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No scope.'",
")",
"unless",
"@scope",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No reason.'",
")",
"unless",
"@reason",
"case",
"@scope",
"when",
"Scope",
"::",
"ALL_INSTANCES",
"@asset_id",
"=",
"@port",
"=",
"@vuln_key",
"=",
"nil",
"when",
"Scope",
"::",
"ALL_INSTANCES_ON_A_SPECIFIC_ASSET",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No asset_id.'",
")",
"unless",
"@asset_id",
"@port",
"=",
"@vuln_key",
"=",
"nil",
"when",
"Scope",
"::",
"SPECIFIC_INSTANCE_OF_SPECIFIC_ASSET",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No asset_id.'",
")",
"unless",
"@asset_id",
"raise",
"ArgumentError",
".",
"new",
"(",
"'Port or vuln_key is required.'",
")",
"unless",
"@port",
"||",
"@vuln_key",
"when",
"Scope",
"::",
"ALL_INSTANCES_IN_A_SPECIFIC_SITE",
"raise",
"ArgumentError",
".",
"new",
"(",
"'No site_id.'",
")",
"unless",
"@site_id",
"else",
"raise",
"ArgumentError",
".",
"new",
"(",
"\"Invalid scope: #{@scope}\"",
")",
"end",
"end"
] |
Validate that this exception meets to requires for the assigned scope.
|
[
"Validate",
"that",
"this",
"exception",
"meets",
"to",
"requires",
"for",
"the",
"assigned",
"scope",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/vuln_exception.rb#L367-L386
|
18,929
|
rapid7/nexpose-client
|
lib/nexpose/maint.rb
|
Nexpose.Connection.list_backups
|
def list_backups
data = DataTable._get_dyn_table(self, '/data/admin/backups?tableID=BackupSynopsis')
data.map { |b| Backup.parse(b) }
end
|
ruby
|
def list_backups
data = DataTable._get_dyn_table(self, '/data/admin/backups?tableID=BackupSynopsis')
data.map { |b| Backup.parse(b) }
end
|
[
"def",
"list_backups",
"data",
"=",
"DataTable",
".",
"_get_dyn_table",
"(",
"self",
",",
"'/data/admin/backups?tableID=BackupSynopsis'",
")",
"data",
".",
"map",
"{",
"|",
"b",
"|",
"Backup",
".",
"parse",
"(",
"b",
")",
"}",
"end"
] |
Retrieve a list of all backups currently stored on the Console.
@return [Array[Backup]] List of backups.
|
[
"Retrieve",
"a",
"list",
"of",
"all",
"backups",
"currently",
"stored",
"on",
"the",
"Console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/maint.rb#L9-L12
|
18,930
|
rapid7/nexpose-client
|
lib/nexpose/maint.rb
|
Nexpose.Connection.backup
|
def backup(platform_independent = false, description = nil)
parameters = { 'backup_desc' => description,
'cmd' => 'backup',
'platform_independent' => platform_independent,
'targetTask' => 'backupRestore' }
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
_maintenance_restart
end
end
|
ruby
|
def backup(platform_independent = false, description = nil)
parameters = { 'backup_desc' => description,
'cmd' => 'backup',
'platform_independent' => platform_independent,
'targetTask' => 'backupRestore' }
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
_maintenance_restart
end
end
|
[
"def",
"backup",
"(",
"platform_independent",
"=",
"false",
",",
"description",
"=",
"nil",
")",
"parameters",
"=",
"{",
"'backup_desc'",
"=>",
"description",
",",
"'cmd'",
"=>",
"'backup'",
",",
"'platform_independent'",
"=>",
"platform_independent",
",",
"'targetTask'",
"=>",
"'backupRestore'",
"}",
"xml",
"=",
"AJAX",
".",
"form_post",
"(",
"self",
",",
"'/admin/global/maintenance/maintCmd.txml'",
",",
"parameters",
")",
"if",
"!",
"!",
"(",
"xml",
"=~",
"/",
"/",
")",
"_maintenance_restart",
"end",
"end"
] |
Create a backup of this security console's data.
A restart will be initiated in order to put the product into maintenance
mode while the backup is made. It will then restart automatically.
@param [Boolean] platform_independent Whether to make a platform
independent backup.
@param [String] description A note about this backup which will be
visible through the web interface.
@return [Boolean] Whether a backup is successfully initiated.
|
[
"Create",
"a",
"backup",
"of",
"this",
"security",
"console",
"s",
"data",
".",
"A",
"restart",
"will",
"be",
"initiated",
"in",
"order",
"to",
"put",
"the",
"product",
"into",
"maintenance",
"mode",
"while",
"the",
"backup",
"is",
"made",
".",
"It",
"will",
"then",
"restart",
"automatically",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/maint.rb#L24-L33
|
18,931
|
rapid7/nexpose-client
|
lib/nexpose/maint.rb
|
Nexpose.Connection.db_maintenance
|
def db_maintenance(clean_up = false, compress = false, reindex = false)
return unless compress || clean_up || reindex
parameters = { 'cmd' => 'startMaintenance', 'targetTask' => 'dbMaintenance' }
parameters['cleanup'] = 1 if clean_up
parameters['compress'] = 1 if compress
parameters['reindex'] = 1 if reindex
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
_maintenance_restart
end
end
|
ruby
|
def db_maintenance(clean_up = false, compress = false, reindex = false)
return unless compress || clean_up || reindex
parameters = { 'cmd' => 'startMaintenance', 'targetTask' => 'dbMaintenance' }
parameters['cleanup'] = 1 if clean_up
parameters['compress'] = 1 if compress
parameters['reindex'] = 1 if reindex
xml = AJAX.form_post(self, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
_maintenance_restart
end
end
|
[
"def",
"db_maintenance",
"(",
"clean_up",
"=",
"false",
",",
"compress",
"=",
"false",
",",
"reindex",
"=",
"false",
")",
"return",
"unless",
"compress",
"||",
"clean_up",
"||",
"reindex",
"parameters",
"=",
"{",
"'cmd'",
"=>",
"'startMaintenance'",
",",
"'targetTask'",
"=>",
"'dbMaintenance'",
"}",
"parameters",
"[",
"'cleanup'",
"]",
"=",
"1",
"if",
"clean_up",
"parameters",
"[",
"'compress'",
"]",
"=",
"1",
"if",
"compress",
"parameters",
"[",
"'reindex'",
"]",
"=",
"1",
"if",
"reindex",
"xml",
"=",
"AJAX",
".",
"form_post",
"(",
"self",
",",
"'/admin/global/maintenance/maintCmd.txml'",
",",
"parameters",
")",
"if",
"!",
"!",
"(",
"xml",
"=~",
"/",
"/",
")",
"_maintenance_restart",
"end",
"end"
] |
Initiate database maintenance tasks to improve database performance and
consistency.
A restart will be initiated in order to put the product into maintenance
mode while the tasks are run. It will then restart automatically.
@param [Boolean] clean_up Removes any unnecessary data from the database.
@param [Boolean] compress Compresses the database tables and reclaims
unused, allocated space.
@param [Boolean] reindex Drops and recreates the database indexes for
improved performance.
@return [Boolean] Whether a maintenance tasks are successfully initiated.
|
[
"Initiate",
"database",
"maintenance",
"tasks",
"to",
"improve",
"database",
"performance",
"and",
"consistency",
".",
"A",
"restart",
"will",
"be",
"initiated",
"in",
"order",
"to",
"put",
"the",
"product",
"into",
"maintenance",
"mode",
"while",
"the",
"tasks",
"are",
"run",
".",
"It",
"will",
"then",
"restart",
"automatically",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/maint.rb#L47-L57
|
18,932
|
rapid7/nexpose-client
|
lib/nexpose/maint.rb
|
Nexpose.Backup.restore
|
def restore(nsc, password = nil)
raise 'Supplied Password is incorrect for restoring this Backup.' if invalid_backup_password?(nsc, password)
parameters = { 'backupid' => @name,
'cmd' => 'restore',
'targetTask' => 'backupRestore',
'password' => password }
xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
nsc._maintenance_restart
end
end
|
ruby
|
def restore(nsc, password = nil)
raise 'Supplied Password is incorrect for restoring this Backup.' if invalid_backup_password?(nsc, password)
parameters = { 'backupid' => @name,
'cmd' => 'restore',
'targetTask' => 'backupRestore',
'password' => password }
xml = AJAX.form_post(nsc, '/admin/global/maintenance/maintCmd.txml', parameters)
if !!(xml =~ /succeded="true"/)
nsc._maintenance_restart
end
end
|
[
"def",
"restore",
"(",
"nsc",
",",
"password",
"=",
"nil",
")",
"raise",
"'Supplied Password is incorrect for restoring this Backup.'",
"if",
"invalid_backup_password?",
"(",
"nsc",
",",
"password",
")",
"parameters",
"=",
"{",
"'backupid'",
"=>",
"@name",
",",
"'cmd'",
"=>",
"'restore'",
",",
"'targetTask'",
"=>",
"'backupRestore'",
",",
"'password'",
"=>",
"password",
"}",
"xml",
"=",
"AJAX",
".",
"form_post",
"(",
"nsc",
",",
"'/admin/global/maintenance/maintCmd.txml'",
",",
"parameters",
")",
"if",
"!",
"!",
"(",
"xml",
"=~",
"/",
"/",
")",
"nsc",
".",
"_maintenance_restart",
"end",
"end"
] |
Restore this backup to the Nexpose console.
It will restart the console after acknowledging receiving the request.
@param [Connection] nsc An active connection to a Nexpose console.
@param [String] (Optional) The password to use when restoring the backup.
@return [Boolean] Whether the request was received.
|
[
"Restore",
"this",
"backup",
"to",
"the",
"Nexpose",
"console",
".",
"It",
"will",
"restart",
"the",
"console",
"after",
"acknowledging",
"receiving",
"the",
"request",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/maint.rb#L102-L112
|
18,933
|
rapid7/nexpose-client
|
lib/nexpose/util.rb
|
Nexpose.HostOrIP.convert
|
def convert(asset)
ips = asset.split('-').map(&:strip)
IPAddr.new(ips[0])
IPAddr.new(ips[1]) if ips[1]
IPRange.new(ips[0], ips[1])
rescue ArgumentError => e
if e.message == 'invalid address'
HostName.new(asset)
else
raise "Unable to parse asset: '#{asset}'. #{e.message}"
end
end
|
ruby
|
def convert(asset)
ips = asset.split('-').map(&:strip)
IPAddr.new(ips[0])
IPAddr.new(ips[1]) if ips[1]
IPRange.new(ips[0], ips[1])
rescue ArgumentError => e
if e.message == 'invalid address'
HostName.new(asset)
else
raise "Unable to parse asset: '#{asset}'. #{e.message}"
end
end
|
[
"def",
"convert",
"(",
"asset",
")",
"ips",
"=",
"asset",
".",
"split",
"(",
"'-'",
")",
".",
"map",
"(",
":strip",
")",
"IPAddr",
".",
"new",
"(",
"ips",
"[",
"0",
"]",
")",
"IPAddr",
".",
"new",
"(",
"ips",
"[",
"1",
"]",
")",
"if",
"ips",
"[",
"1",
"]",
"IPRange",
".",
"new",
"(",
"ips",
"[",
"0",
"]",
",",
"ips",
"[",
"1",
"]",
")",
"rescue",
"ArgumentError",
"=>",
"e",
"if",
"e",
".",
"message",
"==",
"'invalid address'",
"HostName",
".",
"new",
"(",
"asset",
")",
"else",
"raise",
"\"Unable to parse asset: '#{asset}'. #{e.message}\"",
"end",
"end"
] |
Convert a host or IP address to the corresponding HostName or IPRange
class.
If the String cannot be converted, it will raise an error.
@param [String] asset String representation of an IP or host name.
@return [IPRange|HostName] Valid class, if it can be converted.
|
[
"Convert",
"a",
"host",
"or",
"IP",
"address",
"to",
"the",
"corresponding",
"HostName",
"or",
"IPRange",
"class",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/util.rb#L52-L63
|
18,934
|
rapid7/nexpose-client
|
lib/nexpose/util.rb
|
Nexpose.Attributes.to_hash
|
def to_hash(arr)
arr.map(&:flatten).map { |p| { 'key' => p.first.to_s, 'value' => p.last.to_s } }
end
|
ruby
|
def to_hash(arr)
arr.map(&:flatten).map { |p| { 'key' => p.first.to_s, 'value' => p.last.to_s } }
end
|
[
"def",
"to_hash",
"(",
"arr",
")",
"arr",
".",
"map",
"(",
":flatten",
")",
".",
"map",
"{",
"|",
"p",
"|",
"{",
"'key'",
"=>",
"p",
".",
"first",
".",
"to_s",
",",
"'value'",
"=>",
"p",
".",
"last",
".",
"to_s",
"}",
"}",
"end"
] |
Convert an array of attributes into a hash consumable by the API.
@param [Array[Hash]] arr Array of attributes to convert.
@return [Array[Hash]] Array formatted as expected by the API.
|
[
"Convert",
"an",
"array",
"of",
"attributes",
"into",
"a",
"hash",
"consumable",
"by",
"the",
"API",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/util.rb#L122-L124
|
18,935
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.save
|
def save(nsc)
# load method can return XML missing this required attribute.
unless REXML::XPath.first(xml, '//*[@recalculation_duration]')
risk_model = REXML::XPath.first(xml, '//riskModel')
risk_model.add_attribute('recalculation_duration', 'do_not_recalculate')
end
replace_exclusions(xml, asset_exclusions)
add_control_scanning_to_xml(xml, control_scanning)
add_asset_linking_to_xml(xml, asset_linking)
response = AJAX.post(nsc, '/data/admin/global-settings', xml)
XMLUtils.success? response
end
|
ruby
|
def save(nsc)
# load method can return XML missing this required attribute.
unless REXML::XPath.first(xml, '//*[@recalculation_duration]')
risk_model = REXML::XPath.first(xml, '//riskModel')
risk_model.add_attribute('recalculation_duration', 'do_not_recalculate')
end
replace_exclusions(xml, asset_exclusions)
add_control_scanning_to_xml(xml, control_scanning)
add_asset_linking_to_xml(xml, asset_linking)
response = AJAX.post(nsc, '/data/admin/global-settings', xml)
XMLUtils.success? response
end
|
[
"def",
"save",
"(",
"nsc",
")",
"# load method can return XML missing this required attribute.",
"unless",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//*[@recalculation_duration]'",
")",
"risk_model",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//riskModel'",
")",
"risk_model",
".",
"add_attribute",
"(",
"'recalculation_duration'",
",",
"'do_not_recalculate'",
")",
"end",
"replace_exclusions",
"(",
"xml",
",",
"asset_exclusions",
")",
"add_control_scanning_to_xml",
"(",
"xml",
",",
"control_scanning",
")",
"add_asset_linking_to_xml",
"(",
"xml",
",",
"asset_linking",
")",
"response",
"=",
"AJAX",
".",
"post",
"(",
"nsc",
",",
"'/data/admin/global-settings'",
",",
"xml",
")",
"XMLUtils",
".",
"success?",
"response",
"end"
] |
Save any updates to this settings object to the Nexpose console.
@param [Connection] nsc Connection to a Nexpose console.
@return [Boolean] Whether saving was successful.
|
[
"Save",
"any",
"updates",
"to",
"this",
"settings",
"object",
"to",
"the",
"Nexpose",
"console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L38-L51
|
18,936
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.add_exclusion
|
def add_exclusion(host_or_ip)
asset = host_or_ip
unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from)
asset = HostOrIP.convert(host_or_ip)
end
@asset_exclusions << asset
end
|
ruby
|
def add_exclusion(host_or_ip)
asset = host_or_ip
unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from)
asset = HostOrIP.convert(host_or_ip)
end
@asset_exclusions << asset
end
|
[
"def",
"add_exclusion",
"(",
"host_or_ip",
")",
"asset",
"=",
"host_or_ip",
"unless",
"host_or_ip",
".",
"respond_to?",
"(",
":host",
")",
"||",
"host_or_ip",
".",
"respond_to?",
"(",
":from",
")",
"asset",
"=",
"HostOrIP",
".",
"convert",
"(",
"host_or_ip",
")",
"end",
"@asset_exclusions",
"<<",
"asset",
"end"
] |
Add an asset exclusion setting.
@param [IPRange|HostName|String] host_or_ip Host or IP (range) to exclude
from scanning by the Nexpose console.
|
[
"Add",
"an",
"asset",
"exclusion",
"setting",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L58-L64
|
18,937
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.remove_exclusion
|
def remove_exclusion(host_or_ip)
asset = host_or_ip
unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from)
# Attept to convert String to appropriate object.
asset = HostOrIP.convert(host_or_ip)
end
@asset_exclusions = asset_exclusions.reject { |a| a.eql? asset }
end
|
ruby
|
def remove_exclusion(host_or_ip)
asset = host_or_ip
unless host_or_ip.respond_to?(:host) || host_or_ip.respond_to?(:from)
# Attept to convert String to appropriate object.
asset = HostOrIP.convert(host_or_ip)
end
@asset_exclusions = asset_exclusions.reject { |a| a.eql? asset }
end
|
[
"def",
"remove_exclusion",
"(",
"host_or_ip",
")",
"asset",
"=",
"host_or_ip",
"unless",
"host_or_ip",
".",
"respond_to?",
"(",
":host",
")",
"||",
"host_or_ip",
".",
"respond_to?",
"(",
":from",
")",
"# Attept to convert String to appropriate object.",
"asset",
"=",
"HostOrIP",
".",
"convert",
"(",
"host_or_ip",
")",
"end",
"@asset_exclusions",
"=",
"asset_exclusions",
".",
"reject",
"{",
"|",
"a",
"|",
"a",
".",
"eql?",
"asset",
"}",
"end"
] |
Remove an asset exclusion setting.
If you need to remove a range of IPs, be sure to explicitly supply an
IPRange object to the method.
@param [IPRange|HostName|String] host_or_ip Host or IP (range) to remove
from the exclusion list.
|
[
"Remove",
"an",
"asset",
"exclusion",
"setting",
".",
"If",
"you",
"need",
"to",
"remove",
"a",
"range",
"of",
"IPs",
"be",
"sure",
"to",
"explicitly",
"supply",
"an",
"IPRange",
"object",
"to",
"the",
"method",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L73-L80
|
18,938
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.replace_exclusions
|
def replace_exclusions(xml, exclusions)
xml.elements.delete('//ExcludedHosts')
elem = xml.root.add_element('ExcludedHosts')
exclusions.each do |exclusion|
elem.add_element(exclusion.as_xml)
end
end
|
ruby
|
def replace_exclusions(xml, exclusions)
xml.elements.delete('//ExcludedHosts')
elem = xml.root.add_element('ExcludedHosts')
exclusions.each do |exclusion|
elem.add_element(exclusion.as_xml)
end
end
|
[
"def",
"replace_exclusions",
"(",
"xml",
",",
"exclusions",
")",
"xml",
".",
"elements",
".",
"delete",
"(",
"'//ExcludedHosts'",
")",
"elem",
"=",
"xml",
".",
"root",
".",
"add_element",
"(",
"'ExcludedHosts'",
")",
"exclusions",
".",
"each",
"do",
"|",
"exclusion",
"|",
"elem",
".",
"add_element",
"(",
"exclusion",
".",
"as_xml",
")",
"end",
"end"
] |
Internal method for updating exclusions before saving.
|
[
"Internal",
"method",
"for",
"updating",
"exclusions",
"before",
"saving",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L95-L101
|
18,939
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.parse_control_scanning_from_xml
|
def parse_control_scanning_from_xml(xml)
enabled = false
if elem = REXML::XPath.first(xml, '//enableControlsScan[@enabled]')
enabled = elem.attribute('enabled').value.to_i == 1
end
enabled
end
|
ruby
|
def parse_control_scanning_from_xml(xml)
enabled = false
if elem = REXML::XPath.first(xml, '//enableControlsScan[@enabled]')
enabled = elem.attribute('enabled').value.to_i == 1
end
enabled
end
|
[
"def",
"parse_control_scanning_from_xml",
"(",
"xml",
")",
"enabled",
"=",
"false",
"if",
"elem",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//enableControlsScan[@enabled]'",
")",
"enabled",
"=",
"elem",
".",
"attribute",
"(",
"'enabled'",
")",
".",
"value",
".",
"to_i",
"==",
"1",
"end",
"enabled",
"end"
] |
Internal method for parsing XML for whether control scanning in enabled.
|
[
"Internal",
"method",
"for",
"parsing",
"XML",
"for",
"whether",
"control",
"scanning",
"in",
"enabled",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L104-L110
|
18,940
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.add_control_scanning_to_xml
|
def add_control_scanning_to_xml(xml, enabled)
if elem = REXML::XPath.first(xml, '//enableControlsScan')
elem.attributes['enabled'] = enabled ? '1' : '0'
else
elem = REXML::Element.new('ControlsScan', xml.root)
elem.add_element('enableControlsScan',
'enabled' => enabled ? '1' : '0')
end
end
|
ruby
|
def add_control_scanning_to_xml(xml, enabled)
if elem = REXML::XPath.first(xml, '//enableControlsScan')
elem.attributes['enabled'] = enabled ? '1' : '0'
else
elem = REXML::Element.new('ControlsScan', xml.root)
elem.add_element('enableControlsScan',
'enabled' => enabled ? '1' : '0')
end
end
|
[
"def",
"add_control_scanning_to_xml",
"(",
"xml",
",",
"enabled",
")",
"if",
"elem",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//enableControlsScan'",
")",
"elem",
".",
"attributes",
"[",
"'enabled'",
"]",
"=",
"enabled",
"?",
"'1'",
":",
"'0'",
"else",
"elem",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'ControlsScan'",
",",
"xml",
".",
"root",
")",
"elem",
".",
"add_element",
"(",
"'enableControlsScan'",
",",
"'enabled'",
"=>",
"enabled",
"?",
"'1'",
":",
"'0'",
")",
"end",
"end"
] |
Internal method for updating control scanning before saving.
|
[
"Internal",
"method",
"for",
"updating",
"control",
"scanning",
"before",
"saving",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L113-L121
|
18,941
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.parse_asset_linking_from_xml
|
def parse_asset_linking_from_xml(xml)
enabled = true
if elem = REXML::XPath.first(xml, '//AssetCorrelation[@enabled]')
enabled = elem.attribute('enabled').value.to_i == 1
end
enabled
end
|
ruby
|
def parse_asset_linking_from_xml(xml)
enabled = true
if elem = REXML::XPath.first(xml, '//AssetCorrelation[@enabled]')
enabled = elem.attribute('enabled').value.to_i == 1
end
enabled
end
|
[
"def",
"parse_asset_linking_from_xml",
"(",
"xml",
")",
"enabled",
"=",
"true",
"if",
"elem",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//AssetCorrelation[@enabled]'",
")",
"enabled",
"=",
"elem",
".",
"attribute",
"(",
"'enabled'",
")",
".",
"value",
".",
"to_i",
"==",
"1",
"end",
"enabled",
"end"
] |
Internal method for parsing XML for whether asset linking in enabled.
|
[
"Internal",
"method",
"for",
"parsing",
"XML",
"for",
"whether",
"asset",
"linking",
"in",
"enabled",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L124-L130
|
18,942
|
rapid7/nexpose-client
|
lib/nexpose/global_settings.rb
|
Nexpose.GlobalSettings.add_asset_linking_to_xml
|
def add_asset_linking_to_xml(xml, enabled)
elem = REXML::XPath.first(xml, '//AssetCorrelation')
return nil unless elem
elem.attributes['enabled'] = enabled ? '1' : '0'
end
|
ruby
|
def add_asset_linking_to_xml(xml, enabled)
elem = REXML::XPath.first(xml, '//AssetCorrelation')
return nil unless elem
elem.attributes['enabled'] = enabled ? '1' : '0'
end
|
[
"def",
"add_asset_linking_to_xml",
"(",
"xml",
",",
"enabled",
")",
"elem",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"xml",
",",
"'//AssetCorrelation'",
")",
"return",
"nil",
"unless",
"elem",
"elem",
".",
"attributes",
"[",
"'enabled'",
"]",
"=",
"enabled",
"?",
"'1'",
":",
"'0'",
"end"
] |
Internal method for updating asset linking before saving.
|
[
"Internal",
"method",
"for",
"updating",
"asset",
"linking",
"before",
"saving",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/global_settings.rb#L133-L138
|
18,943
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_db2_service
|
def set_db2_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::DB2
end
|
ruby
|
def set_db2_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::DB2
end
|
[
"def",
"set_db2_service",
"(",
"database",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"database",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"DB2",
"end"
] |
sets the DB2 service
|
[
"sets",
"the",
"DB2",
"service"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L14-L19
|
18,944
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_tds_service
|
def set_tds_service(database = nil, domain = nil, username = nil, password = nil)
self.database = database
self.domain = domain
self.use_windows_auth = domain.nil?
self.user_name = username
self.password = password
self.service = Credential::Service::TDS
end
|
ruby
|
def set_tds_service(database = nil, domain = nil, username = nil, password = nil)
self.database = database
self.domain = domain
self.use_windows_auth = domain.nil?
self.user_name = username
self.password = password
self.service = Credential::Service::TDS
end
|
[
"def",
"set_tds_service",
"(",
"database",
"=",
"nil",
",",
"domain",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"database",
"self",
".",
"domain",
"=",
"domain",
"self",
".",
"use_windows_auth",
"=",
"domain",
".",
"nil?",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"TDS",
"end"
] |
sets the Microsoft SQL Server service.
|
[
"sets",
"the",
"Microsoft",
"SQL",
"Server",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L43-L50
|
18,945
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_mysql_service
|
def set_mysql_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::MYSQL
end
|
ruby
|
def set_mysql_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::MYSQL
end
|
[
"def",
"set_mysql_service",
"(",
"database",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"database",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"MYSQL",
"end"
] |
sets the MySQL Server service.
|
[
"sets",
"the",
"MySQL",
"Server",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L69-L74
|
18,946
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_oracle_service
|
def set_oracle_service(sid = nil, username = nil, password = nil)
self.database = sid
self.user_name = username
self.password = password
self.service = Credential::Service::ORACLE
end
|
ruby
|
def set_oracle_service(sid = nil, username = nil, password = nil)
self.database = sid
self.user_name = username
self.password = password
self.service = Credential::Service::ORACLE
end
|
[
"def",
"set_oracle_service",
"(",
"sid",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"sid",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"ORACLE",
"end"
] |
sets the Oracle service.
|
[
"sets",
"the",
"Oracle",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L77-L82
|
18,947
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_postgresql_service
|
def set_postgresql_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::POSTGRESQL
end
|
ruby
|
def set_postgresql_service(database = nil, username = nil, password = nil)
self.database = database
self.user_name = username
self.password = password
self.service = Credential::Service::POSTGRESQL
end
|
[
"def",
"set_postgresql_service",
"(",
"database",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"database",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"POSTGRESQL",
"end"
] |
sets the PostgreSQL service.
|
[
"sets",
"the",
"PostgreSQL",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L92-L97
|
18,948
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_remote_execution_service
|
def set_remote_execution_service(username = nil, password = nil)
self.user_name = username
self.password = password
self.service = Credential::Service::REMOTE_EXECUTION
end
|
ruby
|
def set_remote_execution_service(username = nil, password = nil)
self.user_name = username
self.password = password
self.service = Credential::Service::REMOTE_EXECUTION
end
|
[
"def",
"set_remote_execution_service",
"(",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"REMOTE_EXECUTION",
"end"
] |
sets the Remote Execution service.
|
[
"sets",
"the",
"Remote",
"Execution",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L100-L104
|
18,949
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_snmpv3_service
|
def set_snmpv3_service(authentication_type = Credential::AuthenticationType::NOAUTH, username = nil, password = nil, privacy_type = Credential::PrivacyType::NOPRIV, privacy_password = nil)
self.authentication_type = authentication_type
self.user_name = username
self.password = password
self.privacy_type = privacy_type
self.privacy_password = privacy_password
self.service = Credential::Service::SNMPV3
end
|
ruby
|
def set_snmpv3_service(authentication_type = Credential::AuthenticationType::NOAUTH, username = nil, password = nil, privacy_type = Credential::PrivacyType::NOPRIV, privacy_password = nil)
self.authentication_type = authentication_type
self.user_name = username
self.password = password
self.privacy_type = privacy_type
self.privacy_password = privacy_password
self.service = Credential::Service::SNMPV3
end
|
[
"def",
"set_snmpv3_service",
"(",
"authentication_type",
"=",
"Credential",
"::",
"AuthenticationType",
"::",
"NOAUTH",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
",",
"privacy_type",
"=",
"Credential",
"::",
"PrivacyType",
"::",
"NOPRIV",
",",
"privacy_password",
"=",
"nil",
")",
"self",
".",
"authentication_type",
"=",
"authentication_type",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"privacy_type",
"=",
"privacy_type",
"self",
".",
"privacy_password",
"=",
"privacy_password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"SNMPV3",
"end"
] |
sets the Simple Network Management Protocol v3 service.
|
[
"sets",
"the",
"Simple",
"Network",
"Management",
"Protocol",
"v3",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L134-L141
|
18,950
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_sybase_service
|
def set_sybase_service(database = nil, domain = nil, username = nil, password = nil)
self.database = database
self.domain = domain
self.use_windows_auth = domain.nil?
self.user_name = username
self.password = password
self.service = Credential::Service::SYBASE
end
|
ruby
|
def set_sybase_service(database = nil, domain = nil, username = nil, password = nil)
self.database = database
self.domain = domain
self.use_windows_auth = domain.nil?
self.user_name = username
self.password = password
self.service = Credential::Service::SYBASE
end
|
[
"def",
"set_sybase_service",
"(",
"database",
"=",
"nil",
",",
"domain",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"database",
"=",
"database",
"self",
".",
"domain",
"=",
"domain",
"self",
".",
"use_windows_auth",
"=",
"domain",
".",
"nil?",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"SYBASE",
"end"
] |
sets the Sybase SQL Server service.
|
[
"sets",
"the",
"Sybase",
"SQL",
"Server",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L144-L151
|
18,951
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_telnet_service
|
def set_telnet_service(username = nil, password = nil)
self.user_name = username
self.password = password
self.service = Credential::Service::TELNET
end
|
ruby
|
def set_telnet_service(username = nil, password = nil)
self.user_name = username
self.password = password
self.service = Credential::Service::TELNET
end
|
[
"def",
"set_telnet_service",
"(",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"TELNET",
"end"
] |
sets the Telnet service.
|
[
"sets",
"the",
"Telnet",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L154-L158
|
18,952
|
rapid7/nexpose-client
|
lib/nexpose/credential_helper.rb
|
Nexpose.CredentialHelper.set_http_service
|
def set_http_service(domain = nil, username = nil, password = nil)
self.domain = domain
self.user_name = username
self.password = password
self.service = Credential::Service::HTTP
end
|
ruby
|
def set_http_service(domain = nil, username = nil, password = nil)
self.domain = domain
self.user_name = username
self.password = password
self.service = Credential::Service::HTTP
end
|
[
"def",
"set_http_service",
"(",
"domain",
"=",
"nil",
",",
"username",
"=",
"nil",
",",
"password",
"=",
"nil",
")",
"self",
".",
"domain",
"=",
"domain",
"self",
".",
"user_name",
"=",
"username",
"self",
".",
"password",
"=",
"password",
"self",
".",
"service",
"=",
"Credential",
"::",
"Service",
"::",
"HTTP",
"end"
] |
sets the Web Site HTTP Authentication service.
|
[
"sets",
"the",
"Web",
"Site",
"HTTP",
"Authentication",
"service",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/credential_helper.rb#L161-L166
|
18,953
|
rapid7/nexpose-client
|
lib/nexpose/user.rb
|
Nexpose.Connection.list_users
|
def list_users
r = execute(make_xml('UserListingRequest'))
arr = []
if r.success
r.res.elements.each('UserListingResponse/UserSummary') do |summary|
arr << UserSummary.parse(summary)
end
end
arr
end
|
ruby
|
def list_users
r = execute(make_xml('UserListingRequest'))
arr = []
if r.success
r.res.elements.each('UserListingResponse/UserSummary') do |summary|
arr << UserSummary.parse(summary)
end
end
arr
end
|
[
"def",
"list_users",
"r",
"=",
"execute",
"(",
"make_xml",
"(",
"'UserListingRequest'",
")",
")",
"arr",
"=",
"[",
"]",
"if",
"r",
".",
"success",
"r",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'UserListingResponse/UserSummary'",
")",
"do",
"|",
"summary",
"|",
"arr",
"<<",
"UserSummary",
".",
"parse",
"(",
"summary",
")",
"end",
"end",
"arr",
"end"
] |
Retrieve a list of all users configured on this console.
@return [Array[UserSummary]] Array of users.
|
[
"Retrieve",
"a",
"list",
"of",
"all",
"users",
"configured",
"on",
"this",
"console",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/user.rb#L10-L19
|
18,954
|
rapid7/nexpose-client
|
lib/nexpose/discovery.rb
|
Nexpose.Connection.list_discovery_connections
|
def list_discovery_connections
xml = make_xml('DiscoveryConnectionListingRequest')
response = execute(xml, '1.2')
connections = []
response.res.elements.each('DiscoveryConnectionListingResponse/DiscoveryConnectionSummary') do |conn|
connections << DiscoveryConnection.parse(conn)
end
connections
end
|
ruby
|
def list_discovery_connections
xml = make_xml('DiscoveryConnectionListingRequest')
response = execute(xml, '1.2')
connections = []
response.res.elements.each('DiscoveryConnectionListingResponse/DiscoveryConnectionSummary') do |conn|
connections << DiscoveryConnection.parse(conn)
end
connections
end
|
[
"def",
"list_discovery_connections",
"xml",
"=",
"make_xml",
"(",
"'DiscoveryConnectionListingRequest'",
")",
"response",
"=",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"connections",
"=",
"[",
"]",
"response",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'DiscoveryConnectionListingResponse/DiscoveryConnectionSummary'",
")",
"do",
"|",
"conn",
"|",
"connections",
"<<",
"DiscoveryConnection",
".",
"parse",
"(",
"conn",
")",
"end",
"connections",
"end"
] |
Retrieve information about all available connections for dynamic
discovery of assets, including whether or not connections are active.
|
[
"Retrieve",
"information",
"about",
"all",
"available",
"connections",
"for",
"dynamic",
"discovery",
"of",
"assets",
"including",
"whether",
"or",
"not",
"connections",
"are",
"active",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/discovery.rb#L8-L16
|
18,955
|
rapid7/nexpose-client
|
lib/nexpose/discovery.rb
|
Nexpose.Connection.delete_discovery_connection
|
def delete_discovery_connection(id)
xml = make_xml('DiscoveryConnectionDeleteRequest', { 'id' => id })
response = execute(xml, '1.2')
response.success
end
|
ruby
|
def delete_discovery_connection(id)
xml = make_xml('DiscoveryConnectionDeleteRequest', { 'id' => id })
response = execute(xml, '1.2')
response.success
end
|
[
"def",
"delete_discovery_connection",
"(",
"id",
")",
"xml",
"=",
"make_xml",
"(",
"'DiscoveryConnectionDeleteRequest'",
",",
"{",
"'id'",
"=>",
"id",
"}",
")",
"response",
"=",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"response",
".",
"success",
"end"
] |
Delete an existing connection to a target used for dynamic discovery of assets.
@param [Fixnum] id ID of an existing discovery connection.
|
[
"Delete",
"an",
"existing",
"connection",
"to",
"a",
"target",
"used",
"for",
"dynamic",
"discovery",
"of",
"assets",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/discovery.rb#L23-L27
|
18,956
|
rapid7/nexpose-client
|
lib/nexpose/discovery.rb
|
Nexpose.DiscoveryConnection.create
|
def create(nsc)
xml = nsc.make_xml('DiscoveryConnectionCreateRequest')
xml.add_element(as_xml)
response = nsc.execute(xml, '1.2')
if response.success
ret = REXML::XPath.first(response.res, 'DiscoveryConnectionCreateResponse')
@id = ret.attributes['id'].to_i unless ret.nil?
end
end
|
ruby
|
def create(nsc)
xml = nsc.make_xml('DiscoveryConnectionCreateRequest')
xml.add_element(as_xml)
response = nsc.execute(xml, '1.2')
if response.success
ret = REXML::XPath.first(response.res, 'DiscoveryConnectionCreateResponse')
@id = ret.attributes['id'].to_i unless ret.nil?
end
end
|
[
"def",
"create",
"(",
"nsc",
")",
"xml",
"=",
"nsc",
".",
"make_xml",
"(",
"'DiscoveryConnectionCreateRequest'",
")",
"xml",
".",
"add_element",
"(",
"as_xml",
")",
"response",
"=",
"nsc",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"if",
"response",
".",
"success",
"ret",
"=",
"REXML",
"::",
"XPath",
".",
"first",
"(",
"response",
".",
"res",
",",
"'DiscoveryConnectionCreateResponse'",
")",
"@id",
"=",
"ret",
".",
"attributes",
"[",
"'id'",
"]",
".",
"to_i",
"unless",
"ret",
".",
"nil?",
"end",
"end"
] |
Create a new discovery connection.
@param [String] name Name to assign to this connection.
@param [String] address IP or fully qualified domain name of the
connection server.
@param [String] user User name for credentials on this connection.
@param [String] password Password for credentials on this connection.
Save this discovery connection on a given Nexpose console.
@param [Connection] nsc Connection to a console.
|
[
"Create",
"a",
"new",
"discovery",
"connection",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/discovery.rb#L117-L126
|
18,957
|
rapid7/nexpose-client
|
lib/nexpose/discovery.rb
|
Nexpose.DiscoveryConnection.discover
|
def discover(nsc, criteria = nil)
parameters = { 'table-id' => 'assetdiscovery',
'sort' => 'assetDiscoveryName',
'searchCriteria' => criteria.nil? ? 'null' : criteria.to_json,
'configID' => @id }
data = DataTable._get_json_table(nsc, '/data/discoveryAsset/discoverAssets', parameters)
data.map { |a| DiscoveredAsset.parse(a) }
end
|
ruby
|
def discover(nsc, criteria = nil)
parameters = { 'table-id' => 'assetdiscovery',
'sort' => 'assetDiscoveryName',
'searchCriteria' => criteria.nil? ? 'null' : criteria.to_json,
'configID' => @id }
data = DataTable._get_json_table(nsc, '/data/discoveryAsset/discoverAssets', parameters)
data.map { |a| DiscoveredAsset.parse(a) }
end
|
[
"def",
"discover",
"(",
"nsc",
",",
"criteria",
"=",
"nil",
")",
"parameters",
"=",
"{",
"'table-id'",
"=>",
"'assetdiscovery'",
",",
"'sort'",
"=>",
"'assetDiscoveryName'",
",",
"'searchCriteria'",
"=>",
"criteria",
".",
"nil?",
"?",
"'null'",
":",
"criteria",
".",
"to_json",
",",
"'configID'",
"=>",
"@id",
"}",
"data",
"=",
"DataTable",
".",
"_get_json_table",
"(",
"nsc",
",",
"'/data/discoveryAsset/discoverAssets'",
",",
"parameters",
")",
"data",
".",
"map",
"{",
"|",
"a",
"|",
"DiscoveredAsset",
".",
"parse",
"(",
"a",
")",
"}",
"end"
] |
Perform dynamic discover of assets against this connection.
@param [Connection] nsc Connection to a console.
@param [Criteria] criteria Criteria search object narrowing which assets
to filter.
@return [Array[DiscoveredAsset]] All discovered assets matching the criteria.
|
[
"Perform",
"dynamic",
"discover",
"of",
"assets",
"against",
"this",
"connection",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/discovery.rb#L157-L164
|
18,958
|
rapid7/nexpose-client
|
lib/nexpose/discovery.rb
|
Nexpose.DiscoveryConnection.connect
|
def connect(nsc)
xml = nsc.make_xml('DiscoveryConnectionConnectRequest', { 'id' => id })
response = nsc.execute(xml, '1.2')
response.success
end
|
ruby
|
def connect(nsc)
xml = nsc.make_xml('DiscoveryConnectionConnectRequest', { 'id' => id })
response = nsc.execute(xml, '1.2')
response.success
end
|
[
"def",
"connect",
"(",
"nsc",
")",
"xml",
"=",
"nsc",
".",
"make_xml",
"(",
"'DiscoveryConnectionConnectRequest'",
",",
"{",
"'id'",
"=>",
"id",
"}",
")",
"response",
"=",
"nsc",
".",
"execute",
"(",
"xml",
",",
"'1.2'",
")",
"response",
".",
"success",
"end"
] |
Initiates a connection to a target used for dynamic discovery of assets.
As long as a connection is active, dynamic discovery is continuous.
@param [Connection] nsc Connection to a console.
|
[
"Initiates",
"a",
"connection",
"to",
"a",
"target",
"used",
"for",
"dynamic",
"discovery",
"of",
"assets",
".",
"As",
"long",
"as",
"a",
"connection",
"is",
"active",
"dynamic",
"discovery",
"is",
"continuous",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/discovery.rb#L171-L175
|
18,959
|
rapid7/nexpose-client
|
lib/nexpose/group.rb
|
Nexpose.Connection.list_asset_groups
|
def list_asset_groups
r = execute(make_xml('AssetGroupListingRequest'))
groups = []
if r.success
r.res.elements.each('AssetGroupListingResponse/AssetGroupSummary') do |group|
groups << AssetGroupSummary.new(group.attributes['id'].to_i,
group.attributes['name'],
group.attributes['description'],
group.attributes['riskscore'].to_f,
group.attributes['dynamic'].to_i == 1)
end
end
groups
end
|
ruby
|
def list_asset_groups
r = execute(make_xml('AssetGroupListingRequest'))
groups = []
if r.success
r.res.elements.each('AssetGroupListingResponse/AssetGroupSummary') do |group|
groups << AssetGroupSummary.new(group.attributes['id'].to_i,
group.attributes['name'],
group.attributes['description'],
group.attributes['riskscore'].to_f,
group.attributes['dynamic'].to_i == 1)
end
end
groups
end
|
[
"def",
"list_asset_groups",
"r",
"=",
"execute",
"(",
"make_xml",
"(",
"'AssetGroupListingRequest'",
")",
")",
"groups",
"=",
"[",
"]",
"if",
"r",
".",
"success",
"r",
".",
"res",
".",
"elements",
".",
"each",
"(",
"'AssetGroupListingResponse/AssetGroupSummary'",
")",
"do",
"|",
"group",
"|",
"groups",
"<<",
"AssetGroupSummary",
".",
"new",
"(",
"group",
".",
"attributes",
"[",
"'id'",
"]",
".",
"to_i",
",",
"group",
".",
"attributes",
"[",
"'name'",
"]",
",",
"group",
".",
"attributes",
"[",
"'description'",
"]",
",",
"group",
".",
"attributes",
"[",
"'riskscore'",
"]",
".",
"to_f",
",",
"group",
".",
"attributes",
"[",
"'dynamic'",
"]",
".",
"to_i",
"==",
"1",
")",
"end",
"end",
"groups",
"end"
] |
Retrieve an array of all asset groups the user is authorized to view or
manage.
@return [Array[AssetGroupSummary]] Array of AssetGroupSummary objects.
|
[
"Retrieve",
"an",
"array",
"of",
"all",
"asset",
"groups",
"the",
"user",
"is",
"authorized",
"to",
"view",
"or",
"manage",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/group.rb#L24-L37
|
18,960
|
rapid7/nexpose-client
|
lib/nexpose/group.rb
|
Nexpose.AssetGroup.as_xml
|
def as_xml
xml = REXML::Element.new('AssetGroup')
xml.attributes['id'] = @id
xml.attributes['name'] = @name
xml.attributes['description'] = @description
if @description && !@description.empty?
elem = REXML::Element.new('Description')
elem.add_text(@description)
xml.add_element(elem)
end
elem = REXML::Element.new('Devices')
@assets.each { |a| elem.add_element('device', { 'id' => a.id }) }
xml.add_element(elem)
unless tags.empty?
tag_xml = xml.add_element(REXML::Element.new('Tags'))
@tags.each { |tag| tag_xml.add_element(tag.as_xml) }
end
xml
end
|
ruby
|
def as_xml
xml = REXML::Element.new('AssetGroup')
xml.attributes['id'] = @id
xml.attributes['name'] = @name
xml.attributes['description'] = @description
if @description && !@description.empty?
elem = REXML::Element.new('Description')
elem.add_text(@description)
xml.add_element(elem)
end
elem = REXML::Element.new('Devices')
@assets.each { |a| elem.add_element('device', { 'id' => a.id }) }
xml.add_element(elem)
unless tags.empty?
tag_xml = xml.add_element(REXML::Element.new('Tags'))
@tags.each { |tag| tag_xml.add_element(tag.as_xml) }
end
xml
end
|
[
"def",
"as_xml",
"xml",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'AssetGroup'",
")",
"xml",
".",
"attributes",
"[",
"'id'",
"]",
"=",
"@id",
"xml",
".",
"attributes",
"[",
"'name'",
"]",
"=",
"@name",
"xml",
".",
"attributes",
"[",
"'description'",
"]",
"=",
"@description",
"if",
"@description",
"&&",
"!",
"@description",
".",
"empty?",
"elem",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'Description'",
")",
"elem",
".",
"add_text",
"(",
"@description",
")",
"xml",
".",
"add_element",
"(",
"elem",
")",
"end",
"elem",
"=",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'Devices'",
")",
"@assets",
".",
"each",
"{",
"|",
"a",
"|",
"elem",
".",
"add_element",
"(",
"'device'",
",",
"{",
"'id'",
"=>",
"a",
".",
"id",
"}",
")",
"}",
"xml",
".",
"add_element",
"(",
"elem",
")",
"unless",
"tags",
".",
"empty?",
"tag_xml",
"=",
"xml",
".",
"add_element",
"(",
"REXML",
"::",
"Element",
".",
"new",
"(",
"'Tags'",
")",
")",
"@tags",
".",
"each",
"{",
"|",
"tag",
"|",
"tag_xml",
".",
"add_element",
"(",
"tag",
".",
"as_xml",
")",
"}",
"end",
"xml",
"end"
] |
Generate an XML representation of this group configuration
@return [String] XML valid for submission as part of other requests.
|
[
"Generate",
"an",
"XML",
"representation",
"of",
"this",
"group",
"configuration"
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/group.rb#L102-L124
|
18,961
|
rapid7/nexpose-client
|
lib/nexpose/group.rb
|
Nexpose.AssetGroup.rescan_assets
|
def rescan_assets(connection)
scans = {}
sites_ids = @assets.map(&:site_id).uniq
sites_ids.each do |site_id|
to_scan = @assets.select { |d| d.site_id == site_id }
scans[site_id] = connection.scan_devices(to_scan)
end
scans
end
|
ruby
|
def rescan_assets(connection)
scans = {}
sites_ids = @assets.map(&:site_id).uniq
sites_ids.each do |site_id|
to_scan = @assets.select { |d| d.site_id == site_id }
scans[site_id] = connection.scan_devices(to_scan)
end
scans
end
|
[
"def",
"rescan_assets",
"(",
"connection",
")",
"scans",
"=",
"{",
"}",
"sites_ids",
"=",
"@assets",
".",
"map",
"(",
":site_id",
")",
".",
"uniq",
"sites_ids",
".",
"each",
"do",
"|",
"site_id",
"|",
"to_scan",
"=",
"@assets",
".",
"select",
"{",
"|",
"d",
"|",
"d",
".",
"site_id",
"==",
"site_id",
"}",
"scans",
"[",
"site_id",
"]",
"=",
"connection",
".",
"scan_devices",
"(",
"to_scan",
")",
"end",
"scans",
"end"
] |
Launch ad hoc scans against each group of assets per site.
@param [Connection] connection Connection to console where asset group
is configured.
@return [Hash] Hash of site ID to Scan launch information for each scan.
|
[
"Launch",
"ad",
"hoc",
"scans",
"against",
"each",
"group",
"of",
"assets",
"per",
"site",
"."
] |
933fc8c0c85ba11d3e17db1d7f4542816f400d71
|
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/group.rb#L142-L150
|
18,962
|
atomita/fluent-plugin-aws-elasticsearch-service
|
lib/fluent/plugin/out_aws-elasticsearch-service.rb
|
Fluent::Plugin.AwsElasticsearchServiceOutput.credentials
|
def credentials(opts)
calback = lambda do
credentials = nil
unless opts[:access_key_id].empty? or opts[:secret_access_key].empty?
credentials = Aws::Credentials.new opts[:access_key_id], opts[:secret_access_key]
else
if opts[:assume_role_arn].nil?
if opts[:ecs_container_credentials_relative_uri].nil?
credentials = Aws::SharedCredentials.new({retries: 2}).credentials
credentials ||= Aws::InstanceProfileCredentials.new.credentials
credentials ||= Aws::ECSCredentials.new.credentials
else
credentials = Aws::ECSCredentials.new({
credential_path: opts[:ecs_container_credentials_relative_uri]
}).credentials
end
else
credentials = sts_credential_provider({
role_arn: opts[:assume_role_arn],
role_session_name: opts[:assume_role_session_name],
region: opts[:region]
}).credentials
end
end
raise "No valid AWS credentials found." unless credentials.set?
credentials
end
def calback.inspect
credentials = self.call
credentials.credentials.inspect
end
calback
end
|
ruby
|
def credentials(opts)
calback = lambda do
credentials = nil
unless opts[:access_key_id].empty? or opts[:secret_access_key].empty?
credentials = Aws::Credentials.new opts[:access_key_id], opts[:secret_access_key]
else
if opts[:assume_role_arn].nil?
if opts[:ecs_container_credentials_relative_uri].nil?
credentials = Aws::SharedCredentials.new({retries: 2}).credentials
credentials ||= Aws::InstanceProfileCredentials.new.credentials
credentials ||= Aws::ECSCredentials.new.credentials
else
credentials = Aws::ECSCredentials.new({
credential_path: opts[:ecs_container_credentials_relative_uri]
}).credentials
end
else
credentials = sts_credential_provider({
role_arn: opts[:assume_role_arn],
role_session_name: opts[:assume_role_session_name],
region: opts[:region]
}).credentials
end
end
raise "No valid AWS credentials found." unless credentials.set?
credentials
end
def calback.inspect
credentials = self.call
credentials.credentials.inspect
end
calback
end
|
[
"def",
"credentials",
"(",
"opts",
")",
"calback",
"=",
"lambda",
"do",
"credentials",
"=",
"nil",
"unless",
"opts",
"[",
":access_key_id",
"]",
".",
"empty?",
"or",
"opts",
"[",
":secret_access_key",
"]",
".",
"empty?",
"credentials",
"=",
"Aws",
"::",
"Credentials",
".",
"new",
"opts",
"[",
":access_key_id",
"]",
",",
"opts",
"[",
":secret_access_key",
"]",
"else",
"if",
"opts",
"[",
":assume_role_arn",
"]",
".",
"nil?",
"if",
"opts",
"[",
":ecs_container_credentials_relative_uri",
"]",
".",
"nil?",
"credentials",
"=",
"Aws",
"::",
"SharedCredentials",
".",
"new",
"(",
"{",
"retries",
":",
"2",
"}",
")",
".",
"credentials",
"credentials",
"||=",
"Aws",
"::",
"InstanceProfileCredentials",
".",
"new",
".",
"credentials",
"credentials",
"||=",
"Aws",
"::",
"ECSCredentials",
".",
"new",
".",
"credentials",
"else",
"credentials",
"=",
"Aws",
"::",
"ECSCredentials",
".",
"new",
"(",
"{",
"credential_path",
":",
"opts",
"[",
":ecs_container_credentials_relative_uri",
"]",
"}",
")",
".",
"credentials",
"end",
"else",
"credentials",
"=",
"sts_credential_provider",
"(",
"{",
"role_arn",
":",
"opts",
"[",
":assume_role_arn",
"]",
",",
"role_session_name",
":",
"opts",
"[",
":assume_role_session_name",
"]",
",",
"region",
":",
"opts",
"[",
":region",
"]",
"}",
")",
".",
"credentials",
"end",
"end",
"raise",
"\"No valid AWS credentials found.\"",
"unless",
"credentials",
".",
"set?",
"credentials",
"end",
"def",
"calback",
".",
"inspect",
"credentials",
"=",
"self",
".",
"call",
"credentials",
".",
"credentials",
".",
"inspect",
"end",
"calback",
"end"
] |
get AWS Credentials
|
[
"get",
"AWS",
"Credentials"
] |
907bd77c292469f074185d7ddc3ba73f5c45258b
|
https://github.com/atomita/fluent-plugin-aws-elasticsearch-service/blob/907bd77c292469f074185d7ddc3ba73f5c45258b/lib/fluent/plugin/out_aws-elasticsearch-service.rb#L70-L102
|
18,963
|
panthomakos/timezone
|
lib/timezone/zone.rb
|
Timezone.Zone.local_to_utc
|
def local_to_utc(time)
time = sanitize(time)
(time - rule_for_local(time).rules.first[OFFSET_BIT]).utc
end
|
ruby
|
def local_to_utc(time)
time = sanitize(time)
(time - rule_for_local(time).rules.first[OFFSET_BIT]).utc
end
|
[
"def",
"local_to_utc",
"(",
"time",
")",
"time",
"=",
"sanitize",
"(",
"time",
")",
"(",
"time",
"-",
"rule_for_local",
"(",
"time",
")",
".",
"rules",
".",
"first",
"[",
"OFFSET_BIT",
"]",
")",
".",
"utc",
"end"
] |
Converts the given local time to the UTC equivalent.
@param time [#to_time] the local time
@return [Time] the time in UTC
@note The UTC equivalent is a "best guess". There are cases where
local times do not map to UTC at all (during a time skip forward).
There are also cases where local times map to two distinct UTC
times (during a fall back). All of these cases are approximated
in this method and the first possible result is used instead.
@note A note about the handling of time arguments.
Because the UTC offset of a `Time` object in Ruby is not
equivalent to a single timezone, the `time` argument in this
method is first converted to a UTC equivalent before being
used as a local time.
This prevents confusion between historical UTC offsets and the UTC
offset that the `Time` object provides. For instance, if I pass
a "local" time with offset `+8` but the timezone actually had
an offset of `+9` at the given historical time, there is an
inconsistency that must be resolved.
Did the user make a mistake; or is the offset intentional?
One approach to solving this problem would be to raise an error,
but this means that the user then needs to calculate the
appropriate local offset and append that to a UTC time to satisfy
the function. This is impractical because the offset can already
be calculated by this library. The user should only need to
provide a time without an offset!
To resolve this inconsistency, the solution I chose was to scrub
the offset. In the case where an offset is provided, the time is
just converted to the UTC equivalent (without an offset). The
resulting time is used as the local reference time.
For example, if the time `08:00 +2` is passed to this function,
the local time is assumed to be `06:00`.
|
[
"Converts",
"the",
"given",
"local",
"time",
"to",
"the",
"UTC",
"equivalent",
"."
] |
23acc721a6b1df1fde840cf05ab097b5d59925f0
|
https://github.com/panthomakos/timezone/blob/23acc721a6b1df1fde840cf05ab097b5d59925f0/lib/timezone/zone.rb#L109-L113
|
18,964
|
panthomakos/timezone
|
lib/timezone/zone.rb
|
Timezone.Zone.time_with_offset
|
def time_with_offset(time)
time = sanitize(time)
utc = utc_to_local(time)
offset = utc_offset(time)
Time.new(
utc.year,
utc.month,
utc.day,
utc.hour,
utc.min,
utc.sec + utc.subsec,
offset
)
end
|
ruby
|
def time_with_offset(time)
time = sanitize(time)
utc = utc_to_local(time)
offset = utc_offset(time)
Time.new(
utc.year,
utc.month,
utc.day,
utc.hour,
utc.min,
utc.sec + utc.subsec,
offset
)
end
|
[
"def",
"time_with_offset",
"(",
"time",
")",
"time",
"=",
"sanitize",
"(",
"time",
")",
"utc",
"=",
"utc_to_local",
"(",
"time",
")",
"offset",
"=",
"utc_offset",
"(",
"time",
")",
"Time",
".",
"new",
"(",
"utc",
".",
"year",
",",
"utc",
".",
"month",
",",
"utc",
".",
"day",
",",
"utc",
".",
"hour",
",",
"utc",
".",
"min",
",",
"utc",
".",
"sec",
"+",
"utc",
".",
"subsec",
",",
"offset",
")",
"end"
] |
Converts the given time to the local timezone and includes the UTC
offset in the result.
@param time [#to_time] the source time
@return [Time] the time in the local timezone with the UTC offset
|
[
"Converts",
"the",
"given",
"time",
"to",
"the",
"local",
"timezone",
"and",
"includes",
"the",
"UTC",
"offset",
"in",
"the",
"result",
"."
] |
23acc721a6b1df1fde840cf05ab097b5d59925f0
|
https://github.com/panthomakos/timezone/blob/23acc721a6b1df1fde840cf05ab097b5d59925f0/lib/timezone/zone.rb#L120-L135
|
18,965
|
panthomakos/timezone
|
lib/timezone/zone.rb
|
Timezone.Zone.binary_search
|
def binary_search(time, from = 0, to = nil, &block)
to = private_rules.length - 1 if to.nil?
return from if from == to
mid = (from + to).div(2)
unless yield(time, private_rules[mid])
return binary_search(time, mid + 1, to, &block)
end
return mid if mid.zero?
return mid unless yield(time, private_rules[mid - 1])
binary_search(time, from, mid - 1, &block)
end
|
ruby
|
def binary_search(time, from = 0, to = nil, &block)
to = private_rules.length - 1 if to.nil?
return from if from == to
mid = (from + to).div(2)
unless yield(time, private_rules[mid])
return binary_search(time, mid + 1, to, &block)
end
return mid if mid.zero?
return mid unless yield(time, private_rules[mid - 1])
binary_search(time, from, mid - 1, &block)
end
|
[
"def",
"binary_search",
"(",
"time",
",",
"from",
"=",
"0",
",",
"to",
"=",
"nil",
",",
"&",
"block",
")",
"to",
"=",
"private_rules",
".",
"length",
"-",
"1",
"if",
"to",
".",
"nil?",
"return",
"from",
"if",
"from",
"==",
"to",
"mid",
"=",
"(",
"from",
"+",
"to",
")",
".",
"div",
"(",
"2",
")",
"unless",
"yield",
"(",
"time",
",",
"private_rules",
"[",
"mid",
"]",
")",
"return",
"binary_search",
"(",
"time",
",",
"mid",
"+",
"1",
",",
"to",
",",
"block",
")",
"end",
"return",
"mid",
"if",
"mid",
".",
"zero?",
"return",
"mid",
"unless",
"yield",
"(",
"time",
",",
"private_rules",
"[",
"mid",
"-",
"1",
"]",
")",
"binary_search",
"(",
"time",
",",
"from",
",",
"mid",
"-",
"1",
",",
"block",
")",
"end"
] |
Find the first rule that matches using binary search.
|
[
"Find",
"the",
"first",
"rule",
"that",
"matches",
"using",
"binary",
"search",
"."
] |
23acc721a6b1df1fde840cf05ab097b5d59925f0
|
https://github.com/panthomakos/timezone/blob/23acc721a6b1df1fde840cf05ab097b5d59925f0/lib/timezone/zone.rb#L253-L269
|
18,966
|
mongodb/bson-ruby
|
lib/bson/open_struct.rb
|
BSON.OpenStruct.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if Environment.ruby_1_9?
marshal_dump.dup
else
to_h
end.to_bson(buffer, validating_keys)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if Environment.ruby_1_9?
marshal_dump.dup
else
to_h
end.to_bson(buffer, validating_keys)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"if",
"Environment",
".",
"ruby_1_9?",
"marshal_dump",
".",
"dup",
"else",
"to_h",
"end",
".",
"to_bson",
"(",
"buffer",
",",
"validating_keys",
")",
"end"
] |
Get the OpenStruct as encoded BSON.
@example Get the OpenStruct object as encoded BSON.
OpenStruct.new({ "field" => "value" }).to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 4.2.0
|
[
"Get",
"the",
"OpenStruct",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/open_struct.rb#L35-L41
|
18,967
|
mongodb/bson-ruby
|
lib/bson/hash.rb
|
BSON.Hash.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if buffer.respond_to?(:put_hash)
buffer.put_hash(self, validating_keys)
else
position = buffer.length
buffer.put_int32(0)
each do |field, value|
buffer.put_byte(value.bson_type)
buffer.put_cstring(field.to_bson_key(validating_keys))
value.to_bson(buffer, validating_keys)
end
buffer.put_byte(NULL_BYTE)
buffer.replace_int32(position, buffer.length - position)
end
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if buffer.respond_to?(:put_hash)
buffer.put_hash(self, validating_keys)
else
position = buffer.length
buffer.put_int32(0)
each do |field, value|
buffer.put_byte(value.bson_type)
buffer.put_cstring(field.to_bson_key(validating_keys))
value.to_bson(buffer, validating_keys)
end
buffer.put_byte(NULL_BYTE)
buffer.replace_int32(position, buffer.length - position)
end
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"if",
"buffer",
".",
"respond_to?",
"(",
":put_hash",
")",
"buffer",
".",
"put_hash",
"(",
"self",
",",
"validating_keys",
")",
"else",
"position",
"=",
"buffer",
".",
"length",
"buffer",
".",
"put_int32",
"(",
"0",
")",
"each",
"do",
"|",
"field",
",",
"value",
"|",
"buffer",
".",
"put_byte",
"(",
"value",
".",
"bson_type",
")",
"buffer",
".",
"put_cstring",
"(",
"field",
".",
"to_bson_key",
"(",
"validating_keys",
")",
")",
"value",
".",
"to_bson",
"(",
"buffer",
",",
"validating_keys",
")",
"end",
"buffer",
".",
"put_byte",
"(",
"NULL_BYTE",
")",
"buffer",
".",
"replace_int32",
"(",
"position",
",",
"buffer",
".",
"length",
"-",
"position",
")",
"end",
"end"
] |
Get the hash as encoded BSON.
@example Get the hash as encoded BSON.
{ "field" => "value" }.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"hash",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/hash.rb#L40-L54
|
18,968
|
mongodb/bson-ruby
|
lib/bson/timestamp.rb
|
BSON.Timestamp.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int32(increment)
buffer.put_int32(seconds)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int32(increment)
buffer.put_int32(seconds)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_int32",
"(",
"increment",
")",
"buffer",
".",
"put_int32",
"(",
"seconds",
")",
"end"
] |
Instantiate the new timestamp.
@example Instantiate the timestamp.
BSON::Timestamp.new(5, 30)
@param [ Integer ] seconds The number of seconds.
@param [ Integer ] increment The increment value.
@since 2.0.0
Get the timestamp as its encoded raw BSON bytes.
@example Get the timestamp as BSON.
timestamp.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Instantiate",
"the",
"new",
"timestamp",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/timestamp.rb#L114-L117
|
18,969
|
mongodb/bson-ruby
|
lib/bson/array.rb
|
BSON.Array.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if buffer.respond_to?(:put_array)
buffer.put_array(self, validating_keys)
else
position = buffer.length
buffer.put_int32(0)
each_with_index do |value, index|
buffer.put_byte(value.bson_type)
buffer.put_cstring(index.to_s)
value.to_bson(buffer, validating_keys)
end
buffer.put_byte(NULL_BYTE)
buffer.replace_int32(position, buffer.length - position)
end
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if buffer.respond_to?(:put_array)
buffer.put_array(self, validating_keys)
else
position = buffer.length
buffer.put_int32(0)
each_with_index do |value, index|
buffer.put_byte(value.bson_type)
buffer.put_cstring(index.to_s)
value.to_bson(buffer, validating_keys)
end
buffer.put_byte(NULL_BYTE)
buffer.replace_int32(position, buffer.length - position)
end
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"if",
"buffer",
".",
"respond_to?",
"(",
":put_array",
")",
"buffer",
".",
"put_array",
"(",
"self",
",",
"validating_keys",
")",
"else",
"position",
"=",
"buffer",
".",
"length",
"buffer",
".",
"put_int32",
"(",
"0",
")",
"each_with_index",
"do",
"|",
"value",
",",
"index",
"|",
"buffer",
".",
"put_byte",
"(",
"value",
".",
"bson_type",
")",
"buffer",
".",
"put_cstring",
"(",
"index",
".",
"to_s",
")",
"value",
".",
"to_bson",
"(",
"buffer",
",",
"validating_keys",
")",
"end",
"buffer",
".",
"put_byte",
"(",
"NULL_BYTE",
")",
"buffer",
".",
"replace_int32",
"(",
"position",
",",
"buffer",
".",
"length",
"-",
"position",
")",
"end",
"end"
] |
Get the array as encoded BSON.
@example Get the array as encoded BSON.
[ 1, 2, 3 ].to_bson
@note Arrays are encoded as documents, where the index of the value in
the array is the actual key.
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"array",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/array.rb#L43-L57
|
18,970
|
mongodb/bson-ruby
|
lib/bson/code.rb
|
BSON.Code.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_string(javascript) # @todo: was formerly to_bson_string
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_string(javascript) # @todo: was formerly to_bson_string
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_string",
"(",
"javascript",
")",
"# @todo: was formerly to_bson_string",
"end"
] |
Instantiate the new code.
@example Instantiate the new code.
BSON::Code.new("this.value = 5")
@param [ String ] javascript The javascript code.
@since 2.0.0
Encode the javascript code.
@example Encode the code.
code.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Instantiate",
"the",
"new",
"code",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/code.rb#L84-L86
|
18,971
|
mongodb/bson-ruby
|
lib/bson/date_time.rb
|
BSON.DateTime.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
to_time.to_bson(buffer)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
to_time.to_bson(buffer)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"to_time",
".",
"to_bson",
"(",
"buffer",
")",
"end"
] |
Get the date time as encoded BSON.
@example Get the date time as encoded BSON.
DateTime.new(2012, 1, 1, 0, 0, 0).to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.1.0
|
[
"Get",
"the",
"date",
"time",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/date_time.rb#L37-L39
|
18,972
|
mongodb/bson-ruby
|
lib/bson/code_with_scope.rb
|
BSON.CodeWithScope.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
position = buffer.length
buffer.put_int32(0)
buffer.put_string(javascript)
scope.to_bson(buffer)
buffer.replace_int32(position, buffer.length - position)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
position = buffer.length
buffer.put_int32(0)
buffer.put_string(javascript)
scope.to_bson(buffer)
buffer.replace_int32(position, buffer.length - position)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"position",
"=",
"buffer",
".",
"length",
"buffer",
".",
"put_int32",
"(",
"0",
")",
"buffer",
".",
"put_string",
"(",
"javascript",
")",
"scope",
".",
"to_bson",
"(",
"buffer",
")",
"buffer",
".",
"replace_int32",
"(",
"position",
",",
"buffer",
".",
"length",
"-",
"position",
")",
"end"
] |
Instantiate the new code with scope.
@example Instantiate the code with scope.
BSON::CodeWithScope.new("this.value = name", name: "sid")
@param [ String ] javascript The javascript code.
@param [ Hash ] scope The variable scope.
@since 2.0.0
Encode the javascript code with scope.
@example Encode the code with scope.
code_with_scope.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Instantiate",
"the",
"new",
"code",
"with",
"scope",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/code_with_scope.rb#L90-L96
|
18,973
|
mongodb/bson-ruby
|
lib/bson/integer.rb
|
BSON.Integer.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if bson_int32?
buffer.put_int32(self)
elsif bson_int64?
buffer.put_int64(self)
else
out_of_range!
end
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
if bson_int32?
buffer.put_int32(self)
elsif bson_int64?
buffer.put_int64(self)
else
out_of_range!
end
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"if",
"bson_int32?",
"buffer",
".",
"put_int32",
"(",
"self",
")",
"elsif",
"bson_int64?",
"buffer",
".",
"put_int64",
"(",
"self",
")",
"else",
"out_of_range!",
"end",
"end"
] |
Get the integer as encoded BSON.
@example Get the integer as encoded BSON.
1024.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"integer",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/integer.rb#L106-L114
|
18,974
|
mongodb/bson-ruby
|
lib/bson/object_id.rb
|
BSON.ObjectId.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_bytes(generate_data)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_bytes(generate_data)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_bytes",
"(",
"generate_data",
")",
"end"
] |
Get the object id as it's raw BSON data.
@example Get the raw bson bytes.
object_id.to_bson
@note Since Moped's BSON and MongoDB BSON before 2.0.0 have different
internal representations, we will attempt to repair the data for cases
where the object was instantiated in a non-standard way. (Like a
Marshal.load)
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"object",
"id",
"as",
"it",
"s",
"raw",
"BSON",
"data",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/object_id.rb#L172-L174
|
18,975
|
mongodb/bson-ruby
|
lib/bson/true_class.rb
|
BSON.TrueClass.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_byte(TRUE_BYTE)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_byte(TRUE_BYTE)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_byte",
"(",
"TRUE_BYTE",
")",
"end"
] |
Get the true boolean as encoded BSON.
@example Get the true boolean as encoded BSON.
true.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"true",
"boolean",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/true_class.rb#L52-L54
|
18,976
|
mongodb/bson-ruby
|
lib/bson/binary.rb
|
BSON.Binary.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
position = buffer.length
buffer.put_int32(0)
buffer.put_byte(SUBTYPES[type])
buffer.put_int32(data.bytesize) if type == :old
buffer.put_bytes(data.force_encoding(BINARY))
buffer.replace_int32(position, buffer.length - position - 5)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
position = buffer.length
buffer.put_int32(0)
buffer.put_byte(SUBTYPES[type])
buffer.put_int32(data.bytesize) if type == :old
buffer.put_bytes(data.force_encoding(BINARY))
buffer.replace_int32(position, buffer.length - position - 5)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"position",
"=",
"buffer",
".",
"length",
"buffer",
".",
"put_int32",
"(",
"0",
")",
"buffer",
".",
"put_byte",
"(",
"SUBTYPES",
"[",
"type",
"]",
")",
"buffer",
".",
"put_int32",
"(",
"data",
".",
"bytesize",
")",
"if",
"type",
"==",
":old",
"buffer",
".",
"put_bytes",
"(",
"data",
".",
"force_encoding",
"(",
"BINARY",
")",
")",
"buffer",
".",
"replace_int32",
"(",
"position",
",",
"buffer",
".",
"length",
"-",
"position",
"-",
"5",
")",
"end"
] |
Encode the binary type
@example Encode the binary.
binary.to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Encode",
"the",
"binary",
"type"
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/binary.rb#L134-L141
|
18,977
|
mongodb/bson-ruby
|
lib/bson/registry.rb
|
BSON.Registry.get
|
def get(byte, field = nil)
if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord])
type
else
handle_unsupported_type!(byte, field)
end
end
|
ruby
|
def get(byte, field = nil)
if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord])
type
else
handle_unsupported_type!(byte, field)
end
end
|
[
"def",
"get",
"(",
"byte",
",",
"field",
"=",
"nil",
")",
"if",
"type",
"=",
"MAPPINGS",
"[",
"byte",
"]",
"||",
"(",
"byte",
".",
"is_a?",
"(",
"String",
")",
"&&",
"type",
"=",
"MAPPINGS",
"[",
"byte",
".",
"ord",
"]",
")",
"type",
"else",
"handle_unsupported_type!",
"(",
"byte",
",",
"field",
")",
"end",
"end"
] |
Get the class for the single byte identifier for the type in the BSON
specification.
@example Get the type for the byte.
BSON::Registry.get("\x01")
@return [ Class ] The corresponding Ruby class for the type.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"class",
"for",
"the",
"single",
"byte",
"identifier",
"for",
"the",
"type",
"in",
"the",
"BSON",
"specification",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/registry.rb#L42-L48
|
18,978
|
mongodb/bson-ruby
|
lib/bson/date.rb
|
BSON.Date.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int64((jd - DATE_REFERENCE) * MILLISECONDS_IN_DAY)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int64((jd - DATE_REFERENCE) * MILLISECONDS_IN_DAY)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_int64",
"(",
"(",
"jd",
"-",
"DATE_REFERENCE",
")",
"*",
"MILLISECONDS_IN_DAY",
")",
"end"
] |
Get the date as encoded BSON.
@example Get the date as encoded BSON.
Date.new(2012, 1, 1).to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.1.0
|
[
"Get",
"the",
"date",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/date.rb#L47-L49
|
18,979
|
mongodb/bson-ruby
|
lib/bson/regexp.rb
|
BSON.Regexp.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_cstring(source)
buffer.put_cstring(bson_options)
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_cstring(source)
buffer.put_cstring(bson_options)
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_cstring",
"(",
"source",
")",
"buffer",
".",
"put_cstring",
"(",
"bson_options",
")",
"end"
] |
Get the regular expression as encoded BSON.
@example Get the regular expression as encoded BSON.
%r{\d+}.to_bson
@note From the BSON spec: The first cstring is the regex pattern,
the second is the regex options string. Options are identified
by characters, which must be stored in alphabetical order.
Valid options are 'i' for case insensitive matching,
'm' for multiline matching, 'x' for verbose mode,
'l' to make \w, \W, etc. locale dependent,
's' for dotall mode ('.' matches everything),
and 'u' to make \w, \W, etc. match unicode.
@param [ BSON::ByteBuffer ] buffer The byte buffer to append to.
@param [ true, false ] validating_keys
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"regular",
"expression",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/regexp.rb#L92-L95
|
18,980
|
mongodb/bson-ruby
|
lib/bson/time.rb
|
BSON.Time.to_bson
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int64((to_i * 1000) + (usec / 1000))
end
|
ruby
|
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
buffer.put_int64((to_i * 1000) + (usec / 1000))
end
|
[
"def",
"to_bson",
"(",
"buffer",
"=",
"ByteBuffer",
".",
"new",
",",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"buffer",
".",
"put_int64",
"(",
"(",
"to_i",
"*",
"1000",
")",
"+",
"(",
"usec",
"/",
"1000",
")",
")",
"end"
] |
Get the time as encoded BSON.
@example Get the time as encoded BSON.
Time.new(2012, 1, 1, 0, 0, 0).to_bson
@return [ BSON::ByteBuffer ] The buffer with the encoded object.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"time",
"as",
"encoded",
"BSON",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/time.rb#L40-L42
|
18,981
|
mongodb/bson-ruby
|
lib/bson/document.rb
|
BSON.Document.fetch
|
def fetch(key, *args, &block)
key = convert_key(key)
super(key, *args, &block)
end
|
ruby
|
def fetch(key, *args, &block)
key = convert_key(key)
super(key, *args, &block)
end
|
[
"def",
"fetch",
"(",
"key",
",",
"*",
"args",
",",
"&",
"block",
")",
"key",
"=",
"convert_key",
"(",
"key",
")",
"super",
"(",
"key",
",",
"args",
",",
"block",
")",
"end"
] |
Get a value from the document for the provided key. Can use string or
symbol access, with string access being the faster of the two.
@overload fetch(key)
Returns a value from the hash for the given key. If the key does
not exist, raises KeyError exception.
@overload fetch(key, default)
Returns a value from the hash for the given key. If the key does not
exist, returns *default*.
@overload fetch(key, &block)
Returns a value from the hash for the given key. If the key does not
exist, returns the value of the block called with the key.
@example Get an element for the key.
document.fetch("field")
@example Get an element for the key by symbol with a default.
document.fetch(:field, 'foo')
@example Get an element for the key by symbol with a block default.
document.fetch(:field) { |key| key.upcase }
@param [ String, Symbol ] key The key to look up.
@param [ Object ] default Returned value if key does not exist.
@yield [key] Block returning default value for the given key.
@return [ Object ] The found value. Raises KeyError if none found.
@since 4.4.0
|
[
"Get",
"a",
"value",
"from",
"the",
"document",
"for",
"the",
"provided",
"key",
".",
"Can",
"use",
"string",
"or",
"symbol",
"access",
"with",
"string",
"access",
"being",
"the",
"faster",
"of",
"the",
"two",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/document.rb#L68-L71
|
18,982
|
mongodb/bson-ruby
|
lib/bson/document.rb
|
BSON.Document.merge!
|
def merge!(other)
other.each_pair do |key, value|
value = yield(convert_key(key), self[key], convert_value(value)) if block_given? && self[key]
self[key] = value
end
self
end
|
ruby
|
def merge!(other)
other.each_pair do |key, value|
value = yield(convert_key(key), self[key], convert_value(value)) if block_given? && self[key]
self[key] = value
end
self
end
|
[
"def",
"merge!",
"(",
"other",
")",
"other",
".",
"each_pair",
"do",
"|",
"key",
",",
"value",
"|",
"value",
"=",
"yield",
"(",
"convert_key",
"(",
"key",
")",
",",
"self",
"[",
"key",
"]",
",",
"convert_value",
"(",
"value",
")",
")",
"if",
"block_given?",
"&&",
"self",
"[",
"key",
"]",
"self",
"[",
"key",
"]",
"=",
"value",
"end",
"self",
"end"
] |
Merge this document with another document, returning the same document in
the process.
@example Merge with another document.
document.merge(name: "Bob")
@param [ BSON::Document, Hash ] other The document/hash to merge with.
@return [ BSON::Document ] The result of the merge.
@since 3.0.0
|
[
"Merge",
"this",
"document",
"with",
"another",
"document",
"returning",
"the",
"same",
"document",
"in",
"the",
"process",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/document.rb#L200-L206
|
18,983
|
mongodb/bson-ruby
|
lib/bson/symbol.rb
|
BSON.Symbol.to_bson_key
|
def to_bson_key(validating_keys = Config.validating_keys?)
if validating_keys
raise BSON::String::IllegalKey.new(self) if BSON::String::ILLEGAL_KEY =~ self
end
self
end
|
ruby
|
def to_bson_key(validating_keys = Config.validating_keys?)
if validating_keys
raise BSON::String::IllegalKey.new(self) if BSON::String::ILLEGAL_KEY =~ self
end
self
end
|
[
"def",
"to_bson_key",
"(",
"validating_keys",
"=",
"Config",
".",
"validating_keys?",
")",
"if",
"validating_keys",
"raise",
"BSON",
"::",
"String",
"::",
"IllegalKey",
".",
"new",
"(",
"self",
")",
"if",
"BSON",
"::",
"String",
"::",
"ILLEGAL_KEY",
"=~",
"self",
"end",
"self",
"end"
] |
Get the symbol as a BSON key name encoded C symbol.
@example Get the symbol as a key name.
:test.to_bson_key
@return [ String ] The encoded symbol as a BSON key.
@see http://bsonspec.org/#/specification
@since 2.0.0
|
[
"Get",
"the",
"symbol",
"as",
"a",
"BSON",
"key",
"name",
"encoded",
"C",
"symbol",
"."
] |
297af124a7462f522b75fe9851ac81ce4fd33b0f
|
https://github.com/mongodb/bson-ruby/blob/297af124a7462f522b75fe9851ac81ce4fd33b0f/lib/bson/symbol.rb#L73-L78
|
18,984
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/inspector.rb
|
RubyLint.Inspector.inspect_methods
|
def inspect_methods
return [] unless constant.respond_to?(:methods)
methods = get_methods.map do |name|
method_information(:method, name)
end
return methods.sort_by(&:name)
end
|
ruby
|
def inspect_methods
return [] unless constant.respond_to?(:methods)
methods = get_methods.map do |name|
method_information(:method, name)
end
return methods.sort_by(&:name)
end
|
[
"def",
"inspect_methods",
"return",
"[",
"]",
"unless",
"constant",
".",
"respond_to?",
"(",
":methods",
")",
"methods",
"=",
"get_methods",
".",
"map",
"do",
"|",
"name",
"|",
"method_information",
"(",
":method",
",",
"name",
")",
"end",
"return",
"methods",
".",
"sort_by",
"(",
":name",
")",
"end"
] |
Returns an Array containing all method objects sorted by their names.
@return [Array]
|
[
"Returns",
"an",
"Array",
"containing",
"all",
"method",
"objects",
"sorted",
"by",
"their",
"names",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/inspector.rb#L94-L102
|
18,985
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/inspector.rb
|
RubyLint.Inspector.inspect_modules
|
def inspect_modules
modules = []
if constant.respond_to?(:ancestors)
parent = inspect_superclass
# Take all the modules included *directly* into the constant.
modules = constant.ancestors.take_while do |ancestor|
parent && ancestor != parent
end
# Get rid of non Module instances and modules that don't have a name.
modules = modules.select do |mod|
mod.instance_of?(Module) && mod.name
end
end
return modules
end
|
ruby
|
def inspect_modules
modules = []
if constant.respond_to?(:ancestors)
parent = inspect_superclass
# Take all the modules included *directly* into the constant.
modules = constant.ancestors.take_while do |ancestor|
parent && ancestor != parent
end
# Get rid of non Module instances and modules that don't have a name.
modules = modules.select do |mod|
mod.instance_of?(Module) && mod.name
end
end
return modules
end
|
[
"def",
"inspect_modules",
"modules",
"=",
"[",
"]",
"if",
"constant",
".",
"respond_to?",
"(",
":ancestors",
")",
"parent",
"=",
"inspect_superclass",
"# Take all the modules included *directly* into the constant.",
"modules",
"=",
"constant",
".",
"ancestors",
".",
"take_while",
"do",
"|",
"ancestor",
"|",
"parent",
"&&",
"ancestor",
"!=",
"parent",
"end",
"# Get rid of non Module instances and modules that don't have a name.",
"modules",
"=",
"modules",
".",
"select",
"do",
"|",
"mod",
"|",
"mod",
".",
"instance_of?",
"(",
"Module",
")",
"&&",
"mod",
".",
"name",
"end",
"end",
"return",
"modules",
"end"
] |
Returns the modules that are included in the constant.
@return [Array]
|
[
"Returns",
"the",
"modules",
"that",
"are",
"included",
"in",
"the",
"constant",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/inspector.rb#L124-L142
|
18,986
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/inspector.rb
|
RubyLint.Inspector.inspect_superclass
|
def inspect_superclass
parent = nil
if constant.respond_to?(:superclass) \
and constant.superclass \
and constant.superclass.name
return constant.superclass
end
return parent
end
|
ruby
|
def inspect_superclass
parent = nil
if constant.respond_to?(:superclass) \
and constant.superclass \
and constant.superclass.name
return constant.superclass
end
return parent
end
|
[
"def",
"inspect_superclass",
"parent",
"=",
"nil",
"if",
"constant",
".",
"respond_to?",
"(",
":superclass",
")",
"and",
"constant",
".",
"superclass",
"and",
"constant",
".",
"superclass",
".",
"name",
"return",
"constant",
".",
"superclass",
"end",
"return",
"parent",
"end"
] |
Returns the superclass of the current constant or `nil` if there is none.
@return [Mixed]
|
[
"Returns",
"the",
"superclass",
"of",
"the",
"current",
"constant",
"or",
"nil",
"if",
"there",
"is",
"none",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/inspector.rb#L149-L159
|
18,987
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/inspector.rb
|
RubyLint.Inspector.get_methods
|
def get_methods(getter = :methods)
parent = inspect_superclass || Object
diff = constant.__send__(getter, false) -
parent.__send__(getter, false)
methods = diff | constant.__send__(getter, false)
# If the constant manually defines the initialize method (= private)
# we'll also want to include it.
if include_initialize?(getter)
methods = methods | [:initialize]
end
return methods
end
|
ruby
|
def get_methods(getter = :methods)
parent = inspect_superclass || Object
diff = constant.__send__(getter, false) -
parent.__send__(getter, false)
methods = diff | constant.__send__(getter, false)
# If the constant manually defines the initialize method (= private)
# we'll also want to include it.
if include_initialize?(getter)
methods = methods | [:initialize]
end
return methods
end
|
[
"def",
"get_methods",
"(",
"getter",
"=",
":methods",
")",
"parent",
"=",
"inspect_superclass",
"||",
"Object",
"diff",
"=",
"constant",
".",
"__send__",
"(",
"getter",
",",
"false",
")",
"-",
"parent",
".",
"__send__",
"(",
"getter",
",",
"false",
")",
"methods",
"=",
"diff",
"|",
"constant",
".",
"__send__",
"(",
"getter",
",",
"false",
")",
"# If the constant manually defines the initialize method (= private)",
"# we'll also want to include it.",
"if",
"include_initialize?",
"(",
"getter",
")",
"methods",
"=",
"methods",
"|",
"[",
":initialize",
"]",
"end",
"return",
"methods",
"end"
] |
Gets the methods of the current constant minus those defined in Object.
@param [Symbol] getter
@return [Array]
|
[
"Gets",
"the",
"methods",
"of",
"the",
"current",
"constant",
"minus",
"those",
"defined",
"in",
"Object",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/inspector.rb#L167-L181
|
18,988
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/inspector.rb
|
RubyLint.Inspector.resolve_constant
|
def resolve_constant(constant)
current = Object
final = nil
constant.split('::').each do |segment|
if current.const_defined?(segment)
current = final = current.const_get(segment)
else
raise(
ArgumentError,
"Constant #{segment} does not exist in #{constant}"
)
end
end
return final
end
|
ruby
|
def resolve_constant(constant)
current = Object
final = nil
constant.split('::').each do |segment|
if current.const_defined?(segment)
current = final = current.const_get(segment)
else
raise(
ArgumentError,
"Constant #{segment} does not exist in #{constant}"
)
end
end
return final
end
|
[
"def",
"resolve_constant",
"(",
"constant",
")",
"current",
"=",
"Object",
"final",
"=",
"nil",
"constant",
".",
"split",
"(",
"'::'",
")",
".",
"each",
"do",
"|",
"segment",
"|",
"if",
"current",
".",
"const_defined?",
"(",
"segment",
")",
"current",
"=",
"final",
"=",
"current",
".",
"const_get",
"(",
"segment",
")",
"else",
"raise",
"(",
"ArgumentError",
",",
"\"Constant #{segment} does not exist in #{constant}\"",
")",
"end",
"end",
"return",
"final",
"end"
] |
Converts a String based constant path into an actual constant.
@param [String] constant
@return [Class]
@raise [ArgumentError] Raised when one of the segments doesn't exist.
|
[
"Converts",
"a",
"String",
"based",
"constant",
"path",
"into",
"an",
"actual",
"constant",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/inspector.rb#L243-L259
|
18,989
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/iterator.rb
|
RubyLint.Iterator.execute_callback
|
def execute_callback(name, *args)
return unless respond_to?(name)
unless arity_cache.key?(name)
arity_cache[name] = method(name).arity
end
if arity_cache[name] == 0
send(name)
else
send(name, *args)
end
end
|
ruby
|
def execute_callback(name, *args)
return unless respond_to?(name)
unless arity_cache.key?(name)
arity_cache[name] = method(name).arity
end
if arity_cache[name] == 0
send(name)
else
send(name, *args)
end
end
|
[
"def",
"execute_callback",
"(",
"name",
",",
"*",
"args",
")",
"return",
"unless",
"respond_to?",
"(",
"name",
")",
"unless",
"arity_cache",
".",
"key?",
"(",
"name",
")",
"arity_cache",
"[",
"name",
"]",
"=",
"method",
"(",
"name",
")",
".",
"arity",
"end",
"if",
"arity_cache",
"[",
"name",
"]",
"==",
"0",
"send",
"(",
"name",
")",
"else",
"send",
"(",
"name",
",",
"args",
")",
"end",
"end"
] |
Executes the specified callback method if it exists.
@param [String|Symbol] name The name of the callback method to execute.
@param [Array] args Arguments to pass to the callback method.
|
[
"Executes",
"the",
"specified",
"callback",
"method",
"if",
"it",
"exists",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/iterator.rb#L115-L127
|
18,990
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/constant_path.rb
|
RubyLint.ConstantPath.constant_segments
|
def constant_segments(node = self.node)
segments = []
if has_child_node?(node)
segments.concat(constant_segments(node.children[0]))
end
segments << [node.type, name_for_node(node)]
return segments
end
|
ruby
|
def constant_segments(node = self.node)
segments = []
if has_child_node?(node)
segments.concat(constant_segments(node.children[0]))
end
segments << [node.type, name_for_node(node)]
return segments
end
|
[
"def",
"constant_segments",
"(",
"node",
"=",
"self",
".",
"node",
")",
"segments",
"=",
"[",
"]",
"if",
"has_child_node?",
"(",
"node",
")",
"segments",
".",
"concat",
"(",
"constant_segments",
"(",
"node",
".",
"children",
"[",
"0",
"]",
")",
")",
"end",
"segments",
"<<",
"[",
"node",
".",
"type",
",",
"name_for_node",
"(",
"node",
")",
"]",
"return",
"segments",
"end"
] |
Returns an Array containing the segments of a constant path.
@param [RubyLint::AST::Node] node
@return [Array<Array(Symbol,String)>]
|
[
"Returns",
"an",
"Array",
"containing",
"the",
"segments",
"of",
"a",
"constant",
"path",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/constant_path.rb#L74-L84
|
18,991
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/constant_loader.rb
|
RubyLint.ConstantLoader.bootstrap
|
def bootstrap
types = VariablePredicates::RUBY_CLASSES.values
(BOOTSTRAP_CONSTS | types).each do |name|
load_constant(name)
end
BOOTSTRAP_GVARS.each do |gvar|
definitions.define_global_variable(gvar)
end
end
|
ruby
|
def bootstrap
types = VariablePredicates::RUBY_CLASSES.values
(BOOTSTRAP_CONSTS | types).each do |name|
load_constant(name)
end
BOOTSTRAP_GVARS.each do |gvar|
definitions.define_global_variable(gvar)
end
end
|
[
"def",
"bootstrap",
"types",
"=",
"VariablePredicates",
"::",
"RUBY_CLASSES",
".",
"values",
"(",
"BOOTSTRAP_CONSTS",
"|",
"types",
")",
".",
"each",
"do",
"|",
"name",
"|",
"load_constant",
"(",
"name",
")",
"end",
"BOOTSTRAP_GVARS",
".",
"each",
"do",
"|",
"gvar",
"|",
"definitions",
".",
"define_global_variable",
"(",
"gvar",
")",
"end",
"end"
] |
Bootstraps various core definitions.
|
[
"Bootstraps",
"various",
"core",
"definitions",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/constant_loader.rb#L49-L59
|
18,992
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/constant_loader.rb
|
RubyLint.ConstantLoader.load_nested_constant
|
def load_nested_constant(constant)
if constant.start_with?("::")
constant = constant.sub(/^::/, "")
else
# ["A", "B", "C"] -> ["A::B::C", "A::B", "A"]
namespaces = module_nesting.size.downto(1).map do |n|
module_nesting.take(n).join("::")
end
namespaces.each do |ns|
load_constant("#{ns}::#{constant}")
end
end
load_constant(constant)
end
|
ruby
|
def load_nested_constant(constant)
if constant.start_with?("::")
constant = constant.sub(/^::/, "")
else
# ["A", "B", "C"] -> ["A::B::C", "A::B", "A"]
namespaces = module_nesting.size.downto(1).map do |n|
module_nesting.take(n).join("::")
end
namespaces.each do |ns|
load_constant("#{ns}::#{constant}")
end
end
load_constant(constant)
end
|
[
"def",
"load_nested_constant",
"(",
"constant",
")",
"if",
"constant",
".",
"start_with?",
"(",
"\"::\"",
")",
"constant",
"=",
"constant",
".",
"sub",
"(",
"/",
"/",
",",
"\"\"",
")",
"else",
"# [\"A\", \"B\", \"C\"] -> [\"A::B::C\", \"A::B\", \"A\"]",
"namespaces",
"=",
"module_nesting",
".",
"size",
".",
"downto",
"(",
"1",
")",
".",
"map",
"do",
"|",
"n",
"|",
"module_nesting",
".",
"take",
"(",
"n",
")",
".",
"join",
"(",
"\"::\"",
")",
"end",
"namespaces",
".",
"each",
"do",
"|",
"ns",
"|",
"load_constant",
"(",
"\"#{ns}::#{constant}\"",
")",
"end",
"end",
"load_constant",
"(",
"constant",
")",
"end"
] |
Tries to load the definitions for the given constant.
Takes into account what modules we are in to resolve the constant name.
@param [String] constant name, possibly unqualified
|
[
"Tries",
"to",
"load",
"the",
"definitions",
"for",
"the",
"given",
"constant",
".",
"Takes",
"into",
"account",
"what",
"modules",
"we",
"are",
"in",
"to",
"resolve",
"the",
"constant",
"name",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/constant_loader.rb#L131-L145
|
18,993
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/constant_loader.rb
|
RubyLint.ConstantLoader.load_constant
|
def load_constant(constant)
return if loaded?(constant)
registry.load(constant)
return unless registry.include?(constant)
apply(constant)
end
|
ruby
|
def load_constant(constant)
return if loaded?(constant)
registry.load(constant)
return unless registry.include?(constant)
apply(constant)
end
|
[
"def",
"load_constant",
"(",
"constant",
")",
"return",
"if",
"loaded?",
"(",
"constant",
")",
"registry",
".",
"load",
"(",
"constant",
")",
"return",
"unless",
"registry",
".",
"include?",
"(",
"constant",
")",
"apply",
"(",
"constant",
")",
"end"
] |
Tries to load the definitions for the given constant.
@param [String] constant
|
[
"Tries",
"to",
"load",
"the",
"definitions",
"for",
"the",
"given",
"constant",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/constant_loader.rb#L152-L160
|
18,994
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/configuration.rb
|
RubyLint.Configuration.report_levels=
|
def report_levels=(given)
available = self.class.available_report_levels
levels = []
given.each do |level|
levels << available[level] if available[level]
end
if levels.empty?
levels = default_report_levels
end
@report_levels = levels
end
|
ruby
|
def report_levels=(given)
available = self.class.available_report_levels
levels = []
given.each do |level|
levels << available[level] if available[level]
end
if levels.empty?
levels = default_report_levels
end
@report_levels = levels
end
|
[
"def",
"report_levels",
"=",
"(",
"given",
")",
"available",
"=",
"self",
".",
"class",
".",
"available_report_levels",
"levels",
"=",
"[",
"]",
"given",
".",
"each",
"do",
"|",
"level",
"|",
"levels",
"<<",
"available",
"[",
"level",
"]",
"if",
"available",
"[",
"level",
"]",
"end",
"if",
"levels",
".",
"empty?",
"levels",
"=",
"default_report_levels",
"end",
"@report_levels",
"=",
"levels",
"end"
] |
Sets a list of the enabled report levels.
@param [Array] given The report levels specified by the user.
@return [Array]
|
[
"Sets",
"a",
"list",
"of",
"the",
"enabled",
"report",
"levels",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/configuration.rb#L135-L148
|
18,995
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/configuration.rb
|
RubyLint.Configuration.analysis_classes=
|
def analysis_classes=(names)
classes = []
available = self.class.available_analysis_classes
names.each do |name|
classes << available[name] if available[name]
end
if classes.empty?
classes = default_analysis_classes
end
@analysis_classes = classes
end
|
ruby
|
def analysis_classes=(names)
classes = []
available = self.class.available_analysis_classes
names.each do |name|
classes << available[name] if available[name]
end
if classes.empty?
classes = default_analysis_classes
end
@analysis_classes = classes
end
|
[
"def",
"analysis_classes",
"=",
"(",
"names",
")",
"classes",
"=",
"[",
"]",
"available",
"=",
"self",
".",
"class",
".",
"available_analysis_classes",
"names",
".",
"each",
"do",
"|",
"name",
"|",
"classes",
"<<",
"available",
"[",
"name",
"]",
"if",
"available",
"[",
"name",
"]",
"end",
"if",
"classes",
".",
"empty?",
"classes",
"=",
"default_analysis_classes",
"end",
"@analysis_classes",
"=",
"classes",
"end"
] |
Sets a collection of the analysis constants to use.
@param [Array] names The analysis names as given by the user.
@return [Array]
|
[
"Sets",
"a",
"collection",
"of",
"the",
"analysis",
"constants",
"to",
"use",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/configuration.rb#L174-L187
|
18,996
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/rake_task.rb
|
RubyLint.RakeTask.run_task
|
def run_task
config = create_configuration
runner = RubyLint::Runner.new(config)
list = FileList.new
output = runner.analyze(list.process(files))
puts(output) unless output.empty?
end
|
ruby
|
def run_task
config = create_configuration
runner = RubyLint::Runner.new(config)
list = FileList.new
output = runner.analyze(list.process(files))
puts(output) unless output.empty?
end
|
[
"def",
"run_task",
"config",
"=",
"create_configuration",
"runner",
"=",
"RubyLint",
"::",
"Runner",
".",
"new",
"(",
"config",
")",
"list",
"=",
"FileList",
".",
"new",
"output",
"=",
"runner",
".",
"analyze",
"(",
"list",
".",
"process",
"(",
"files",
")",
")",
"puts",
"(",
"output",
")",
"unless",
"output",
".",
"empty?",
"end"
] |
Processes a list of files and writes the output to STDOUT.
|
[
"Processes",
"a",
"list",
"of",
"files",
"and",
"writes",
"the",
"output",
"to",
"STDOUT",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/rake_task.rb#L73-L80
|
18,997
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/file_scanner.rb
|
RubyLint.FileScanner.build_constant_paths_cache
|
def build_constant_paths_cache(constant)
paths = match_globbed_files(constant_to_path(constant))
# Lets see if we can find anything when using dashes for the directory
# names instead of underscores.
if paths.empty?
paths = match_globbed_files(constant_to_dashed_path(constant))
end
paths.map! { |p| File.expand_path(p) }
ignore.each do |pattern|
paths.reject! do |path|
path.include?(pattern)
end
end
# Ensure that the order is from top-level -> deeply nested files
# instead of a random order.
paths.sort! do |left, right|
left.length <=> right.length
end
@constant_paths_cache[constant] = paths
end
|
ruby
|
def build_constant_paths_cache(constant)
paths = match_globbed_files(constant_to_path(constant))
# Lets see if we can find anything when using dashes for the directory
# names instead of underscores.
if paths.empty?
paths = match_globbed_files(constant_to_dashed_path(constant))
end
paths.map! { |p| File.expand_path(p) }
ignore.each do |pattern|
paths.reject! do |path|
path.include?(pattern)
end
end
# Ensure that the order is from top-level -> deeply nested files
# instead of a random order.
paths.sort! do |left, right|
left.length <=> right.length
end
@constant_paths_cache[constant] = paths
end
|
[
"def",
"build_constant_paths_cache",
"(",
"constant",
")",
"paths",
"=",
"match_globbed_files",
"(",
"constant_to_path",
"(",
"constant",
")",
")",
"# Lets see if we can find anything when using dashes for the directory",
"# names instead of underscores.",
"if",
"paths",
".",
"empty?",
"paths",
"=",
"match_globbed_files",
"(",
"constant_to_dashed_path",
"(",
"constant",
")",
")",
"end",
"paths",
".",
"map!",
"{",
"|",
"p",
"|",
"File",
".",
"expand_path",
"(",
"p",
")",
"}",
"ignore",
".",
"each",
"do",
"|",
"pattern",
"|",
"paths",
".",
"reject!",
"do",
"|",
"path",
"|",
"path",
".",
"include?",
"(",
"pattern",
")",
"end",
"end",
"# Ensure that the order is from top-level -> deeply nested files",
"# instead of a random order.",
"paths",
".",
"sort!",
"do",
"|",
"left",
",",
"right",
"|",
"left",
".",
"length",
"<=>",
"right",
".",
"length",
"end",
"@constant_paths_cache",
"[",
"constant",
"]",
"=",
"paths",
"end"
] |
Searches all the files that could potentially define the given constant
and caches them.
@param [String] constant
|
[
"Searches",
"all",
"the",
"files",
"that",
"could",
"potentially",
"define",
"the",
"given",
"constant",
"and",
"caches",
"them",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/file_scanner.rb#L130-L154
|
18,998
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/runner.rb
|
RubyLint.Runner.parse_file
|
def parse_file(parser, file)
return parser.parse(File.read(file, :encoding => Encoding::UTF_8), file)
end
|
ruby
|
def parse_file(parser, file)
return parser.parse(File.read(file, :encoding => Encoding::UTF_8), file)
end
|
[
"def",
"parse_file",
"(",
"parser",
",",
"file",
")",
"return",
"parser",
".",
"parse",
"(",
"File",
".",
"read",
"(",
"file",
",",
":encoding",
"=>",
"Encoding",
"::",
"UTF_8",
")",
",",
"file",
")",
"end"
] |
Parses the given file and returns an Array containing all the associated
AST nodes and comments.
@param [RubyLint::Parser] parser
@param [String] file
@return [Array]
|
[
"Parses",
"the",
"given",
"file",
"and",
"returns",
"an",
"Array",
"containing",
"all",
"the",
"associated",
"AST",
"nodes",
"and",
"comments",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/runner.rb#L71-L73
|
18,999
|
YorickPeterse/ruby-lint
|
lib/ruby-lint/runner.rb
|
RubyLint.Runner.run_analysis
|
def run_analysis(ast, vm, report)
classes = configuration.analysis_classes.select do |const|
const.analyze?(ast, vm)
end
classes.each do |const|
instance = const.new(
:vm => vm,
:report => report,
:config => configuration
)
instance.iterate(ast)
end
end
|
ruby
|
def run_analysis(ast, vm, report)
classes = configuration.analysis_classes.select do |const|
const.analyze?(ast, vm)
end
classes.each do |const|
instance = const.new(
:vm => vm,
:report => report,
:config => configuration
)
instance.iterate(ast)
end
end
|
[
"def",
"run_analysis",
"(",
"ast",
",",
"vm",
",",
"report",
")",
"classes",
"=",
"configuration",
".",
"analysis_classes",
".",
"select",
"do",
"|",
"const",
"|",
"const",
".",
"analyze?",
"(",
"ast",
",",
"vm",
")",
"end",
"classes",
".",
"each",
"do",
"|",
"const",
"|",
"instance",
"=",
"const",
".",
"new",
"(",
":vm",
"=>",
"vm",
",",
":report",
"=>",
"report",
",",
":config",
"=>",
"configuration",
")",
"instance",
".",
"iterate",
"(",
"ast",
")",
"end",
"end"
] |
Runs all the registered analysis classes.
@param [RubyLint::AST::Node] ast
@param [RubyLint::VirtualMachine] vm
@param [RubyLint::Report] report
|
[
"Runs",
"all",
"the",
"registered",
"analysis",
"classes",
"."
] |
87842ae295c2283d8e02d951781189486a7cc970
|
https://github.com/YorickPeterse/ruby-lint/blob/87842ae295c2283d8e02d951781189486a7cc970/lib/ruby-lint/runner.rb#L137-L151
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.