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
sequence
docstring
stringlengths
8
16k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
94
266
partition
stringclasses
1 value
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.disable_vuln_check
def disable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/Check[@id='#{check_id}']") disabled_checks = checks.elements['Disabled'] || checks.add_element('Disabled') disabled_checks.add_element('Check', { 'id' => check_id }) end
ruby
def disable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/Check[@id='#{check_id}']") disabled_checks = checks.elements['Disabled'] || checks.add_element('Disabled') disabled_checks.add_element('Check', { 'id' => check_id }) end
[ "def", "disable_vuln_check", "(", "check_id", ")", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks'", ")", "checks", ".", "elements", ".", "delete", "(", "\"Enabled/Check[@id='#{check_id}']\"", ")", "disabled_checks", "=", "checks", ".", "elements", "[", "'Disabled'", "]", "||", "checks", ".", "add_element", "(", "'Disabled'", ")", "disabled_checks", ".", "add_element", "(", "'Check'", ",", "{", "'id'", "=>", "check_id", "}", ")", "end" ]
Disable individual check for this template. @param [String] check_id Unique identifier of vuln check.
[ "Disable", "individual", "check", "for", "this", "template", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L454-L459
train
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.remove_vuln_check
def remove_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements.delete("Enabled/Check[@id='#{check_id}']") end
ruby
def remove_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements.delete("Enabled/Check[@id='#{check_id}']") end
[ "def", "remove_vuln_check", "(", "check_id", ")", "checks", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'//VulnerabilityChecks'", ")", "checks", ".", "elements", ".", "delete", "(", "\"Disabled/Check[@id='#{check_id}']\"", ")", "checks", ".", "elements", ".", "delete", "(", "\"Enabled/Check[@id='#{check_id}']\"", ")", "end" ]
Remove individual check for this template. Removes both enabled and disabled checks. @param [String] check_id Unique identifier of vuln check.
[ "Remove", "individual", "check", "for", "this", "template", ".", "Removes", "both", "enabled", "and", "disabled", "checks", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L466-L470
train
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.save
def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') if root.attributes['id'] == '#NewScanTemplate#' response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) root.attributes['id'] = response['value'] else response = JSON.parse(AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml)) end response['value'] end
ruby
def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') if root.attributes['id'] == '#NewScanTemplate#' response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) root.attributes['id'] = response['value'] else response = JSON.parse(AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml)) end response['value'] end
[ "def", "save", "(", "nsc", ")", "root", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate'", ")", "if", "root", ".", "attributes", "[", "'id'", "]", "==", "'#NewScanTemplate#'", "response", "=", "JSON", ".", "parse", "(", "AJAX", ".", "post", "(", "nsc", ",", "'/data/scan/templates'", ",", "xml", ")", ")", "root", ".", "attributes", "[", "'id'", "]", "=", "response", "[", "'value'", "]", "else", "response", "=", "JSON", ".", "parse", "(", "AJAX", ".", "put", "(", "nsc", ",", "\"/data/scan/templates/#{URI.encode(id)}\"", ",", "xml", ")", ")", "end", "response", "[", "'value'", "]", "end" ]
Save this scan template configuration to a Nexpose console. @param [Connection] nsc API connection to a Nexpose console.
[ "Save", "this", "scan", "template", "configuration", "to", "a", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L476-L485
train
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.aces_level=
def aces_level=(level) return if level.nil? return unless ['full', 'default', 'none'].include? level.downcase logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end aces = REXML::XPath.first(logging, 'aces') if aces.nil? aces = REXML::Element.new('aces') logging.add_element(aces) end aces.attributes['level'] = level end
ruby
def aces_level=(level) return if level.nil? return unless ['full', 'default', 'none'].include? level.downcase logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end aces = REXML::XPath.first(logging, 'aces') if aces.nil? aces = REXML::Element.new('aces') logging.add_element(aces) end aces.attributes['level'] = level end
[ "def", "aces_level", "=", "(", "level", ")", "return", "if", "level", ".", "nil?", "return", "unless", "[", "'full'", ",", "'default'", ",", "'none'", "]", ".", "include?", "level", ".", "downcase", "logging", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Logging'", ")", "if", "logging", ".", "nil?", "logging", "=", "REXML", "::", "Element", ".", "new", "(", "'Logging'", ")", "@xml", ".", "add_element", "(", "logging", ")", "end", "aces", "=", "REXML", "::", "XPath", ".", "first", "(", "logging", ",", "'aces'", ")", "if", "aces", ".", "nil?", "aces", "=", "REXML", "::", "Element", ".", "new", "(", "'aces'", ")", "logging", ".", "add_element", "(", "aces", ")", "end", "aces", ".", "attributes", "[", "'level'", "]", "=", "level", "end" ]
Enable or disable asset configuration scanning for this template. If the level is not "full", "default" or "none", this is a no-op. @param [String] "full" to enable asset configuration logging, and "default" or "none" to disable it.
[ "Enable", "or", "disable", "asset", "configuration", "scanning", "for", "this", "template", ".", "If", "the", "level", "is", "not", "full", "default", "or", "none", "this", "is", "a", "no", "-", "op", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L531-L545
train
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.enable_debug_logging=
def enable_debug_logging=(enable) return if enable.nil? logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end debug_logging = REXML::XPath.first(logging, 'debugLogging') if debug_logging.nil? debug_logging = REXML::Element.new('debugLogging') logging.add_element(debug_logging) end debug_logging.attributes['enabled'] = (enable ? 1 : 0) end
ruby
def enable_debug_logging=(enable) return if enable.nil? logging = REXML::XPath.first(@xml, 'ScanTemplate/Logging') if logging.nil? logging = REXML::Element.new('Logging') @xml.add_element(logging) end debug_logging = REXML::XPath.first(logging, 'debugLogging') if debug_logging.nil? debug_logging = REXML::Element.new('debugLogging') logging.add_element(debug_logging) end debug_logging.attributes['enabled'] = (enable ? 1 : 0) end
[ "def", "enable_debug_logging", "=", "(", "enable", ")", "return", "if", "enable", ".", "nil?", "logging", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Logging'", ")", "if", "logging", ".", "nil?", "logging", "=", "REXML", "::", "Element", ".", "new", "(", "'Logging'", ")", "@xml", ".", "add_element", "(", "logging", ")", "end", "debug_logging", "=", "REXML", "::", "XPath", ".", "first", "(", "logging", ",", "'debugLogging'", ")", "if", "debug_logging", ".", "nil?", "debug_logging", "=", "REXML", "::", "Element", ".", "new", "(", "'debugLogging'", ")", "logging", ".", "add_element", "(", "debug_logging", ")", "end", "debug_logging", ".", "attributes", "[", "'enabled'", "]", "=", "(", "enable", "?", "1", ":", "0", ")", "end" ]
Enable or disable the debug logging. @param [Boolean] enable Enable or disable the debug logging.
[ "Enable", "or", "disable", "the", "debug", "logging", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L565-L578
train
rapid7/nexpose-client
lib/nexpose/scan_template.rb
Nexpose.ScanTemplate.windows_service_editor=
def windows_service_editor=(enable) cifs_scanner = REXML::XPath.first(@xml, 'ScanTemplate/Plugins/Plugin[@name="java/CifsScanner"]') param = REXML::XPath.first(cifs_scanner, './param[@name="windowsServiceEditor"]') if param param.text = (enable ? '1' : '0') else param = REXML::Element.new('param') param.attributes['name'] = 'windowsServiceEditor' param.text = (enable ? '1' : '0') cifs_scanner.add_element(param) end param.text end
ruby
def windows_service_editor=(enable) cifs_scanner = REXML::XPath.first(@xml, 'ScanTemplate/Plugins/Plugin[@name="java/CifsScanner"]') param = REXML::XPath.first(cifs_scanner, './param[@name="windowsServiceEditor"]') if param param.text = (enable ? '1' : '0') else param = REXML::Element.new('param') param.attributes['name'] = 'windowsServiceEditor' param.text = (enable ? '1' : '0') cifs_scanner.add_element(param) end param.text end
[ "def", "windows_service_editor", "=", "(", "enable", ")", "cifs_scanner", "=", "REXML", "::", "XPath", ".", "first", "(", "@xml", ",", "'ScanTemplate/Plugins/Plugin[@name=\"java/CifsScanner\"]'", ")", "param", "=", "REXML", "::", "XPath", ".", "first", "(", "cifs_scanner", ",", "'./param[@name=\"windowsServiceEditor\"]'", ")", "if", "param", "param", ".", "text", "=", "(", "enable", "?", "'1'", ":", "'0'", ")", "else", "param", "=", "REXML", "::", "Element", ".", "new", "(", "'param'", ")", "param", ".", "attributes", "[", "'name'", "]", "=", "'windowsServiceEditor'", "param", ".", "text", "=", "(", "enable", "?", "'1'", ":", "'0'", ")", "cifs_scanner", ".", "add_element", "(", "param", ")", "end", "param", ".", "text", "end" ]
Enable or disable windows service editor. @param [Boolean] enable Enable or disable windows service editor.
[ "Enable", "or", "disable", "windows", "service", "editor", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/scan_template.rb#L589-L601
train
rapid7/nexpose-client
lib/nexpose/role.rb
Nexpose.Connection.role_listing
def role_listing xml = make_xml('RoleListingRequest') r = execute(xml, '1.2') roles = [] if r.success r.res.elements.each('RoleListingResponse/RoleSummary') do |summary| roles << RoleSummary.parse(summary) end end roles end
ruby
def role_listing xml = make_xml('RoleListingRequest') r = execute(xml, '1.2') roles = [] if r.success r.res.elements.each('RoleListingResponse/RoleSummary') do |summary| roles << RoleSummary.parse(summary) end end roles end
[ "def", "role_listing", "xml", "=", "make_xml", "(", "'RoleListingRequest'", ")", "r", "=", "execute", "(", "xml", ",", "'1.2'", ")", "roles", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'RoleListingResponse/RoleSummary'", ")", "do", "|", "summary", "|", "roles", "<<", "RoleSummary", ".", "parse", "(", "summary", ")", "end", "end", "roles", "end" ]
Returns a summary list of all roles.
[ "Returns", "a", "summary", "list", "of", "all", "roles", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/role.rb#L53-L63
train
rapid7/nexpose-client
lib/nexpose/role.rb
Nexpose.Role.save
def save(nsc) if @existing xml = nsc.make_xml('RoleUpdateRequest') else xml = nsc.make_xml('RoleCreateRequest') end xml.add_element(as_xml) response = APIRequest.execute(nsc.url, xml, '1.2', { timeout: nsc.timeout, open_timeout: nsc.open_timeout }) xml = REXML::XPath.first(response.res, 'RoleCreateResponse') @id = xml.attributes['id'].to_i unless @existing @existing = true response.success end
ruby
def save(nsc) if @existing xml = nsc.make_xml('RoleUpdateRequest') else xml = nsc.make_xml('RoleCreateRequest') end xml.add_element(as_xml) response = APIRequest.execute(nsc.url, xml, '1.2', { timeout: nsc.timeout, open_timeout: nsc.open_timeout }) xml = REXML::XPath.first(response.res, 'RoleCreateResponse') @id = xml.attributes['id'].to_i unless @existing @existing = true response.success end
[ "def", "save", "(", "nsc", ")", "if", "@existing", "xml", "=", "nsc", ".", "make_xml", "(", "'RoleUpdateRequest'", ")", "else", "xml", "=", "nsc", ".", "make_xml", "(", "'RoleCreateRequest'", ")", "end", "xml", ".", "add_element", "(", "as_xml", ")", "response", "=", "APIRequest", ".", "execute", "(", "nsc", ".", "url", ",", "xml", ",", "'1.2'", ",", "{", "timeout", ":", "nsc", ".", "timeout", ",", "open_timeout", ":", "nsc", ".", "open_timeout", "}", ")", "xml", "=", "REXML", "::", "XPath", ".", "first", "(", "response", ".", "res", ",", "'RoleCreateResponse'", ")", "@id", "=", "xml", ".", "attributes", "[", "'id'", "]", ".", "to_i", "unless", "@existing", "@existing", "=", "true", "response", ".", "success", "end" ]
Create or save a Role to the Nexpose console. @param [Connection] nsc Nexpose connection.
[ "Create", "or", "save", "a", "Role", "to", "the", "Nexpose", "console", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/role.rb#L174-L187
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.get
def get(nsc, uri, content_type = CONTENT_TYPE::XML, options = {}) parameterize_uri(uri, options) get = Net::HTTP::Get.new(uri) get.set_content_type(content_type) request(nsc, get) end
ruby
def get(nsc, uri, content_type = CONTENT_TYPE::XML, options = {}) parameterize_uri(uri, options) get = Net::HTTP::Get.new(uri) get.set_content_type(content_type) request(nsc, get) end
[ "def", "get", "(", "nsc", ",", "uri", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ",", "options", "=", "{", "}", ")", "parameterize_uri", "(", "uri", ",", "options", ")", "get", "=", "Net", "::", "HTTP", "::", "Get", ".", "new", "(", "uri", ")", "get", ".", "set_content_type", "(", "content_type", ")", "request", "(", "nsc", ",", "get", ")", "end" ]
GET call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String] content_type Content type to use when issuing the GET. @param [Hash] options Parameter options to the call. @return [String|REXML::Document|Hash] The response from the call.
[ "GET", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L31-L36
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.put
def put(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) put = Net::HTTP::Put.new(uri) put.set_content_type(content_type) put.body = payload.to_s if payload request(nsc, put) end
ruby
def put(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) put = Net::HTTP::Put.new(uri) put.set_content_type(content_type) put.body = payload.to_s if payload request(nsc, put) end
[ "def", "put", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "put", "=", "Net", "::", "HTTP", "::", "Put", ".", "new", "(", "uri", ")", "put", ".", "set_content_type", "(", "content_type", ")", "put", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "put", ")", "end" ]
PUT call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the PUT. @return [String] The response from the call.
[ "PUT", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L46-L51
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.post
def post(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML, timeout = nil) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.body = payload.to_s if payload request(nsc, post, timeout) end
ruby
def post(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML, timeout = nil) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.body = payload.to_s if payload request(nsc, post, timeout) end
[ "def", "post", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ",", "timeout", "=", "nil", ")", "post", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "uri", ")", "post", ".", "set_content_type", "(", "content_type", ")", "post", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "post", ",", "timeout", ")", "end" ]
POST call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the POST. @param [Fixnum] timeout Set an explicit timeout for the HTTP request. @return [String|REXML::Document|Hash] The response from the call.
[ "POST", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L62-L67
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.patch
def patch(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) patch = Net::HTTP::Patch.new(uri) patch.set_content_type(content_type) patch.body = payload.to_s if payload request(nsc, patch) end
ruby
def patch(nsc, uri, payload = nil, content_type = CONTENT_TYPE::XML) patch = Net::HTTP::Patch.new(uri) patch.set_content_type(content_type) patch.body = payload.to_s if payload request(nsc, patch) end
[ "def", "patch", "(", "nsc", ",", "uri", ",", "payload", "=", "nil", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "patch", "=", "Net", "::", "HTTP", "::", "Patch", ".", "new", "(", "uri", ")", "patch", ".", "set_content_type", "(", "content_type", ")", "patch", ".", "body", "=", "payload", ".", "to_s", "if", "payload", "request", "(", "nsc", ",", "patch", ")", "end" ]
PATCH call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String|REXML::Document] payload XML document required by the call. @param [String] content_type Content type to use when issuing the PATCH. @return [String] The response from the call.
[ "PATCH", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L77-L82
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.form_post
def form_post(nsc, uri, parameters, content_type = CONTENT_TYPE::FORM) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.set_form_data(parameters) request(nsc, post) end
ruby
def form_post(nsc, uri, parameters, content_type = CONTENT_TYPE::FORM) post = Net::HTTP::Post.new(uri) post.set_content_type(content_type) post.set_form_data(parameters) request(nsc, post) end
[ "def", "form_post", "(", "nsc", ",", "uri", ",", "parameters", ",", "content_type", "=", "CONTENT_TYPE", "::", "FORM", ")", "post", "=", "Net", "::", "HTTP", "::", "Post", ".", "new", "(", "uri", ")", "post", ".", "set_content_type", "(", "content_type", ")", "post", ".", "set_form_data", "(", "parameters", ")", "request", "(", "nsc", ",", "post", ")", "end" ]
POST call to a Nexpose controller that uses a form-post model. This is here to support legacy use of POST in old controllers. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [Hash] parameters Hash of attributes that need to be sent to the controller. @param [String] content_type Content type to use when issuing the POST. @return [Hash] The parsed JSON response from the call.
[ "POST", "call", "to", "a", "Nexpose", "controller", "that", "uses", "a", "form", "-", "post", "model", ".", "This", "is", "here", "to", "support", "legacy", "use", "of", "POST", "in", "old", "controllers", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L94-L99
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.delete
def delete(nsc, uri, content_type = CONTENT_TYPE::XML) delete = Net::HTTP::Delete.new(uri) delete.set_content_type(content_type) request(nsc, delete) end
ruby
def delete(nsc, uri, content_type = CONTENT_TYPE::XML) delete = Net::HTTP::Delete.new(uri) delete.set_content_type(content_type) request(nsc, delete) end
[ "def", "delete", "(", "nsc", ",", "uri", ",", "content_type", "=", "CONTENT_TYPE", "::", "XML", ")", "delete", "=", "Net", "::", "HTTP", "::", "Delete", ".", "new", "(", "uri", ")", "delete", ".", "set_content_type", "(", "content_type", ")", "request", "(", "nsc", ",", "delete", ")", "end" ]
DELETE call to a Nexpose controller. @param [Connection] nsc API connection to a Nexpose console. @param [String] uri Controller address relative to https://host:port @param [String] content_type Content type to use when issuing the DELETE.
[ "DELETE", "call", "to", "a", "Nexpose", "controller", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L106-L110
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.get_error_message
def get_error_message(request, response) version = get_request_api_version(request) data_request = use_response_error_message?(request, response) return_response = (version >= 2.1 || data_request) (return_response && response.body) ? "response body: #{response.body}" : "request body: #{request.body}" end
ruby
def get_error_message(request, response) version = get_request_api_version(request) data_request = use_response_error_message?(request, response) return_response = (version >= 2.1 || data_request) (return_response && response.body) ? "response body: #{response.body}" : "request body: #{request.body}" end
[ "def", "get_error_message", "(", "request", ",", "response", ")", "version", "=", "get_request_api_version", "(", "request", ")", "data_request", "=", "use_response_error_message?", "(", "request", ",", "response", ")", "return_response", "=", "(", "version", ">=", "2.1", "||", "data_request", ")", "(", "return_response", "&&", "response", ".", "body", ")", "?", "\"response body: #{response.body}\"", ":", "\"request body: #{request.body}\"", "end" ]
Get an error message from the response body if the request url api version is 2.1 or greater otherwise use the request body
[ "Get", "an", "error", "message", "from", "the", "response", "body", "if", "the", "request", "url", "api", "version", "is", "2", ".", "1", "or", "greater", "otherwise", "use", "the", "request", "body" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L194-L199
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.use_response_error_message?
def use_response_error_message?(request, response) if (request.path.include?('/data/') && !response.content_type.nil?) response.content_type.include? 'text/plain' else false end end
ruby
def use_response_error_message?(request, response) if (request.path.include?('/data/') && !response.content_type.nil?) response.content_type.include? 'text/plain' else false end end
[ "def", "use_response_error_message?", "(", "request", ",", "response", ")", "if", "(", "request", ".", "path", ".", "include?", "(", "'/data/'", ")", "&&", "!", "response", ".", "content_type", ".", "nil?", ")", "response", ".", "content_type", ".", "include?", "'text/plain'", "else", "false", "end", "end" ]
Code cleanup to allow for cleaner get_error_message method
[ "Code", "cleanup", "to", "allow", "for", "cleaner", "get_error_message", "method" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L203-L209
train
rapid7/nexpose-client
lib/nexpose/ajax.rb
Nexpose.AJAX.preserving_preference
def preserving_preference(nsc, pref) orig = get_rows(nsc, pref) yield ensure set_rows(nsc, pref, orig) end
ruby
def preserving_preference(nsc, pref) orig = get_rows(nsc, pref) yield ensure set_rows(nsc, pref, orig) end
[ "def", "preserving_preference", "(", "nsc", ",", "pref", ")", "orig", "=", "get_rows", "(", "nsc", ",", "pref", ")", "yield", "ensure", "set_rows", "(", "nsc", ",", "pref", ",", "orig", ")", "end" ]
Execute a block of code while presenving the preferences for any underlying table being accessed. Use this method when accessing data tables which are present in the UI to prevent existing row preferences from being set to 500. This is an internal utility method, not subject to backward compatibility concerns. @param [Connection] nsc Live connection to a Nepose console. @param [String] pref Preference key value to preserve.
[ "Execute", "a", "block", "of", "code", "while", "presenving", "the", "preferences", "for", "any", "underlying", "table", "being", "accessed", ".", "Use", "this", "method", "when", "accessing", "data", "tables", "which", "are", "present", "in", "the", "UI", "to", "prevent", "existing", "row", "preferences", "from", "being", "set", "to", "500", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/ajax.rb#L222-L227
train
rapid7/nexpose-client
lib/nexpose/filter.rb
Nexpose.Connection.filter
def filter(field, operator, value = '') criterion = Criterion.new(field, operator, value) criteria = Criteria.new(criterion) search(criteria) end
ruby
def filter(field, operator, value = '') criterion = Criterion.new(field, operator, value) criteria = Criteria.new(criterion) search(criteria) end
[ "def", "filter", "(", "field", ",", "operator", ",", "value", "=", "''", ")", "criterion", "=", "Criterion", ".", "new", "(", "field", ",", "operator", ",", "value", ")", "criteria", "=", "Criteria", ".", "new", "(", "criterion", ")", "search", "(", "criteria", ")", "end" ]
Perform an asset filter search that will locate assets matching the provided conditions. For example, the following call will return assets with Java installed: nsc.filter(Search::Field::SOFTWARE, Search::Operator::CONTAINS, 'java') @param [String] field Constant from Search::Field @param [String] operator Constant from Search::Operator @param [String] value Search term or constant from Search::Value @return [Array[FilteredAsset]] List of matching assets.
[ "Perform", "an", "asset", "filter", "search", "that", "will", "locate", "assets", "matching", "the", "provided", "conditions", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/filter.rb#L15-L19
train
rapid7/nexpose-client
lib/nexpose/filter.rb
Nexpose.Connection.search
def search(criteria) results = DataTable._get_json_table(self, '/data/asset/filterAssets', criteria._to_payload) results.map { |a| FilteredAsset.new(a) } end
ruby
def search(criteria) results = DataTable._get_json_table(self, '/data/asset/filterAssets', criteria._to_payload) results.map { |a| FilteredAsset.new(a) } end
[ "def", "search", "(", "criteria", ")", "results", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "'/data/asset/filterAssets'", ",", "criteria", ".", "_to_payload", ")", "results", ".", "map", "{", "|", "a", "|", "FilteredAsset", ".", "new", "(", "a", ")", "}", "end" ]
Perform a search that will match the criteria provided. For example, the following call will return assets with Java and .NET: java_criterion = Criterion.new(Search::Field::SOFTWARE, Search::Operator::CONTAINS, 'java') dot_net_criterion = Criterion.new(Search::Field::SOFTWARE, Search::Operator::CONTAINS, '.net') criteria = Criteria.new([java_criterion, dot_net_criterion]) results = nsc.search(criteria) @param [Criteria] criteria Criteria search object. @return [Array[FilteredAsset]] List of matching assets.
[ "Perform", "a", "search", "that", "will", "match", "the", "criteria", "provided", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/filter.rb#L36-L39
train
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.login
def login login_hash = { 'sync-id' => 0, 'password' => @password, 'user-id' => @username, 'token' => @token } login_hash['silo-id'] = @silo_id if @silo_id r = execute(make_xml('LoginRequest', login_hash)) if r.success @session_id = r.sid true end rescue APIError raise AuthenticationFailed.new(r) end
ruby
def login login_hash = { 'sync-id' => 0, 'password' => @password, 'user-id' => @username, 'token' => @token } login_hash['silo-id'] = @silo_id if @silo_id r = execute(make_xml('LoginRequest', login_hash)) if r.success @session_id = r.sid true end rescue APIError raise AuthenticationFailed.new(r) end
[ "def", "login", "login_hash", "=", "{", "'sync-id'", "=>", "0", ",", "'password'", "=>", "@password", ",", "'user-id'", "=>", "@username", ",", "'token'", "=>", "@token", "}", "login_hash", "[", "'silo-id'", "]", "=", "@silo_id", "if", "@silo_id", "r", "=", "execute", "(", "make_xml", "(", "'LoginRequest'", ",", "login_hash", ")", ")", "if", "r", ".", "success", "@session_id", "=", "r", ".", "sid", "true", "end", "rescue", "APIError", "raise", "AuthenticationFailed", ".", "new", "(", "r", ")", "end" ]
A constructor for Connection @param [String] ip The IP address or hostname/FQDN of the Nexpose console. @param [String] user The username for Nexpose sessions. @param [String] pass The password for Nexpose sessions. @param [Fixnum] port The port number of the Nexpose console. @param [String] silo_id The silo identifier for Nexpose sessions. @param [String] token The two-factor authentication (2FA) token for Nexpose sessions. @param [String] trust_cert The PEM-formatted web certificate of the Nexpose console. Used for SSL validation. Establish a new connection and Session ID
[ "A", "constructor", "for", "Connection" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L99-L109
train
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.logout
def logout r = execute(make_xml('LogoutRequest', { 'sync-id' => 0 })) return true if r.success raise APIError.new(r, 'Logout failed') end
ruby
def logout r = execute(make_xml('LogoutRequest', { 'sync-id' => 0 })) return true if r.success raise APIError.new(r, 'Logout failed') end
[ "def", "logout", "r", "=", "execute", "(", "make_xml", "(", "'LogoutRequest'", ",", "{", "'sync-id'", "=>", "0", "}", ")", ")", "return", "true", "if", "r", ".", "success", "raise", "APIError", ".", "new", "(", "r", ",", "'Logout failed'", ")", "end" ]
Logout of the current connection
[ "Logout", "of", "the", "current", "connection" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L112-L116
train
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.execute
def execute(xml, version = '1.1', options = {}) options.store(:timeout, @timeout) unless options.key?(:timeout) options.store(:open_timeout, @open_timeout) @request_xml = xml.to_s @api_version = version response = APIRequest.execute(@url, @request_xml, @api_version, options, @trust_store) @response_xml = response.raw_response_data response end
ruby
def execute(xml, version = '1.1', options = {}) options.store(:timeout, @timeout) unless options.key?(:timeout) options.store(:open_timeout, @open_timeout) @request_xml = xml.to_s @api_version = version response = APIRequest.execute(@url, @request_xml, @api_version, options, @trust_store) @response_xml = response.raw_response_data response end
[ "def", "execute", "(", "xml", ",", "version", "=", "'1.1'", ",", "options", "=", "{", "}", ")", "options", ".", "store", "(", ":timeout", ",", "@timeout", ")", "unless", "options", ".", "key?", "(", ":timeout", ")", "options", ".", "store", "(", ":open_timeout", ",", "@open_timeout", ")", "@request_xml", "=", "xml", ".", "to_s", "@api_version", "=", "version", "response", "=", "APIRequest", ".", "execute", "(", "@url", ",", "@request_xml", ",", "@api_version", ",", "options", ",", "@trust_store", ")", "@response_xml", "=", "response", ".", "raw_response_data", "response", "end" ]
Execute an API request
[ "Execute", "an", "API", "request" ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L119-L127
train
rapid7/nexpose-client
lib/nexpose/connection.rb
Nexpose.Connection.download
def download(url, file_name = nil) return nil if (url.nil? || url.empty?) uri = URI.parse(url) http = Net::HTTP.new(@host, @port) http.use_ssl = true if @trust_store.nil? http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue else http.cert_store = @trust_store end headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}" } if file_name http.request_get(uri.to_s, headers) do |resp| ::File.open(file_name, 'wb') do |file| resp.read_body { |chunk| file.write(chunk) } end end else resp = http.get(uri.to_s, headers) resp.body end end
ruby
def download(url, file_name = nil) return nil if (url.nil? || url.empty?) uri = URI.parse(url) http = Net::HTTP.new(@host, @port) http.use_ssl = true if @trust_store.nil? http.verify_mode = OpenSSL::SSL::VERIFY_NONE # XXX: security issue else http.cert_store = @trust_store end headers = { 'Cookie' => "nexposeCCSessionID=#{@session_id}" } if file_name http.request_get(uri.to_s, headers) do |resp| ::File.open(file_name, 'wb') do |file| resp.read_body { |chunk| file.write(chunk) } end end else resp = http.get(uri.to_s, headers) resp.body end end
[ "def", "download", "(", "url", ",", "file_name", "=", "nil", ")", "return", "nil", "if", "(", "url", ".", "nil?", "||", "url", ".", "empty?", ")", "uri", "=", "URI", ".", "parse", "(", "url", ")", "http", "=", "Net", "::", "HTTP", ".", "new", "(", "@host", ",", "@port", ")", "http", ".", "use_ssl", "=", "true", "if", "@trust_store", ".", "nil?", "http", ".", "verify_mode", "=", "OpenSSL", "::", "SSL", "::", "VERIFY_NONE", "# XXX: security issue", "else", "http", ".", "cert_store", "=", "@trust_store", "end", "headers", "=", "{", "'Cookie'", "=>", "\"nexposeCCSessionID=#{@session_id}\"", "}", "if", "file_name", "http", ".", "request_get", "(", "uri", ".", "to_s", ",", "headers", ")", "do", "|", "resp", "|", "::", "File", ".", "open", "(", "file_name", ",", "'wb'", ")", "do", "|", "file", "|", "resp", ".", "read_body", "{", "|", "chunk", "|", "file", ".", "write", "(", "chunk", ")", "}", "end", "end", "else", "resp", "=", "http", ".", "get", "(", "uri", ".", "to_s", ",", "headers", ")", "resp", ".", "body", "end", "end" ]
Download a specific URL, typically a report. Include an optional file_name parameter to write the output to a file. Note: XML and HTML reports have charts not downloaded by this method. Would need to do something more sophisticated to grab all the associated image files.
[ "Download", "a", "specific", "URL", "typically", "a", "report", ".", "Include", "an", "optional", "file_name", "parameter", "to", "write", "the", "output", "to", "a", "file", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/connection.rb#L135-L157
train
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.find_device_by_address
def find_device_by_address(address, site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) if r.success device = REXML::XPath.first(r.res, "SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']") if device return Device.new(device.attributes['id'].to_i, device.attributes['address'], device.parent.attributes['site-id'], device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end nil end
ruby
def find_device_by_address(address, site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) if r.success device = REXML::XPath.first(r.res, "SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']") if device return Device.new(device.attributes['id'].to_i, device.attributes['address'], device.parent.attributes['site-id'], device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end nil end
[ "def", "find_device_by_address", "(", "address", ",", "site_id", "=", "nil", ")", "r", "=", "execute", "(", "make_xml", "(", "'SiteDeviceListingRequest'", ",", "{", "'site-id'", "=>", "site_id", "}", ")", ")", "if", "r", ".", "success", "device", "=", "REXML", "::", "XPath", ".", "first", "(", "r", ".", "res", ",", "\"SiteDeviceListingResponse/SiteDevices/device[@address='#{address}']\"", ")", "if", "device", "return", "Device", ".", "new", "(", "device", ".", "attributes", "[", "'id'", "]", ".", "to_i", ",", "device", ".", "attributes", "[", "'address'", "]", ",", "device", ".", "parent", ".", "attributes", "[", "'site-id'", "]", ",", "device", ".", "attributes", "[", "'riskfactor'", "]", ".", "to_f", ",", "device", ".", "attributes", "[", "'riskscore'", "]", ".", "to_f", ")", "end", "end", "nil", "end" ]
Find a Device by its address. This is a convenience method for finding a single device from a SiteDeviceListing. If no site_id is provided, the first matching device will be returned when a device occurs across multiple sites. @param [String] address Address of the device to find. Usually the IP address. @param [FixNum] site_id Site ID to restrict search to. @return [Device] The first matching Device with the provided address, if found.
[ "Find", "a", "Device", "by", "its", "address", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L17-L30
train
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.list_site_devices
def list_site_devices(site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) devices = [] if r.success r.res.elements.each('SiteDeviceListingResponse/SiteDevices') do |site| site_id = site.attributes['site-id'].to_i site.elements.each('device') do |device| devices << Device.new(device.attributes['id'].to_i, device.attributes['address'], site_id, device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end end devices end
ruby
def list_site_devices(site_id = nil) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id })) devices = [] if r.success r.res.elements.each('SiteDeviceListingResponse/SiteDevices') do |site| site_id = site.attributes['site-id'].to_i site.elements.each('device') do |device| devices << Device.new(device.attributes['id'].to_i, device.attributes['address'], site_id, device.attributes['riskfactor'].to_f, device.attributes['riskscore'].to_f) end end end devices end
[ "def", "list_site_devices", "(", "site_id", "=", "nil", ")", "r", "=", "execute", "(", "make_xml", "(", "'SiteDeviceListingRequest'", ",", "{", "'site-id'", "=>", "site_id", "}", ")", ")", "devices", "=", "[", "]", "if", "r", ".", "success", "r", ".", "res", ".", "elements", ".", "each", "(", "'SiteDeviceListingResponse/SiteDevices'", ")", "do", "|", "site", "|", "site_id", "=", "site", ".", "attributes", "[", "'site-id'", "]", ".", "to_i", "site", ".", "elements", ".", "each", "(", "'device'", ")", "do", "|", "device", "|", "devices", "<<", "Device", ".", "new", "(", "device", ".", "attributes", "[", "'id'", "]", ".", "to_i", ",", "device", ".", "attributes", "[", "'address'", "]", ",", "site_id", ",", "device", ".", "attributes", "[", "'riskfactor'", "]", ".", "to_f", ",", "device", ".", "attributes", "[", "'riskscore'", "]", ".", "to_f", ")", "end", "end", "end", "devices", "end" ]
Retrieve a list of all of the assets in a site. If no site-id is specified, then return all of the assets for the Nexpose console, grouped by site-id. @param [FixNum] site_id Site ID to request device listing for. Optional. @return [Array[Device]] Array of devices associated with the site, or all devices on the console if no site is provided.
[ "Retrieve", "a", "list", "of", "all", "of", "the", "assets", "in", "a", "site", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L43-L60
train
rapid7/nexpose-client
lib/nexpose/device.rb
Nexpose.Connection.group_assets
def group_assets(group_id) payload = { 'sort' => 'assetName', 'table-id' => 'group-assets', 'groupID' => group_id } results = DataTable._get_json_table(self, '/data/asset/group', payload) results.map { |a| FilteredAsset.new(a) } end
ruby
def group_assets(group_id) payload = { 'sort' => 'assetName', 'table-id' => 'group-assets', 'groupID' => group_id } results = DataTable._get_json_table(self, '/data/asset/group', payload) results.map { |a| FilteredAsset.new(a) } end
[ "def", "group_assets", "(", "group_id", ")", "payload", "=", "{", "'sort'", "=>", "'assetName'", ",", "'table-id'", "=>", "'group-assets'", ",", "'groupID'", "=>", "group_id", "}", "results", "=", "DataTable", ".", "_get_json_table", "(", "self", ",", "'/data/asset/group'", ",", "payload", ")", "results", ".", "map", "{", "|", "a", "|", "FilteredAsset", ".", "new", "(", "a", ")", "}", "end" ]
Get a list of all assets currently associated with a group. @param [Fixnum] group_id Unique identifier of an asset group. @return [Array[FilteredAsset]] List of group assets.
[ "Get", "a", "list", "of", "all", "assets", "currently", "associated", "with", "a", "group", "." ]
933fc8c0c85ba11d3e17db1d7f4542816f400d71
https://github.com/rapid7/nexpose-client/blob/933fc8c0c85ba11d3e17db1d7f4542816f400d71/lib/nexpose/device.rb#L72-L78
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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 && [email protected]? 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 && [email protected]? 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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train
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
train