outliers 0.5.0 → 0.5.1

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: f134273c293b8f65b676420021b09829540e5aa3
4
- data.tar.gz: 87fdbf39311445703671fe53b77c708135cdc9f1
3
+ metadata.gz: 834ef0a08d61f1df2366395da4695af04c034eb1
4
+ data.tar.gz: b958631f09f5e25bbc9ffa84562fda4961ce3ed5
5
5
  SHA512:
6
- metadata.gz: a59b121bf3711dc71d18fbf7b1d12c1f21766f1890005a67267c721ade8a8bc31941351984db00d9dde2b713bf1b1f26018e2b9b1c85f25c3c4e76932402e2b3
7
- data.tar.gz: 4eadc63e016484a970f0196e6395b093141b1c824a1171f5b9269911533b1491aa87d090e7aea861213b4e81df8c29c06dfcc5bea50f6d99415373f9ace992e3
6
+ metadata.gz: f7786919daab3cc5062f27ef73ede084d6263164d319d9669908cf0c47581fed6d916b7f3d1f27ac3187113b457a6403a65668a3c1baa376d68e0ba3d598a09b
7
+ data.tar.gz: 1777fb497e933c4a3de1ca63606d5e1619e71193354cea342a40fb6325f92d4104427babc923805168102e4bf0561a596f86ea3666ffaec2b983622f31830104
@@ -1,3 +1,7 @@
1
+ ## 0.5.1
2
+
3
+ * Added provider, colleciton and resource lookup methods
4
+
1
5
  ## 0.5.0
2
6
 
3
7
  * Added exclude filters
@@ -105,7 +105,9 @@ module Outliers
105
105
  end
106
106
 
107
107
  def account(name)
108
- @run.account.fetch name
108
+ account = @run.account.fetch name, nil
109
+ raise Outliers::Exceptions::UnknownAccount.new "Unkown account '#{name}'." unless account
110
+ account
109
111
  end
110
112
 
111
113
  def merged_account(name, options)
@@ -3,17 +3,36 @@ module Outliers
3
3
 
4
4
  attr_reader :account
5
5
 
6
+ def self.find_by_name(name)
7
+ Outliers::Providers.name_map.fetch name, nil
8
+ end
9
+
10
+ def self.exists?(name)
11
+ find_by_name(name) != nil
12
+ end
13
+
6
14
  def self.connect_to(account)
7
- provider = account.fetch 'provider'
8
- Outliers::Providers.name_map.fetch(provider).new account
9
- rescue KeyError
10
- raise Outliers::Exceptions::UnknownProvider.new "Unkown provider '#{provider.join('_').downcase}'."
15
+ provider_name = account.fetch 'provider'
16
+
17
+ if exists? provider_name
18
+ find_by_name(provider_name).new account
19
+ else
20
+ raise Outliers::Exceptions::UnknownProvider.new "Invalid provider '#{provider_name}'."
21
+ end
11
22
  end
12
23
 
13
24
  def self.to_human
14
25
  (self.to_s.split('::') - ['Outliers', 'Providers']).map { |p| p.underscore }.join('_').downcase
15
26
  end
16
27
 
