esp_sdk 2.1.0 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eec3d492b1abf2d98d6bbf35c1f88a90c5e2b602
4
- data.tar.gz: f51d254cdef908e29b311ac812cf2654e14e1b8a
3
+ metadata.gz: 8ba33c6b2844803fe17abc39fd0f2ecfdd3c86c3
4
+ data.tar.gz: a9f51f6b6e0abd70064f0de21ea5b365b69b2acf
5
5
  SHA512:
6
- metadata.gz: 7edfbd88ee1b306daba55f035da060d5b63eb22c4a3d37d7bc09f6d95b20c510df7756edb8b74f5f18ba1325bbc62929052e4486fb3db26304c3aceba0633981
7
- data.tar.gz: 1ba56c34e806fe32835db2dc32339d3802f3b830ea3dd9021e470ceab3a223a063107fa8566ec1658883d4d4dd2759be3be3f902982f91d7148c55aea797b69c
6
+ metadata.gz: 15e6201640405e7dd7031147e38ff2342da257eba8ef8fd1d7a6e556f0eaf5c740c6953a2ab67522135e5cdbf57b6deed910551c302b325543d80890a3972b7b
7
+ data.tar.gz: 76c3758314ca2ff6121c25305fcb8151197293a3093dd115f9b13eca919b838e995b1027fee46678b5c6ea9f196c25f0115efbdf7b5f83110f7108ac2cd24dbd
data/CHANGELOG.md CHANGED
@@ -1,4 +1,8 @@
1
- ## 2.1.0 - 2015-01-15
1
+ ## 2.2.0 - 2016-03-2
2
+ ### Added
3
+ - Added the ESP::ScanInterval object to use the new scan interval endpoint on the API
4
+
5
+ ## 2.1.0 - 2016-02-10
2
6
  ### Added
3
7
  - Implemented searching using `where` on many object.
4
8
  - Add external account script. Run with `esp a`
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- esp_sdk (2.1.0)
4
+ esp_sdk (2.2.0)
5
5
  activeresource (~> 4.0.0)
6
6
  api-auth
7
7
  rack
data/README.md CHANGED
@@ -206,7 +206,7 @@ The methods with a `!` suffix update the object, methods without the `!` suffix
206
206
  original object.
207
207
 
208
208
  ```ruby
209
- espsdk:004:0> alerts = ESP::Alert.for_report(345)
209
+ espsdk:004:0> alerts = ESP::Alert.where(report_id: 345)
210
210
  espsdk:004:0> alerts.current_page_number # => "1"
211
211
  espsdk:004:0> page2 = alerts.next_page
212
212
  espsdk:004:0> alerts.current_page_number # => "1"
@@ -279,15 +279,6 @@ ESP::Signature.where(name_cont: 'dns')
279
279
  #=> will return signatures `where name LIKE '%dns%'`
280
280
  ```
281
281
 
282
- ### OR Conditions
283
-
284
- You can also combine predicates for OR queries:
285
-
286
- ```ruby
287
- ESP::Signature.where(name_or_description_cont: 'dns')
288
- #=> will return signatures `where name LIKE '%dns%' or description LIKE '%dns%'`
289
- ```
290
-
291
282
  ### Conditions on Relationships
292
283
 
293
284
  The syntax for queries on an associated relationship is to just append the association name to the attribute:
@@ -459,7 +450,7 @@ ESP::Signature.where(identifier_null: 1)
459
450
  Lists can also be sorted by adding the `sorts` parameter with the field to sort by to the `filter` parameter.
460
451
 
461
452
  ```ruby
462
- ESP::Signature.where(name_cont: 'dns', sort: 'risk_level desc')
453
+ ESP::Signature.where(name_cont: 'dns', sorts: 'risk_level desc')
463
454
  #=> will return signatures `where name LIKE '%dns%'` sorted by `risk_level` in descending order.
464
455
  ```
465
456
 
@@ -24,6 +24,16 @@ module ESP
24
24
  super
25
25
  end
26
26
 
