Class: IntrigueApi
- Inherits:
-
Object
- Object
- IntrigueApi
- Defined in:
- lib/intrigue_api_client.rb
Instance Method Summary collapse
- #_get_json_result(path) ⇒ Object
- #get_log(task_id) ⇒ Object
- #get_result(task_id) ⇒ Object
-
#info(task_name) ⇒ Object
Show detailed about a task.
-
#initialize(uri, key = "") ⇒ IntrigueApi
constructor
A new instance of IntrigueApi.
-
#list ⇒ Object
List all tasks.
-
#start(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
Start a task and wait for the result.
-
#start_and_background(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_and_background - start and background a task.
-
#start_scan_and_background(project_name, scan_type, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_scan_and_background - start and background a scan.
Constructor Details
#initialize(uri, key = "") ⇒ IntrigueApi
Returns a new instance of IntrigueApi.
7 8 9 10 |
# File 'lib/intrigue_api_client.rb', line 7 def initialize(uri,key="") @intrigue_basedir = File.dirname(__FILE__) @server_uri = uri end |
Instance Method Details
#_get_json_result(path) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/intrigue_api_client.rb', line 121 def _get_json_result(path) begin JSON.parse(RestClient.get "#{@server_uri}/#{path}") rescue JSON::ParserError => e puts "Error: #{e}" rescue RestClient::InternalServerError => e puts "Error: #{e}" end end |
#get_log(task_id) ⇒ Object
108 109 110 |
# File 'lib/intrigue_api_client.rb', line 108 def get_log(task_id) log = _get_json_result "#{project_name}/task_results/#{task_id}/log" end |
#get_result(task_id) ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/intrigue_api_client.rb', line 112 def get_result(task_id) begin result = _get_json_result "#{project_name}/task_results/#{task_id}.json" rescue JSON::ParserError => e response = nil end result end |
#info(task_name) ⇒ Object
Show detailed about a task
18 19 20 |
# File 'lib/intrigue_api_client.rb', line 18 def info(task_name) _get_json_result "#{@server_uri}/tasks/#{task_name}.json" end |
#list ⇒ Object
List all tasks
13 14 15 |
# File 'lib/intrigue_api_client.rb', line 13 def list _get_json_result "tasks.json" end |
#start(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
Start a task and wait for the result
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/intrigue_api_client.rb', line 56 def start(project_name,task_name,entity_hash,=nil,handler_list=nil) # Construct the request task_id = start_and_background(project_name,task_name,entity_hash,,handler_list) if task_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" return nil end ### XXX - wait to collect the response complete = false until complete sleep 1 begin response = RestClient.get "#{@server_uri}/#{project_name}/task_results/#{task_id}/complete" complete = true if response == "true" rescue URI::InvalidURIError => e puts "[-] Invalid URI: #{uri}" return end end ### Get the response response = _get_json_result "#{project_name}/task_results/#{task_id}.json" response end |
#start_and_background(project_name, task_name, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_and_background - start and background a task
project_name - must exist as a valid project_name task_name - must exist as a valid task name entity_hash - symbol-based hash representing an entity:
:type => "String"
:attributes => { :name => "intrigue.io"
} options_list - list of options: [
{:name => "resolver", :value => "8.8.8.8" }
]
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/intrigue_api_client.rb', line 33 def start_and_background(project_name,task_name,entity_hash,=nil,handler_list=nil) payload = { "project_name" => project_name, "task" => task_name, "options" => , "handlers" => handler_list, "entity" => entity_hash } ### Send to the server task_id = RestClient.post "#{@server_uri}/#{project_name}/task_results", payload.to_json, :content_type => "application/json" if task_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" return nil end task_id end |
#start_scan_and_background(project_name, scan_type, entity_hash, options_list = nil, handler_list = nil) ⇒ Object
start_scan_and_background - start and background a scan
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/intrigue_api_client.rb', line 86 def start_scan_and_background(project_name,scan_type,entity_hash,=nil,handler_list=nil) payload = { "project_name" => project_name, "scan_type" => scan_type, "options" => , "entity" => entity_hash, "handlers" => handler_list } ### Send to the server scan_id = RestClient.post "#{@server_uri}/#{project_name}/scan_results", payload.to_json, :content_type => "application/json" if scan_id == "" # technically a nil is returned , but becomes an empty string return nil end scan_id end |