outliers 0.3.3 → 0.5.0.beta1

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 (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -1
  3. data/README.md +21 -17
  4. data/lib/outliers/{credentials.rb → account.rb} +4 -4
  5. data/lib/outliers/cli/process.rb +53 -15
  6. data/lib/outliers/cli.rb +1 -1
  7. data/lib/outliers/collection.rb +24 -18
  8. data/lib/outliers/evaluation.rb +60 -32
  9. data/lib/outliers/exceptions.rb +10 -1
  10. data/lib/outliers/filters/aws/ec2/tags.rb +2 -2
  11. data/lib/outliers/handlers/json.rb +36 -0
  12. data/lib/outliers/handlers/outliers_api.rb +62 -0
  13. data/lib/outliers/handlers.rb +1 -0
  14. data/lib/outliers/provider.rb +7 -7
  15. data/lib/outliers/resources/aws/ec2/instance.rb +1 -1
  16. data/lib/outliers/resources/aws/elb/load_balancer.rb +1 -1
  17. data/lib/outliers/resources/aws/rds/db_instance.rb +1 -1
  18. data/lib/outliers/resources/aws/s3/bucket_collection.rb +1 -1
  19. data/lib/outliers/result.rb +32 -8
  20. data/lib/outliers/run.rb +9 -3
  21. data/lib/outliers/verifications/shared.rb +2 -2
  22. data/lib/outliers/version.rb +1 -1
  23. data/lib/outliers.rb +2 -1
  24. data/outliers.gemspec +1 -1
  25. data/reference.yaml +10 -10
  26. data/shared.yaml +1 -1
  27. data/spec/{credentials_spec.rb → account_spec.rb} +7 -7
  28. data/spec/collection_spec.rb +48 -7
  29. data/spec/evaluation_spec.rb +109 -47
  30. data/spec/fixtures/{credentials1.yml → account1.yml} +1 -1
  31. data/spec/fixtures/{credentials2.yml → account2.yml} +1 -1
  32. data/spec/handlers/outliers_api_spec.rb +61 -0
  33. data/spec/info_spec.rb +2 -2
  34. data/spec/provider_spec.rb +9 -9
  35. data/spec/results_spec.rb +65 -16
  36. data/spec/run_spec.rb +4 -4
  37. data/spec/spec_helper.rb +3 -3
  38. data/spec/verifications/shared_spec.rb +3 -3
  39. metadata +18 -13
@@ -1,4 +1,4 @@
1
- test_credentials_2:
1
+ test_account_2:
2
2
  region: us-west-1
3
3
  provider: aws_ec2
4
4
  access_key_id: 01234567890123456789
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe Outliers::Handlers::OutliersApi do
4
+ let(:resource1) {stub 'resource1', id: 1}
5
+ let(:resource2) {stub 'resource2', id: 2}
6
+ let(:result) { Outliers::Result.new account_name: 'cnt',
7
+ failing_resources: [resource1],
8
+ name: 'evalme',
9
+ passing_resources: [resource2],
10
+ provider_name: 'aws',
11
+ resource_name: 'instance',
12
+ verification_name: 'vpc' }
13
+ let(:header) {({ 'Content-Type' => 'application/json',
14
+ 'Accept' => 'application/vnd.outliers-v1+json' })}
15
+ let(:req) { mock 'req' }
16
+ let(:session) { mock 'session' }
17
+ let(:http) { mock 'http' }
18
+
19
+ before { stub_logger }
20
+
21
+ context "#post" do
22
+ before do
23
+ Net::HTTP::Post.should_receive(:new).with("/results", header).and_return req
24
+ body = { 'key' => "abc123", 'result' => result.to_hash }.to_json
25
+ req.should_receive(:body=).with(body)
26
+ Net::HTTP.should_receive(:new).with("api.getoutliers.com", 443).and_return session
27
+ session.should_receive(:use_ssl=).with true
28
+ end
29
+
30
+ context "when connection established" do
31
+ before do
32
+ session.should_receive(:start).and_yield http
33
+ http.should_receive(:request).with(req).and_return response
34
+ end
35
+
36
+ context "when successful" do
37
+ let(:response) { stub 'response', code: "200", body: "Some details." }
38
+
39
+ it "should return true" do
40
+ subject.post(result, "abc123", "https://api.getoutliers.com/results").should be_true
41
+ end
42
+ end
43
+
44
+ context "when failure" do
45
+ let(:response) { stub 'response', code: "500", body: "Some details." }
46
+
47
+ it "should return false" do
48
+ subject.post(result, "abc123", "https://api.getoutliers.com/results").should be_false
49
+ end
50
+ end
51
+ end
52
+
53
+ context "connection error" do
54
+ it "should return false if connection to url refused." do
55
+ session.should_receive(:start).and_raise Errno::ECONNREFUSED
56
+ subject.post(result, "abc123", "https://api.getoutliers.com/results").should be_false
57
+ end
58
+ end
59
+ end
60
+
61
+ end
data/spec/info_spec.rb CHANGED
@@ -33,9 +33,9 @@ describe Outliers::Info do
33
33
  end
34
34
  end
35
35
 
36
- it "should validate each resource has a list of credentials" do
36
+ it "should validate each resource has a list of account" do
37
37
  subject.reference.each_pair do |name,provider_data|
38
- expect(provider_data['credentials'].class).to eq(Hash)
38
+ expect(provider_data['account'].class).to eq(Hash)
39
39
  end
40
40
  end
41
41
  end
@@ -4,18 +4,18 @@ describe Outliers::Provider do
4
4
  subject { Outliers::Provider }
5
5
 
6
6
  context "#connect_to" do
7
- let(:credentials) { ( { :name => "test_credentials_1",
8
- "provider" => "aws_ec2",
9
- "secret_access_key" => "abc",
10
- "access_key_id" => "123" } ) }
7
+ let(:account) { ( { :name => "test_account_1",
8
+ "provider" => "aws_ec2",
9
+ "secret_access_key" => "abc",
10
+ "access_key_id" => "123" } ) }
11
11
 
12
- it "should connect to the provider specified in the given credentials" do
13
- expect(subject.connect_to(credentials).class).to eq(Outliers::Providers::Aws::Ec2)
12
+ it "should connect to the provider specified in the given account" do
13
+ expect(subject.connect_to(account).class).to eq(Outliers::Providers::Aws::Ec2)
14
14
  end
15
15
 
16
- it "should set the credentials instance variable" do
17
- expect(subject.connect_to(credentials).credentials).
18
- to eq({ :name => "test_credentials_1",
16
+ it "should set the account instance variable" do
17
+ expect(subject.connect_to(account).account).
18
+ to eq({ :name => "test_account_1",
19
19
  "provider" => "aws_ec2",
20
20
  "secret_access_key" => "abc",
21
21
  "access_key_id" => "123" })
data/spec/results_spec.rb CHANGED
@@ -1,16 +1,18 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Outliers::Result do
4
+ let(:resource1) {stub 'resource1', id: 1}
5
+ let(:resource2) {stub 'resource2', id: 2}
6
+
4
7
  context "passing" do
5
- subject { Outliers::Result.new evaluation: 'evalme',
8
+ subject { Outliers::Result.new account_name: 'cnt',
9
+ arguments: ['test123'],
6
10
  failing_resources: [],
7
- passing_resources: ['key1', 'key2'],
8
- resource: 'instance',
9
- verification: 'vpc' }
10
-
11
- it "should return passed" do
12
- expect(subject.to_s).to eq 'passed'
13
- end
11
+ name: 'evalme',
12
+ passing_resources: [resource1, resource2],
13
+ provider_name: 'aws',
14
+ resource_name: 'instance',
15
+ verification_name: 'vpc' }
14
16
 
15
17
  it "should return true for passing verification" do
16
18
  expect(subject.passed?).to be_true
@@ -21,19 +23,66 @@ describe Outliers::Result do
21
23
  end
22
24
 
23
25
  it "should return the result information" do
24
- expect(subject.passing_resources).to eq(['key1', 'key2'])
26
+ expect(subject.passing_resources).to eq([resource1, resource2])
27
+ end
28
+
29
+
30
+ it "should return the result information" do
31
+ expect(subject.account_name).to eq('cnt')
32
+ expect(subject.failing_resources).to eq([])
33
+ expect(subject.name).to eq('evalme')
34
+ expect(subject.passing_resources).to eq([resource1, resource2])
35
+ expect(subject.provider_name).to eq('aws')
36
+ expect(subject.resource_name).to eq('instance')
37
+ expect(subject.verification_name).to eq('vpc')
38
+ end
39
+
40
+ context "#name" do
41
+ subject { Outliers::Result.new({}) }
42
+
43
+ it "should set the name to unspecified if not set" do
44
+ expect(subject.name).to eq('unspecified')
45
+ end
46
+ end
47
+
48
+ context "#to_json" do
49
+ it "should return the results as json" do
50
+ resources = [ { 'id' => 1, 'passing' => 1 }, { 'id' => 2, 'passing' => 1 } ]
51
+ json = { 'account_name' => 'cnt',
52
+ 'arguments' => ['test123'],
53
+ 'name' => 'evalme',
54
+ 'provider_name' => 'aws',
55
+ 'resource_name' => 'instance',
56
+ 'verification_name' => 'vpc',
57
+ 'resources' => resources }.to_json
58
+ expect(subject.to_json).to eq(json)
59
+ end
60
+ end
61
+
62
+ context "#to_hash" do
63
+ it "should return the results as hash" do
64
+ resources = [ { 'id' => 1, 'passing' => 1 }, { 'id' => 2, 'passing' => 1 } ]
65
+ hash = { 'account_name' => 'cnt',
66
+ 'arguments' => ['test123'],
67
+ 'name' => 'evalme',
68
+ 'provider_name' => 'aws',
69
+ 'resource_name' => 'instance',
70
+ 'verification_name' => 'vpc',
71
+ 'resources' => resources }
72
+ expect(subject.to_hash).to eq(hash)
73
+ end
25
74
  end
26
75
  end
27
76
 
28
77
  context "failing" do
29
- subject { Outliers::Result.new evaluation: 'evalme',
30
- failing_resources: ['key3', 'key4'],
78
+ subject { Outliers::Result.new account_name: 'cnt',
79
+ arguments: ['test123'],
80
+ failing_resources: [resource1, resource2],
81
+ name: 'evalme',
31
82
  passing_resources: [],
32
- resource: 'instance',
33
- verification: 'vpc' }
34
- it "should return failed" do
35
- expect(subject.to_s).to eq 'failed'
36
- end
83
+ provider_name: 'aws',
84
+ resource_name: 'instance',
85
+ verification_name: 'vpc' }
37
86
 
38
87
  it "should return false for passing verification" do
39
88
  expect(subject.passed?).to be_false
data/spec/run_spec.rb CHANGED
@@ -94,8 +94,8 @@ describe Outliers::Run do
94
94
  end
95
95
 
96
96
  context "returning results" do
97
- let(:result1) { Outliers::Result.new name: 'result1', passing_resources: [], failing_resources: [], evaluation: 'test', verification: 'ver' }
98
- let(:result2) { Outliers::Result.new name: 'result2', passing_resources: [], failing_resources: ['failed'], evaluation: 'test', verification: 'ver' }
97
+ let(:result1) { Outliers::Result.new name: 'result1', passing_resources: [], failing_resources: [], verification_name: 'ver' }
98
+ let(:result2) { Outliers::Result.new name: 'result2', passing_resources: [], failing_resources: ['failed'], verification_name: 'ver' }
99
99
 
100
100
  before do
101
101
  subject.results << result1
@@ -104,13 +104,13 @@ describe Outliers::Run do
104
104
 
105
105
  describe "#passed" do
106
106
  it "should return an array of all passing results" do
107
- expect(subject.passed).to eq([result1])
107
+ expect(subject.passing_results).to eq([result1])
108
108
  end
109
109
  end
110
110
 
111
111
  describe "#failed" do
112
112
  it "should return an array of all failing results" do
113
- expect(subject.failed).to eq([result2])
113
+ expect(subject.failing_results).to eq([result2])
114
114
  end
115
115
  end
116
116
  end
data/spec/spec_helper.rb CHANGED
@@ -7,13 +7,13 @@ Dir[File.expand_path(File.join(File.dirname(__FILE__),'helpers', '*.rb'))].each
7
7
  require f
8
8
  end
9
9
 
10
- def credentials
11
- YAML.load(fixture_file 'credentials1.yml')
10
+ def account
11
+ YAML.load(fixture_file 'account1.yml')
12
12
  end
13
13
 
14
14
  def stub_logger
15
15
  Outliers.logger stub 'test'
16
- Outliers.logger.stub :debug => true, :info => true, :warn => true
16
+ Outliers.logger.stub :debug => true, :info => true, :warn => true, :error => true
17
17
  end
18
18
 
19
19
  RSpec.configure do |config|
@@ -26,17 +26,17 @@ describe Outliers::Verifications::Shared do
26
26
  context "#equals?" do
27
27
  it "should verify the list of resources equals the list of keys and return no failing reosurces" do
28
28
  subject.stub :list_by_key => ['resource1'], :list => [resource1]
29
- expect(subject.equals?(:keys => ['resource1'])).to eq([])
29
+ expect(subject.equals?(['resource1'])).to eq([])
30
30
  end
31
31
 
32
32
  it "should verify the list of resources equals the single key and return no failing resources" do
33
33
  subject.stub :list_by_key => ['resource1'], :list => [resource1]
34
- expect(subject.equals?(:keys => 'resource1')).to eq([])
34
+ expect(subject.equals?('resource1')).to eq([])
35
35
  end
36
36
 
37
37
  it "should return resources which do not match the given list" do
38
38
  subject.stub :list_by_key => ['resource1', 'resource2'], :list => [resource1, resource2]
39
- expect(subject.equals?(:keys => 'resource1')).to eq([resource2])
39
+ expect(subject.equals?('resource1')).to eq([resource2])
40
40
  end
41
41
  end
42
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: outliers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.5.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Weaver
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-28 00:00:00.000000000 Z
11
+ date: 2013-10-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -85,16 +85,19 @@ files:
85
85
  - Rakefile
86
86
  - bin/outliers
87
87
  - lib/outliers.rb
88
+ - lib/outliers/account.rb
88
89
  - lib/outliers/cli.rb
89
90
  - lib/outliers/cli/process.rb
90
91
  - lib/outliers/collection.rb
91
- - lib/outliers/credentials.rb
92
92
  - lib/outliers/evaluation.rb
93
93
  - lib/outliers/exceptions.rb
94
94
  - lib/outliers/filters.rb
95
95
  - lib/outliers/filters/aws.rb
96
96
  - lib/outliers/filters/aws/ec2.rb
97
97
  - lib/outliers/filters/aws/ec2/tags.rb
98
+ - lib/outliers/handlers.rb
99
+ - lib/outliers/handlers/json.rb
100
+ - lib/outliers/handlers/outliers_api.rb
98
101
  - lib/outliers/info.rb
99
102
  - lib/outliers/mixins.rb
100
103
  - lib/outliers/provider.rb
@@ -139,12 +142,13 @@ files:
139
142
  - outliers.gemspec
140
143
  - reference.yaml
141
144
  - shared.yaml
145
+ - spec/account_spec.rb
142
146
  - spec/collection_spec.rb
143
- - spec/credentials_spec.rb
144
147
  - spec/evaluation_spec.rb
145
148
  - spec/filters/aws/ec2/tags_spec.rb
146
- - spec/fixtures/credentials1.yml
147
- - spec/fixtures/credentials2.yml
149
+ - spec/fixtures/account1.yml
150
+ - spec/fixtures/account2.yml
151
+ - spec/handlers/outliers_api_spec.rb
148
152
  - spec/helpers/fixtures.rb
149
153
  - spec/info_spec.rb
150
154
  - spec/mixins_spec.rb
@@ -156,7 +160,7 @@ files:
156
160
  - spec/run_spec.rb
157
161
  - spec/spec_helper.rb
158
162
  - spec/verifications/shared_spec.rb
159
- homepage: https://github.com/brettweavnet/outliers
163
+ homepage: http://www.getoutliers.com/documentation
160
164
  licenses:
161
165
  - Apache2
162
166
  metadata: {}
@@ -171,22 +175,23 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
175
  version: '0'
172
176
  required_rubygems_version: !ruby/object:Gem::Requirement
173
177
  requirements:
174
- - - '>='
178
+ - - '>'
175
179
  - !ruby/object:Gem::Version
176
- version: '0'
180
+ version: 1.3.1
177
181
  requirements: []
178
182
  rubyforge_project:
179
- rubygems_version: 2.0.6
183
+ rubygems_version: 2.1.5
180
184
  signing_key:
181
185
  specification_version: 4
182
186
  summary: Configuration verification framework.
183
187
  test_files:
188
+ - spec/account_spec.rb
184
189
  - spec/collection_spec.rb
185
- - spec/credentials_spec.rb
186
190
  - spec/evaluation_spec.rb
187
191
  - spec/filters/aws/ec2/tags_spec.rb
188
- - spec/fixtures/credentials1.yml
189
- - spec/fixtures/credentials2.yml
192
+ - spec/fixtures/account1.yml
193
+ - spec/fixtures/account2.yml
194
+ - spec/handlers/outliers_api_spec.rb
190
195
  - spec/helpers/fixtures.rb
191
196
  - spec/info_spec.rb
192
197
  - spec/mixins_spec.rb