27
+ # Returns a collection of scan_intervals for the external account
28
+ #
29
+ # ==== Example
30
+ #
31
+ # external_account = ESP::ExternalAccount.find(345)
32
+ # scan_intervals = external_account.scan_intervals
33
+ def scan_intervals
34
+ ESP::ScanInterval.for_external_account(id)
35
+ end
36
+
27
37
  # :singleton-method: where
28
38
  # Return a paginated ExternalAccount list filtered by search parameters
29
39
  #
@@ -0,0 +1,46 @@
1
+ module ESP
2
+ class ScanInterval < ESP::Resource
3
+ ##
4
+ # The external account the scan interval belongs to
5
+ belongs_to :external_account, class_name: 'ESP::ExternalAccount'
6
+
7
+ ##
8
+ # The service the scan interval belongs to
9
+ belongs_to :service, class_name: 'ESP::Service'
10
+
11
+ # Find a Scan Interval by id
12
+ #
13
+ # ==== Parameter
14
+ #
15
+ # +id+ | Required | The ID of the scan interval to retrieve
16
+ #
17
+ # :call-seq:
18
+ # find(id)
19
+ def self.find(*arguments)
20
+ scope = arguments.slice!(0)
21
+ options = (arguments.slice!(0) || {}).with_indifferent_access
22
+ # If the first option is a number, we are looking for a specific object.
23
+ # Otherwise `all` calls this with either nil, or a hash of arguments, and we need
24
+ # to use our custom finder to use the correct URL
25
+ return super(scope, options) if scope.is_a?(Numeric) || options[:from].present?
26
+ params = options.fetch(:params, {}).with_indifferent_access
27
+ external_account_id = params.delete(:external_account_id)
28
+ for_external_account(external_account_id)
29
+ end
30
+
31
+ # Returns a collection of scan_intervals for the given external_account_id
32
+ # Convenience method to use instead of ::find since a external_account_id is required to return alerts.
33
+ #
34
+ # ==== Parameters
35
+ #
36
+ # +external_account_id+ | Required | The ID of the external account to retrieve scan intervals for
37
+ #
38
+ # ==== Example
39
+ # alerts = ESP::ScanInterval.for_external_account(54)
40
+ def self.for_external_account(external_account_id = nil)
41
+ fail ArgumentError, "You must supply an external account id." unless external_account_id.present?
42
+ from = "#{prefix}external_accounts/#{external_account_id}/scan_intervals.json"
43
+ all(from: from)
44
+ end
45
+ end
46
+ end
data/lib/esp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module ESP
2
- VERSION = '2.1.0'
2
+ VERSION = '2.2.0'
3
3
  end
data/lib/esp.rb CHANGED
@@ -92,6 +92,7 @@ module ESP
92
92
  autoload :User, File.expand_path(File.dirname(__FILE__) + '/esp/resources/user')
93
93
  autoload :Signature, File.expand_path(File.dirname(__FILE__) + '/esp/resources/signature')
94
94
  autoload :CustomSignature, File.expand_path(File.dirname(__FILE__) + '/esp/resources/custom_signature')
95
+ autoload :ScanInterval, File.expand_path(File.dirname(__FILE__) + '/esp/resources/scan_interval')
95
96
  autoload :Service, File.expand_path(File.dirname(__FILE__) + '/esp/resources/service')
96
97
  autoload :Alert, File.expand_path(File.dirname(__FILE__) + '/esp/resources/alert')
97
98
  autoload :RawAlert, File.expand_path(File.dirname(__FILE__) + '/esp/resources/raw_alert')
@@ -36,6 +36,17 @@ module ESP
36
36
  end
37
37
  end
38
38
 
