outliers 0.0.1 → 0.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 96ee1fb7ec544e936e6a55b6c0d4bac0b8a9baea
4
- data.tar.gz: 098ddc59e2cd429d938785b42336b592823e38a1
3
+ metadata.gz: 5dcb9ddc49eb2c32e3716d6dd090fd7d1f98c3d9
4
+ data.tar.gz: 5516ddb04d0b89be33e4e6d8d7c013f512ed2d3c
5
5
  SHA512:
6
- metadata.gz: 13c134dbeb4901b3016502c188cbfacf41aef8c8f11db1f1d8a85d8f81b08937759fed1c257039b5259130b46756d66e7b19174d742f43acbfe2ecaf2a28ca2b
7
- data.tar.gz: 49dc924d5ea0694f3e8c4e98abae6ea93f327bf2c828309a375e4269430f14117b7169fc4e5dba91562fa8c81bc93e920917d2ab5bfdb73cea5ef63f6ffdb1ed
6
+ metadata.gz: ea89d2a78e78dbbdb296e4666d4fb1bb1c75d442fe094856f9ea79202b4fe7c02cecb710235e3124b6cbfe46da9d86f1373004836cac231dd1917fc8a28ae501
7
+ data.tar.gz: 0e6532c2846d0bbda51586a874823102328ba051aa2e2db5dfc7617488d8f3d3c4d7cbadcabe7f74033e3faa8fa2334a593eb2245078d06a524ea544197b5ac8
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.1.0
2
+
3
+ * Recursively load evaluation files.
4
+ * Updated DSL format.
5
+
1
6
  ## 0.0.1
2
7
 
