sonar-client 0.1.1 → 0.1.2

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: 6439efe4c0387e7b4fd2bea9cade77e0abe674f0
4
- data.tar.gz: 1221b6ed4df40d9f5a10ec3678fc6f00390f66f3
3
+ metadata.gz: 820db139f2824907be22a0f34c228fa5d9175f33
4
+ data.tar.gz: 5d3f107c6d8e627891c4de9e3b2e4886dcb19d8e
5
5
  SHA512:
6
- metadata.gz: 6640801e46ab2c8f2982278cd3d8fb9e6f5a58fcce398712d2e0b9e3a514a82f5e58efbdf6aef86e9ae1395307fd4098da13bb142166269f8d034ef25cda255f
7
- data.tar.gz: ac9d274760ba75c9c8b720ba78bc7ae644f568528b59302132302a951cf92240b5f5736d7ee5a86b6f629acf5f7ec3197d7c09d770f91016c02c567ee66fb06b
6
+ metadata.gz: d1ceabcd6de7dfbf8e8d985413ed05e3c873a4e94df64ef3be6ffbb01330a6f455df8f9104c7b4b165b8d7cbad591ac518f7ea4f84465a48cf9f87531dd43f5b
7
+ data.tar.gz: d3b32283cb878fbad817379ce73d3ecf520701295a133c755d3c5c0adfa5731b4d484369f411b36e663083d53e517c94b57bddd3e0e30be83eb8827ca1447128
data/bin/sonar CHANGED
@@ -5,7 +5,7 @@ require 'bundler/setup'
5
5
  require 'sonar'
6
6
 
7
7
  begin
8
- Sonar::CLI.start(ARGV)
8
+ exit(Sonar::CLI.start(ARGV))
9
9
  rescue Interrupt
10
10
  puts 'Quitting...'
11
11
  end
@@ -35,13 +35,18 @@ module Sonar
35
35
  @query[:exact] = options['exact']
36
36
  resp = @client.search(@query)
37
37
 
38
+ errors = 0
38
39
  if resp.is_a?(Sonar::Request::RequestIterator)
39
40
  resp.each do |data|
41
+ errors += 1 if data.key?('errors') || data.key?('error')
40
42
  print_json(cleanup_data(data), options['format'])
41
43
  end
42
44
  else
45
+ errors += 1 if resp.key?('errors') || resp.key?('error')
43
46
  print_json(cleanup_data(resp), options['format'])
44
47
  end
48
+
49
+ return errors
45
50
  end
46
51
 
47
52
  desc 'types', 'List all Sonar query types'
@@ -1,3 +1,3 @@
1
1
  module Sonar
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -7,9 +7,13 @@ describe Sonar::CLI do
7
7
  Sonar::RCFile.instance.path = "#{fixtures_path}/sonar-stock.rc"
8
8
  end
9
9
  it 'warns user of missing config values when trying to search' do
10
- output = run_command('search rdns 8.8.8.8')
10
+ output, _ = run_command('search rdns 8.8.8.8')
11
11
  expect(output).to match(/Could not authenticate/)
12
12
  end
13
+ it 'exits non-zero when errors are encountered' do
14
+ _, ret = run_command('search rdns 8.8.8.8')
15
+ expect(ret).to eq(1)
16
+ end
13
17
  end
14
18
 
15
19
  context "with a valid profile" do
@@ -17,7 +21,7 @@ describe Sonar::CLI do
17
21
  Sonar::RCFile.instance.path = "#{fixtures_path}/sonar.rc"
18
22
  end
19
23
  it "should return the profile" do
20
- output = run_command('profile')
24
+ output, _ = run_command('profile')
21
25
  expect(output).to match(/email@asdfasdfasfd.com/)
22
26
  end
23
27
 
@@ -28,11 +32,11 @@ describe Sonar::CLI do
28
32
  )
29
33
  end
30
34
  it 'strips whitespace from values' do
31
- output = run_command('search rdns 8.8.8.8')
35
+ output, _ = run_command('search rdns 8.8.8.8')
32
36
  expect(output).to eq('{"collection":[{"address":"192.168.1.1"}],"more":"false"}')
33
37
  end
34
38
  it 'can return lines format' do
35
- output = run_command('search --format lines rdns 8.8.8.8')
39
+ output, _ = run_command('search --format lines rdns 8.8.8.8')
36
40
  expect(output).to eq('{"address":"192.168.1.1"}')
37
41
  end
38
42
  end
@@ -43,7 +47,7 @@ describe Sonar::CLI do
43
47
  )
44
48
  end
45
49
  it 'parses the nested values in an array' do
46
- output = run_command('search sslcert 152a0a633aaf13f02c428ac1a3e672e895512bfd')
50
+ output, _ = run_command('search sslcert 152a0a633aaf13f02c428ac1a3e672e895512bfd')
47
51
  expect(JSON.parse(output)['collection'].first['details'].first['subject']['ST']).to eq('California')
48
52
  end
49
53
  end
@@ -54,7 +58,7 @@ describe Sonar::CLI do
54
58
  )
55
59
  end
56
60
  xit 'parses the nested value as a string' do
57
- output = run_command('search processed 8.8.8.')
61
+ output, _ = run_command('search processed 8.8.8.')
58
62
  expect(JSON.parse(output)['collection'].first['value']['ip']).to eq('8.8.8.8')
59
63
  end
60
64
  end
@@ -66,7 +70,7 @@ describe Sonar::CLI do
66
70
  )
67
71
  end
68
72
  it 'matches exactly with --exact' do
69
- output = run_command('search fdns 208.118.227.20 --exact')
73
+ output, _ = run_command('search fdns 208.118.227.20 --exact')
70
74
  expect(JSON.parse(output)['collection'].size).to be >= 1
71
75
  expect(JSON.parse(output)['collection'].any? { |c| c['name'] == '208.118.227.20' }).to be(true)
72
76
  end
@@ -78,7 +82,7 @@ describe Sonar::CLI do
78
82
  )
79
83
  end
80
84
  it 'matches exactly without --exact' do
81
- output = run_command('search fdns 208.118.227.20')
85
+ output, _ = run_command('search fdns 208.118.227.20')
82
86
  expect(JSON.parse(output)['collection'].size).to be > 1
83
87
  end
84
88
  end
@@ -86,6 +90,8 @@ describe Sonar::CLI do
86
90
  end
87
91
 
88
92
  def run_command(args)
89
- capture(:stdout) { Sonar::CLI.start(args.split) }.strip
93
+ ret = 0
94
+ output, _ = capture(:stdout) { ret = Sonar::CLI.start(args.split) }.strip
95
+ [output, ret]
90
96
  end
91
97
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sonar-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Deardorff & HD Moore
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday_middleware