39
+ context '#scan_intervals' do
40
+ should 'call the api for the external_account and the passed in params' do
41
+ external_account = build(:external_account)
42
+ stub_request(:get, %r{external_accounts/#{external_account.id}/scan_intervals.json*}).to_return(body: json_list(:scan_interval, 2))
43
+
44
+ external_account.scan_intervals
45
+
46
+ assert_requested(:get, %r{external_accounts/#{external_account.id}/scan_intervals.json*})
47
+ end
48
+ end
49
+
39
50
  context '#create' do
40
51
  should "use the external_id in the params if supplied" do
41
52
  stub_request(:post, /external_accounts.json*/).to_return(body: json(:external_account))
@@ -0,0 +1,124 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../test_helper')
2
+
3
+ module ESP
4
+ class ScanIntervalTest < ActiveSupport::TestCase
5
+ context ESP::ScanInterval do
6
+ context '#external_account' do
7
+ should 'call the api' do
8
+ scan_interval = build(:scan_interval, external_account_id: 4)
9
+ stub_account = stub_request(:get, %r{external_accounts/#{scan_interval.external_account_id}.json*}).to_return(body: json(:external_account))
10
+
11
+ scan_interval.external_account
12
+
13
+ assert_requested(stub_account)
14
+ end
15
+ end
16
+
17
+ context '#service' do
18
+ should 'call the api' do
19
+ scan_interval = build(:scan_interval, service_id: 4)
20
+ stub_service = stub_request(:get, %r{services/#{scan_interval.service_id}.json*}).to_return(body: json(:service))
21
+
22
+ scan_interval.service
23
+
24
+ assert_requested(stub_service)
25
+ end
26
+ end
27
+
28
+ context '.for_external_account' do
29
+ should 'throw an error if report_id is not supplied' do
30
+ error = assert_raises ArgumentError do
31
+ ESP::ScanInterval.for_external_account
32
+ end
33
+ assert_equal 'You must supply an external account id.', error.message
34
+ end
35
+
36
+ should 'call the api and pass params' do
37
+ stub_request(:get, %r{external_accounts/5/scan_intervals.json*}).to_return(body: json_list(:scan_interval, 2))
38
+
39
+ intervals = ESP::ScanInterval.for_external_account(5)
40
+
41
+ assert_requested(:get, %r{external_accounts/5/scan_intervals.json*})
42
+ assert_equal ESP::ScanInterval, intervals.resource_class
43
+ end
44
+ end
45
+
46
+ context '.find' do
47
+ should 'throw an error if external_account_id is not supplied' do
48
+ error = assert_raises ArgumentError do
49
+ ESP::ScanInterval.find(:all, params: { id: 3 })
50
+ end
51
+ assert_equal 'You must supply an external account id.', error.message
52
+ end
53
+
54
+ should 'call the show api and return an alert if searching by id' do
55
+ stub_scan_interval = stub_request(:get, %r{scan_intervals/5.json*}).to_return(body: json(:scan_interval))
56
+
57
+ scan_interval = ESP::ScanInterval.find(5)
58
+
59
+ assert_requested(stub_scan_interval)
60
+ assert_equal ESP::ScanInterval, scan_interval.class
61
+ end
62
+
63
+ should 'call the api and return scan_intervals when external_account_id is supplied' do
64
+ stub_scan_interval = stub_request(:get, %r{external_accounts/5/scan_intervals.json*}).to_return(body: json_list(:scan_interval, 2))
65
+
66
+ scan_interval = ESP::ScanInterval.find(:all, params: { external_account_id: 5 })
67
+
68
+ assert_requested(stub_scan_interval)
69
+ assert_equal ESP::ScanInterval, scan_interval.resource_class
70
+ end
71
+ end
72
+
73
+ context 'live calls' do
74
+ setup do
75
+ skip "Make sure you run the live calls locally to ensure proper integration" if ENV['CI_SERVER']
76
+ WebMock.allow_net_connect!
77
+ @external_account = ESP::ExternalAccount.last
78
+ @service = ESP::Service.last
79
+ skip "Live DB does not have any external_accounts. Add an external_account and run tests again." if @external_account.blank?
80
+ skip "Live DB does not have any services. Add an service and run tests again." if @service.blank?
81
+ end
82
+
83
+ teardown do
84
+ # destroy record incase of failure
85
+ @scan_interval.destroy rescue nil # rubocop:disable Style/RescueModifier
86
+ WebMock.disable_net_connect!
87
+ end
88
+
89
+ context '#CRUD' do
90
+ should 'be able to create, update and destroy' do
91
+ @scan_interval = ESP::ScanInterval.new(interval: 15, service_id: @service.id, external_account_id: @external_account.id)
92
+
93
+ # Create
94
+ assert_predicate @scan_interval, :new?
95
+ @scan_interval.save
96
+ refute_predicate @scan_interval, :new?
97
+
98
+ # Update
99
+ @scan_interval.interval = 30
100
+ @scan_interval.save
101
+ assert_nothing_raised do
102
+ ESP::ScanInterval.find(@scan_interval.id.to_i)
103
+ end
104
+
105
+ # Service Relationship
106
+ service = @scan_interval.service
107
+ assert_equal service.id, @service.id
108
+
109
+ # External Account Relationship
110
+ external_account = @scan_interval.external_account
111
+ assert_equal external_account.id, @external_account.id
112
+
113
+ # Destroy
114
+ @scan_interval.destroy
115
+
116
+ assert_raises ActiveResource::ResourceNotFound do
117
+ ESP::ScanInterval.find(@scan_interval.id.to_i)
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,32 @@
1
+ FactoryGirl.define do
2
+ factory :scan_interval, class: 'ESP::ScanInterval' do
3
+ skip_create
4
+
5
+ sequence(:id) { |n| n }
6
+ type "scan_intervals"
7
+ interval 15
8
+ created_at { Time.current }
9
+ updated_at { Time.current }
10
+ relationships do
11
+ { external_account: {
12
+ data: {
13
+ type: "external_accounts",
14
+ id: "1"
15
+ },
16
+ links: {
17
+ related: "http://localhost:3000/api/v2/external_accounts/1.json"
18
+ }
19
+ },
20
+ service: {
21
+ data: {
22
+ type: "services",
23
+ id: "1"
24
+ },
25
+ links: {
26
+ related: "http://localhost:3000/api/v2/services/1.json"
27
+ }
28
+ }
29
+ }
30
+ end
31
+ end
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: esp_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evident.io
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-10 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -337,6 +337,7 @@ files:
337
337
  - lib/esp/resources/region.rb
338
338
  - lib/esp/resources/report.rb
339
339
  - lib/esp/resources/resource.rb
340
+ - lib/esp/resources/scan_interval.rb
340
341
  - lib/esp/resources/service.rb
341
342
  - lib/esp/resources/signature.rb
342
343
  - lib/esp/resources/stat.rb
@@ -372,6 +373,7 @@ files:
372
373
  - test/esp/resources/region_test.rb
373
374
  - test/esp/resources/report_test.rb
374
375
  - test/esp/resources/resource_test.rb
376
+ - test/esp/resources/scan_interval_test.rb
375
377
  - test/esp/resources/service_test.rb
376
378
  - test/esp/resources/signature_test.rb
377
379
  - test/esp/resources/stat_custom_signature_test.rb
@@ -399,6 +401,7 @@ files:
399
401
  - test/factories/organizations.rb
400
402
  - test/factories/regions.rb
401
403
  - test/factories/reports.rb
404
+ - test/factories/scan_intervals.rb
402
405
  - test/factories/services.rb
403
406
  - test/factories/signatures.rb
404
407
  - test/factories/stat_custom_signatures.rb
@@ -457,6 +460,7 @@ test_files:
457
460
  - test/esp/resources/region_test.rb
458
461
  - test/esp/resources/report_test.rb
459
462
  - test/esp/resources/resource_test.rb
463
+ - test/esp/resources/scan_interval_test.rb
460
464
  - test/esp/resources/service_test.rb
461
465
  - test/esp/resources/signature_test.rb
462
466
  - test/esp/resources/stat_custom_signature_test.rb
@@ -484,6 +488,7 @@ test_files:
484
488
  - test/factories/organizations.rb
485
489
  - test/factories/regions.rb
486
490
  - test/factories/reports.rb
491
+ - test/factories/scan_intervals.rb
487
492
  - test/factories/services.rb
488
493
  - test/factories/signatures.rb
489
494
  - test/factories/stat_custom_signatures.rb