3
- * Initial release
8
+ * Initial release.
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/brettweavnet/outliers.png)](http://travis-ci.org/brettweavnet/outliers)
2
+
1
3
  # Outliers
2
4
 
3
5
  Outliers is a framework for verifying configuration of resources.
@@ -90,83 +92,83 @@ To process a directory:
90
92
 
91
93
  To verify all instances are in a VPC, create the file **ec2.rb** and add the following block:
92
94
 
93
- evaluate do |e|
94
- e.connect 'aws_prod', provider: 'aws_ec2'
95
- e.resources 'instance'
96
- e.verify 'vpc'
95
+ evaluate do
96
+ connect 'aws_prod', provider: 'aws_ec2'
97
+ resources 'instance'
98
+ verify 'vpc'
97
99
  end
98
100
 
99
101
  Files can have multiple evaluations, to add a validation that overrides the region:
100
102
 
101
- evaluate do |e|
102
- e.connect 'aws_prod', provider: 'aws_ec2'
103
- e.resources 'instance'
104
- e.verify 'vpc'
103
+ evaluate do
104
+ connect 'aws_prod', provider: 'aws_ec2'
105
+ resources 'instance'
106
+ verify 'vpc'
105
107
  end
106
108
 
107
- evaluate do |e|
108
- e.connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
109
- e.resources 'instance'
110
- e.verify 'vpc'
109
+ evaluate do
110
+ connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
111
+ resources 'instance'
112
+ verify 'vpc'
111
113
  end
112
114
 
113
115
  The DSL supports any valid Ruby code. To iterate over multiple regions:
114
116
 
115
117
  ['us-west-1', 'us-west-2', 'us-east-1'].each do |region|
116
- evaluate do |e|
117
- e.connect 'aws_prod', provider: 'aws_ec2', region: region
118
- e.resources 'instance'
119
- e.verify 'vpc'
118
+ evaluate do
119
+ connect 'aws_prod', provider: 'aws_ec2', region: region
120
+ resources 'instance'
121
+ verify 'vpc'
120
122
  end
121
123
  end
122
124
 
123
125
  Evaluations can be given names to help identify Outliers in results.
124
126
 
125
- evaluate "validate_database_retention_period" do |e|
126
- e.connect 'aws_prod', provider: 'aws_rds', region: 'us-west-1'
127
- e.resources 'db_instance'
128
- e.verify 'backup_retention_period', days: 2
127
+ evaluate "validate_database_retention_period" do
128
+ connect 'aws_prod', provider: 'aws_rds', region: 'us-west-1'
129
+ resources 'db_instance'
130
+ verify 'backup_retention_period', days: 2
129
131
  end
130
132
 
131
133
  To pass arguments to a verification:
132
134
 
133
- evaluate do |e|
134
- e.connect 'aws_prod', provider: 'aws_rds', region: 'us-west-1'
135
- e.resources 'db_instance'
136
- e.verify 'backup_retention_period', days: 2
135
+ evaluate do
136
+ connect 'aws_prod', provider: 'aws_rds', region: 'us-west-1'
137
+ resources 'db_instance'
138
+ verify 'backup_retention_period', days: 2
137
139
  end
138
140
 
139
141
  To pass multiple arguments, specify them as an array:
140
142
 
141
- evaluate do |e|
142
- e.connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
143
- e.resources 'instance'
144
- e.verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
143
+ evaluate do
144
+ connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
145
+ resources 'instance'
146
+ verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
145
147
  end
146
148
 
147
149
  To only target a specific resource:
148
150
 
149
- evaluate do |e|
150
- e.connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
151
- e.resources 'instance', 'i-12345678'
152
- e.verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
151
+ evaluate do
152
+ connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
153
+ resources 'instance', 'i-12345678'
154
+ verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
153
155
  end
154
156
 
155
157
  To target multiple resources, you can pass an array:
156
158
 
157
- evaluate do |e|
158
- e.connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
159
- e.resources 'instance', ['i-12345678', 'i-abcdef12']
160
- e.verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
159
+ evaluate do
160
+ connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
161
+ resources 'instance', ['i-12345678', 'i-abcdef12']
162
+ verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
161
163
  end
162
164
 
163
165
  Sometimes you want to exclude resources that are known exceptions, to exclude an instance from the VPC validation:
164
166
 
165
- evaluate do |e|
166
- e.connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
167
- e.resources 'instance'
168
- e.exclude 'i-12345678'
169
- e.verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
167
+ evaluate do
168
+ connect 'aws_prod', provider: 'aws_ec2', region: 'us-west-1'
169
+ resources 'instance'
170
+ exclude 'i-12345678'
171
+ verify 'valid_image_id', image_ids: ['ami-12345678','ami-87654321']
170
172
  end
171
173
 
172
174
  ### Help
@@ -2,19 +2,6 @@ module Outliers
2
2
  module Credentials
3
3
  module_function
4
4
 
5
- # To Do - Remove me once validated not needed
6
- def load_from_config_folder
7
- credentials = {}
8
- files = Dir.entries(File.join(Outliers.config_path, 'credentials')) - ['.', '..']
9
- files.each do |file|
10
- contents = File.read File.join(Outliers.config_path, 'credentials', file)
11
- YAML.load(contents).each_pair do |k,v|
12
- credentials[k] = v
13
- end
14
- end
15
- credentials
16
- end
17
-
18
5
  def load_from_file(file)
19
6
  credentials = {}
20
7
  contents = File.read file
data/lib/outliers/run.rb CHANGED
@@ -8,18 +8,17 @@ module Outliers
8
8
 
9
9
  def process_evaluations_in_config_folder
10
10
  evaluations_path = File.join Outliers.config_path
11
- entries = Dir.entries(evaluations_path) - ['.', '..']
12
- entries.each do |e|
13
- file = File.join(evaluations_path, e)
14
- unless File.directory? file
15
- logger.info "Processing '#{file}'."
16
- self.instance_eval File.read(file)
17
- end
11
+ files = Dir.glob(File.join(evaluations_path, '**', '*'))
12
+ files.each do |file|
13
+ next if File.directory? file
14
+ next if File.extname(file) != '.rb'
15
+ logger.info "Processing '#{file}'."
16
+ self.instance_eval File.read(file)
18
17
  end
19
18
  end
20
19
 
21
- def evaluate(name='unspecified')
22
- yield Evaluation.new :name => name, :run => self
20
+ def evaluate(name='unspecified', &block)
21
+ Evaluation.new(:name => name, :run => self).instance_eval &block
23
22
  end
24
23
 
25
24
  def passed
@@ -1,3 +1,3 @@
1
1
  module Outliers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -4,27 +4,6 @@ describe Outliers::Credentials do
4
4
  subject { Outliers::Credentials }
5
5
  let(:credentials1) { fixture_file 'credentials1.yml' }
6
6
  let(:credentials2) { fixture_file 'credentials2.yml' }
7
- context "#load_from_config_folder" do
8
- before { Outliers.config_path '/test' }
9
- it "should load the credentials from each file in the directory" do
10
- Dir.should_receive(:entries).with('/test/credentials').
11
- and_return ['.', '..', 'test1.yml', 'test2.yml']
12
- File.should_receive(:read).with('/test/credentials/test1.yml').and_return credentials1
13
- File.should_receive(:read).with('/test/credentials/test2.yml').and_return credentials2
14
- results = { "test_credentials_1" =>
15
- { "region" => "us-west-1",
16
- "provider" => "aws_ec2",
17
- "access_key_id" => "01234567890123456789",
18
- "secret_access_key" =>"0123456789012345678901234567890123456789" },
19
- "test_credentials_2" =>
20
- { "region" => "us-west-1",
21
- "provider" => "aws_ec2",
22
- "access_key_id" => "01234567890123456789",
23
- "secret_access_key" => "0123456789012345678901234567890123456789" }
24
- }
25
- expect(subject.load_from_config_folder).to eq(results)
26
- end
27
- end
28
7
 
29
8
  context "#load_from_file" do
30
9
  it "should load the credentials from the given yaml file" do
data/spec/run_spec.rb CHANGED
@@ -6,28 +6,42 @@ describe Outliers::Run do
6
6
 
7
7
  before do
8
8
  stub_logger
9
+ Outliers.config_path '/test'
9
10
  end
10
11
 
11
12
  describe "#process_evaluations_in_config_folder" do
12
- it "should process all evaluation files in config folder" do
13
- Dir.should_receive(:entries).with('/test').and_return ['.', '..', 'test1.rb', 'test2.rb']
13
+ it "should process all .rb files in config folder and sub folders" do
14
+ files = ['/test/test1.rb', '/test/dir', '/test/dir/test2.rb', '/test/dir/test_other_file']
15
+ Dir.should_receive(:glob).with('/test/**/*').and_return files
16
+
17
+ ['/test/test1.rb', '/test/dir/test2.rb', '/test/dir/test_other_file'].each do |f|
18
+ File.should_receive(:directory?).with(f).and_return false
19
+ end
20
+ File.should_receive(:directory?).with('/test/dir').and_return true
21
+
14
22
  File.should_receive(:read).with('/test/test1.rb').and_return evaluation1
15
- File.should_receive(:read).with('/test/test2.rb').and_return evaluation2
23
+ File.should_receive(:read).with('/test/dir/test2.rb').and_return evaluation2
16
24
 
17
25
  subject.should_receive(:instance_eval).with(evaluation1)
18
26
  subject.should_receive(:instance_eval).with(evaluation2)
19
27
  subject.process_evaluations_in_config_folder
20
28
  end
21
-
22
- it "should skip directories"
23
- it "should only evaluate .rb files"
24
29
  end
25
30
 
26
31
  describe "#evaluate" do
27
- it "should kick off a new evaluation and yield it to the block" do
32
+ it "should kick off a new evaluation and pass the block for execuation" do
28
33
  Outliers::Evaluation.should_receive(:new).with(:name => 'my evaluation', :run => subject).and_return evaluation1
29
- subject.evaluate('my evaluation') do |e|
30
- expect(e).to eq(evaluation1)
34
+ evaluation1.should_receive(:connect).with('test')
35
+ subject.evaluate 'my evaluation' do
36
+ connect 'test'
37
+ end
38
+ end
39
+
40
+ it "should kick off a new evaluation with unspecified name" do
41
+ Outliers::Evaluation.should_receive(:new).with(:name => 'unspecified', :run => subject).and_return evaluation1
42
+ evaluation1.should_receive(:connect).with('test')
43
+ subject.evaluate do
44
+ connect 'test'
31
45
  end
32
46
  end
33
47
  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.0.1
4
+ version: 0.1.0
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-08-11 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler