class IntrigueApi
Public Class Methods
new(uri="http://127.0.0.1:7777/v1",key="")
click to toggle source
# File lib/intrigue_api_client.rb, line 11 def initialize(uri="http://127.0.0.1:7777/v1",key="") @intrigue_basedir = File.dirname(__FILE__) @server_uri = uri end
version()
click to toggle source
# File lib/intrigue_api_client.rb, line 7 def self.version "1.2.4" end
Public Instance Methods
background(project_name,task_name,entity_hash,depth=1,options_list=nil,handler_list=nil, strategy_name=nil, auto_enrich=true)
click to toggle source
# File lib/intrigue_api_client.rb, line 31 def background(project_name,task_name,entity_hash,depth=1,options_list=nil,handler_list=nil, strategy_name=nil, auto_enrich=true) # Construct the request task_id = _start_and_background(project_name,task_name,entity_hash,depth,options_list,handler_list, strategy_name, auto_enrich) end
create_project(project_name)
click to toggle source
create a new project
# File lib/intrigue_api_client.rb, line 27 def create_project(project_name) RestClient.post "#{@server_uri}/project", { "project" => project_name } end
info(task_name)
click to toggle source
Show detailed about a task
# File lib/intrigue_api_client.rb, line 22 def info(task_name) _get_json_result "tasks/#{task_name}.json" end
list()
click to toggle source
List all tasks
# File lib/intrigue_api_client.rb, line 17 def list _get_json_result "tasks.json" end
start(project_name,task_name,entity_hash,depth=1,options_list=nil,handler_list=nil, strategy_name=nil, auto_enrich=true)
click to toggle source
Start a task and wait for the result
# File lib/intrigue_api_client.rb, line 38 def start(project_name,task_name,entity_hash,depth=1,options_list=nil,handler_list=nil, strategy_name=nil, auto_enrich=true) # Construct the request task_id = _start_and_background(project_name,task_name,entity_hash,depth,options_list,handler_list, strategy_name, auto_enrich) if task_id == "" # technically a nil is returned , but becomes an empty string #puts "[-] Task not started. Unknown Error. Exiting" raise "Problem getting result" return nil else #puts "[+] Got Task ID: #{task_id}" end ### XXX - wait to collect the response complete = false until complete sleep 1 begin check_uri = "#{@server_uri}/#{project_name}/results/#{task_id}/complete" #puts "[+] Checking: #{check_uri}" response = RestClient.get check_uri complete = true if response == "true" #return nil if response == "" rescue URI::InvalidURIError => e #puts "[-] Invalid URI: #{check_uri}" return nil end end ### Get the response response = _get_json_result "#{project_name}/results/#{task_id}.json" response end
Private Instance Methods
_get_json_result(path)
click to toggle source
# File lib/intrigue_api_client.rb, line 127 def _get_json_result(path) begin result = JSON.parse(RestClient.get "#{@server_uri}/#{path}") rescue JSON::ParserError => e #puts "Error: #{e}" rescue RestClient::InternalServerError => e #puts "Error: #{e}" end result end
_get_log(task_id)
click to toggle source
# File lib/intrigue_api_client.rb, line 114 def _get_log(task_id) log = _get_json_result "#{project_name}/results/#{task_id}/log" end
_get_result(task_id)
click to toggle source
# File lib/intrigue_api_client.rb, line 118 def _get_result(task_id) begin result = _get_json_result "#{project_name}/results/#{task_id}.json" rescue JSON::ParserError => e response = nil end result end
_start_and_background(project_name,task_name,entity_hash,depth,options_list,handler_list, strategy_name, auto_enrich)
click to toggle source
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" }
]
# File lib/intrigue_api_client.rb, line 88 def _start_and_background(project_name,task_name,entity_hash,depth,options_list,handler_list, strategy_name, auto_enrich) payload = { "project_name" => project_name, "task" => task_name, "options" => options_list, "handlers" => handler_list, "entity" => entity_hash, "depth" => depth, "strategy_name" => strategy_name, "auto_enrich" => auto_enrich } ### Send to the server task_id = RestClient.post "#{@server_uri}/#{project_name}/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" #raise "Problem getting result" return nil end task_id end