Class: CloudSpec::AMZN::Base
- Inherits:
-
Object
- Object
- CloudSpec::AMZN::Base
show all
- Includes:
- RSpec::Matchers
- Defined in:
- lib/cloudspec/amzn/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
9
10
11
12
|
# File 'lib/cloudspec/amzn/base.rb', line 9
def initialize
mock?
super
end
|
Instance Method Details
#compute_client(credentials = { 'access_key' => '', 'secret_key' => '' }, region = nil) ⇒ Object
51
52
53
54
55
56
57
58
59
|
# File 'lib/cloudspec/amzn/base.rb', line 51
def compute_client(credentials = { 'access_key' => '', 'secret_key' => '' }, region = nil)
CloudSpec.log.debug 'creating compute client ...'
Fog::Compute.new(
provider: 'AWS',
aws_access_key_id: credentials['access_key'],
aws_secret_access_key: credentials['secret_key'],
region: region
)
end
|
#harvest ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/cloudspec/amzn/base.rb', line 14
def harvest
load_rules
self.class.include_rules
CloudSpec.log.warn 'harvesting ...'
accounts = CloudSpec.config['aws']
accounts.each do |account_name, credentials|
process_account(account_name, credentials)
end
end
|
#load_rules ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/cloudspec/amzn/base.rb', line 27
def load_rules
CloudSpec.log.debug 'loading rules ...'
rules_path = File.expand_path(CloudSpec.options[:rules])
Dir["#{rules_path}/amzn/**/*.rb"].each do |file|
require file
end
end
|
#mock? ⇒ Boolean
61
62
63
64
|
# File 'lib/cloudspec/amzn/base.rb', line 61
def mock?
CloudSpec.log.debug 'Checking Mocking settings ...'
Fog.mock! if CloudSpec.options[:mock]
end
|
#process_account(account_name, credentials = { 'access_key' => nil, 'secret_key' => nil }) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/cloudspec/amzn/base.rb', line 36
def process_account(account_name, credentials = { 'access_key' => nil, 'secret_key' => nil })
CloudSpec.log.debug "processing account #{account_name} ..."
regions(credentials).each do |region|
objects(credentials, region).each do |object|
evaluate_object(account_name, region, object)
end
end
end
|
#regions(credentials) ⇒ Object
45
46
47
48
49
|
# File 'lib/cloudspec/amzn/base.rb', line 45
def regions(credentials)
CloudSpec.log.debug 'getting regions ...'
aws_client = compute_client(credentials)
aws_client.describe_regions.body['regionInfo'].map { |region| region['regionName'] }
end
|