28
+ def self.resources
29
+ Outliers::Resources.resources.select {|r| r.to_human =~ /^#{to_human}/}
30
+ end
31
+
32
+ def self.collections
33
+ Outliers::Resources.collections.select {|r| r.to_human =~ /^#{to_human}/}
34
+ end
35
+
17
36
  def initialize(account)
18
37
  @account = account
19
38
  @logger = Outliers.logger
@@ -7,10 +7,22 @@ module Outliers
7
7
  'name'
8
8
  end
9
9
 
10
+ def self.to_human
11
+ (self.to_s.split('::') - ['Outliers', 'Resources']).map { |p| p.underscore }.join('_').downcase
12
+ end
13
+
10
14
  def self.verifications
11
15
  []
12
16
  end
13
17
 
18
+ def self.find_by_name(name)
19
+ Outliers::Resources.find_by_name name
20
+ end
21
+
22
+ def self.list
23
+ Outliers::Resources.resources
24
+ end
25
+
14
26
  def initialize(source)
15
27
  @source = source
16
28
  @logger = Outliers.logger
@@ -4,12 +4,17 @@ module Outliers
4
4
  module Resources
5
5
  module_function
6
6
 
7
- def list
8
- Outliers::Resources.collections
7
+ def find_by_name(name)
8
+ l = resources.select {|m| m.to_human == name }
9
+ l.any? ? l.first : nil
9
10
  end
10
11
 
11
12
  def collections
12
13
  all_the_modules.select {|m| (m.is_a? Class) && (m.to_s =~ /Collection$/)}
13
14
  end
15
+
16
+ def resources
17
+ all_the_modules.select {|m| (m.is_a? Class) && !(m.to_s =~ /Collection$/)}
18
+ end
14
19
  end
15
20
  end
@@ -1,3 +1,3 @@
1
1
  module Outliers
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
@@ -17,7 +17,7 @@ describe Outliers::Collection do
17
17
  end
18
18
 
19
19
  context "#to_human" do
20
- it "should return the human name for this resource" do
20
+ it "should return the human name for the resource of the collection" do
21
21
  expect(Outliers::Resources::Aws::Ec2::SecurityGroupCollection.to_human).to eq('aws_ec2_security_group')
22
22
  expect(Outliers::Resources::Aws::S3::BucketCollection.to_human).to eq('aws_s3_bucket')
23
23
  end
@@ -31,6 +31,11 @@ describe Outliers::Evaluation do
31
31
  subject.connect('test_account_1', { 'provider' => 'aws_ec2' })
32
32
  expect(subject.provider_name_array).to eq(['Aws', 'Ec2'])
33
33
  end
34
+
35
+ it "should throw an error if the account is unknown" do
36
+ expect { subject.connect('bad_account') }.
37
+ to raise_error(Outliers::Exceptions::UnknownAccount)
38
+ end
34
39
  end
35
40
 
36
41
 
@@ -20,7 +20,7 @@ describe Outliers::Info do
20
20
  end
21
21
 
22
22
  it "should verify each resource method has a entry in reference.yaml" do
23
- expect((@resources - ['all_shared']).sort).to eq(Outliers::Resources.list.map {|r| r.to_human}.sort)
23
+ expect((@resources - ['all_shared']).sort).to eq(Outliers::Resource.list.map {|r| r.to_human}.sort)
24
24
  end
25
25
 
26
26
  it "should validate each resource has a verification list, filter list and description" do
@@ -3,6 +3,16 @@ require 'spec_helper'
3
3
  describe Outliers::Provider do
4
4
  subject { Outliers::Provider }
5
5
 
6
+ context "#find_by_name" do
7
+ it "should return the provider by the given name" do
8
+ expect(subject.find_by_name 'aws_ec2').to eq(Outliers::Providers::Aws::Ec2)
9
+ end
10
+
11
+ it "should return nil if name not found" do
12
+ expect(subject.find_by_name 'blah').to be_false
13
+ end
14
+ end
15
+
6
16
  context "#connect_to" do
7
17
  let(:account) { ( { :name => "test_account_1",
8
18
  "provider" => "aws_ec2",
@@ -20,6 +30,31 @@ describe Outliers::Provider do
20
30
  "secret_access_key" => "abc",
21
31
  "access_key_id" => "123" })
22
32
  end
33
+
34
+ it "should raise an error if the provider does not exist" do
35
+ expect(subject.connect_to(account).class).to eq(Outliers::Providers::Aws::Ec2)
36
+ end
37
+
38
+ it "should raise an error if the provider is invalid" do
39
+ expect(subject.connect_to(account).class).to eq(Outliers::Providers::Aws::Ec2)
40
+ end
41
+
42
+ end
43
+
44
+ context "#collections" do
45
+ it "should return the collections for the provider" do
46
+ expect(Outliers::Providers::Aws::Rds.collections).
47
+ to eq([Outliers::Resources::Aws::Rds::DbInstanceCollection,
48
+ Outliers::Resources::Aws::Rds::DbSnapshotCollection])
49
+ end
50
+ end
51
+
52
+ context "#resources" do
53
+ it "should return the resources for the provider" do
54
+ expect(Outliers::Providers::Aws::Rds.resources).
55
+ to eq([Outliers::Resources::Aws::Rds::DbInstance,
56
+ Outliers::Resources::Aws::Rds::DbSnapshot])
57
+ end
23
58
  end
24
59
 
25
60
  context "#to_human" do
@@ -16,4 +16,21 @@ describe Outliers::Resource do
16
16
  expect(Outliers::Resource.key).to eq('name')
17
17
  end
18
18
  end
19
+
20
+ context "#to_human" do
21
+ it "should return the human name for this resource" do
22
+ expect(Outliers::Resources::Aws::Ec2::SecurityGroupCollection.to_human).to eq('aws_ec2_security_group')
23
+ expect(Outliers::Resources::Aws::S3::BucketCollection.to_human).to eq('aws_s3_bucket')
24
+ end
25
+ end
26
+
27
+ context "#self.find_by_name" do
28
+ it "should find the resource by name" do
29
+ expect(Outliers::Resource.find_by_name('aws_ec2_instance')).to eq(Outliers::Resources::Aws::Ec2::Instance)
30
+ end
31
+
32
+ it "should return nil if the resource can't be found" do
33
+ expect(Outliers::Resource.find_by_name('blah')).to be_nil
34
+ end
35
+ end
19
36
  end
@@ -2,14 +2,22 @@ require 'spec_helper'
2
2
 
3
3
  describe Outliers::Resources do
4
4
  subject { Outliers::Resources }
5
-
6
- context "#collections" do
7
- it "should return all the collections" do
5
+ before do
8
6
  Outliers::Resources.stub :all_the_modules => [Outliers::Resources::Aws::Ec2,
9
7
  Outliers::Resources::Aws::Ec2::SecurityGroup,
10
8
  Outliers::Resources::Aws::Ec2::SecurityGroupCollection]
9
+ end
10
+
11
+ context "#collection" do
12
+ it "should return all the collections" do
11
13
  expect(subject.collections).to eq([Outliers::Resources::Aws::Ec2::SecurityGroupCollection])
12
14
  end
13
15
  end
14
16
 
17
+ context "#resources" do
18
+ it "should return all the resources" do
19
+ expect(subject.resources).to eq([Outliers::Resources::Aws::Ec2::SecurityGroup])
20
+ end
21
+ end
22
+
15
23
  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.5.0
4
+ version: 0.5.1
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-10-13 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler