intrigue_api_client 1.0.1 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/intrigue_api_client.rb +26 -37
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f76b53c88f4271cda1f176a5117a3e7368e2441d
4
- data.tar.gz: a100ef2677cc519610ac2e6b323b862bdd7f86f4
3
+ metadata.gz: 7584cd1b0f64137d233048a2417c114608108778
4
+ data.tar.gz: 5120734394133b63b0d78993c124aadac04677ef
5
5
  SHA512:
6
- metadata.gz: e7ef5b0786e8c6931562ca74b5dd600a4406ea6d5115dbbe7bf08b0aaa2e5e15ee9f21ef500eff9b9edf6b86418a6cdf51255b59babb6a604fe85d8493d21746
7
- data.tar.gz: 669d9ba0b1bb52e981e6f36ed5c73103cd4dc54552367ab915725c87799a85c03a2b9b2d75c3fe9e5531b49fab0123109293879bc2351d37e99927e8838c15b6
6
+ metadata.gz: 258cae10730ec552a67c32960bcf9bcd25eb783ec6d758e3fb66b448a50d895b5f96ef34d341376639841a4a7e45a9f04c1232620070a8f78cd261bb7a37169a
7
+ data.tar.gz: c6914d3271b78359b6bb4ecb873e37dcbce30cf99a201fccffdba5e79592d1d31c8fe365af7f0d4c138c2a933a7acafd4c419601609a382579b1efe35e5e8be9
@@ -6,33 +6,28 @@ class IntrigueApi
6
6
 
7
7
  def initialize(uri,key="")
8
8
  @intrigue_basedir = File.dirname(__FILE__)
9
- @server_uri = ENV.fetch("INTRIGUE_API", uri)
9
+ @server_uri = uri
10
10
  end
11
11
 
12
12
  # List all tasks
13
13
  def list
14
- tasks_hash = JSON.parse(RestClient.get("#{@server_uri}/tasks.json"))
14
+ _get_json_result "tasks.json"
15
15
  end
16
16
 
17
17
  # Show detailed about a task
18
18
  def info(task_name)
19
-
20
- begin
21
- task_info = JSON.parse(RestClient.get("#{@server_uri}/tasks/#{task_name}.json"))
22
- rescue RestClient::InternalServerError => e
23
- raise "Invalid Task Called"
24
- end
25
-
19
+ _get_json_result "#{@server_uri}/tasks/#{task_name}.json"
26
20
  end
27
21
 
28
22
  # start_and_background - start and background a task
29
23
  #
30
- # entity_hash = {
24
+ # project_name - must exist as a valid project_name
25
+ # task_name - must exist as a valid task name
26
+ # entity_hash - symbol-based hash representing an entity: {
31
27
  # :type => "String"
32
28
  # :attributes => { :name => "intrigue.io"}
33
29
  # }
34
- #
35
- # options_list = [
30
+ # options_list - list of options: [
36
31
  # {:name => "resolver", :value => "8.8.8.8" }
37
32
  # ]
38
33
  def start_and_background(project_name,task_name,entity_hash,options_list=nil,handler_list=nil)
@@ -46,7 +41,7 @@ class IntrigueApi
46
41
  }
47
42
 
48
43
  ### Send to the server
49
- task_id = RestClient.post "#{@server_uri}/task_results",
44
+ task_id = RestClient.post "#{@server_uri}/#{project_name}/task_results",
50
45
  payload.to_json, :content_type => "application/json"
51
46
 
52
47
  if task_id == "" # technically a nil is returned , but becomes an empty string
@@ -57,7 +52,7 @@ class IntrigueApi
57
52
  task_id
58
53
  end
59
54
 
60
- # start Start a task and wait for the result
55
+ # Start a task and wait for the result
61
56
  def start(project_name,task_name,entity_hash,options_list=nil,handler_list=nil)
62
57
 
63
58
  # Construct the request
@@ -71,10 +66,10 @@ class IntrigueApi
71
66
  ### XXX - wait to collect the response
72
67
  complete = false
73
68
  until complete
74
- sleep 3
69
+ sleep 1
75
70
  begin
76
- uri = "#{@server_uri}/task_results/#{task_id}/complete"
77
- complete = true if(RestClient.get(uri) == "true")
71
+ response = RestClient.get "#{@server_uri}/#{project_name}/task_results/#{task_id}/complete"
72
+ complete = true if response == "true"
78
73
  rescue URI::InvalidURIError => e
79
74
  puts "[-] Invalid URI: #{uri}"
80
75
  return
@@ -82,27 +77,12 @@ class IntrigueApi
82
77
  end
83
78
 
84
79
  ### Get the response
85
- begin
86
- response = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json")
87
- rescue JSON::ParserError => e
88
- #puts "Error parsing JSON: #{e}"
89
- #puts "response: #{response}"
90
- response = nil
91
- end
80
+ response = _get_json_result "#{project_name}/task_results/#{task_id}.json"
92
81
 
93
82
  response
94
83
  end
95
84
 
96
85
  # start_scan_and_background - start and background a scan
97
- #
98
- # entity_hash = {
99
- # :type => "String"
100
- # :details => { :name => "intrigue.io"}
101
- # }
102
- #
103
- # options_list = [
104
- # {:name => "resolver", :value => "8.8.8.8" }
105
- # ]
106
86
  def start_scan_and_background(project_name,scan_type,entity_hash,options_list=nil,handler_list=nil)
107
87
 
108
88
  payload = {
@@ -114,12 +94,11 @@ class IntrigueApi
114
94
  }
115
95
 
116
96
  ### Send to the server
117
- scan_id = RestClient.post "#{@server_uri}/scan_results",
97
+ scan_id = RestClient.post "#{@server_uri}/#{project_name}/scan_results",
118
98
  payload.to_json, :content_type => "application/json"
119
99
 
120
100
 
121
101
  if scan_id == "" # technically a nil is returned , but becomes an empty string
122
- #puts "[-] Task not started. Unknown Error. Exiting"
123
102
  return nil
124
103
  end
125
104
 
@@ -127,18 +106,28 @@ class IntrigueApi
127
106
  end
128
107
 
129
108
  def get_log(task_id)
130
- log = RestClient.get "#{@server_uri}/task_results/#{task_id}/log"
109
+ log = _get_json_result "#{project_name}/task_results/#{task_id}/log"
131
110
  end
132
111
 
133
112
  def get_result(task_id)
134
113
  begin
135
- result = JSON.parse(RestClient.get "#{@server_uri}/task_results/#{task_id}.json")
114
+ result = _get_json_result "#{project_name}/task_results/#{task_id}.json"
136
115
  rescue JSON::ParserError => e
137
116
  response = nil
138
117
  end
139
118
  result
140
119
  end
141
120
 
121
+ def _get_json_result(path)
122
+ begin
123
+ JSON.parse(RestClient.get "#{@server_uri}/#{path}")
124
+ rescue JSON::ParserError => e
125
+ puts "Error: #{e}"
126
+ rescue RestClient::InternalServerError => e
127
+ puts "Error: #{e}"
128
+ end
129
+ end
130
+
142
131
 
143
132
  end
144
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: intrigue_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - jcran