hiera-aws 0.5.0 → 0.6.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.
data/.rubocop.yml CHANGED
@@ -5,6 +5,8 @@ AllCops:
5
5
 
6
6
  DotPosition:
7
7
  Enabled: false
8
+ EachWithObject:
9
+ Enabled: false
8
10
  Encoding:
9
11
  Enabled: false
10
12
  HashSyntax:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v0.6.0 (Aug 04 2014)
2
+
3
+ * Added `cloudformation` in order to allow querying CloudFormation outputs.
4
+
1
5
  ## v0.5.0 (May 15 2014)
2
6
 
3
7
  * Change `redis_cluster_nodes_for_cfn_stack`, `memcached_cluster_nodes_for_cfn_stack`,
data/README.md CHANGED
@@ -152,6 +152,20 @@ $instance_identifier = $rds_instances[0]['db_instance_identifier']
152
152
  $endpoint_address = $rds_instances[0]['endpoint']['address']
153
153
  ```
154
154
 
155
+ ### cloudformation stack=<stack-name> output=<output-name>
156
+
157
+ Returns the value (string) of an output property of the given CloudFormation stack.
158
+
159
+ Useful for example if you created a AWS access keypair in your CloudFormation
160
+ stack and want to access the credentials via hiera.
161
+
162
+ Usage:
163
+
164
+ ```
165
+ # Get output "some_output_key" of CloudFormation stack "some_stack"
166
+ value = hiera("cloudformation stack=some_stack output=some_output_key")
167
+ ```
168
+
155
169
  ## License and Authors
156
170
 
157
171
  * Author:: Mathias Lafeldt (mathias.lafeldt@jimdo.com)
data/Rakefile CHANGED
@@ -6,7 +6,9 @@ if RUBY_VERSION >= "1.9.2"
6
6
  require "rubocop/rake_task"
7
7
 
8
8
  desc "Run RuboCop style and lint checks"
9
- Rubocop::RakeTask.new(:rubocop)
9
+ RuboCop::RakeTask.new(:rubocop) do |t|
10
+ t.options = ["-D"]
11
+ end
10
12
 
11
13
  task :test => :rubocop
12
14
  end
data/hiera-aws.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "bundler"
24
24
  spec.add_development_dependency "rake"
25
25
  spec.add_development_dependency "rspec"
26
- spec.add_development_dependency "rubocop", "~> 0.21.0" if RUBY_VERSION >= "1.9.2"
26
+ spec.add_development_dependency "rubocop", "~> 0.23.0" if RUBY_VERSION >= "1.9.2"
27
27
  spec.add_development_dependency "webmock"
28
28
  end
@@ -0,0 +1,37 @@
1
+ require "hiera/backend/aws/base"
2
+
3
+ class Hiera
4
+ module Backend
5
+ module Aws
6
+ # Implementation of Hiera keys for aws/cloudformation
7
+ class Cloudformation < Base
8
+ def initialize(scope = {})
9
+ super(scope)
10
+ @client = AWS::CloudFormation::Client.new
11
+ end
12
+
13
+ # Override default key lookup to implement custom format. Examples:
14
+ def lookup(key, scope)
15
+ r = super(key, scope)
16
+ return r if r
17
+
18
+ args = key.split
19
+ return if args.shift != "cloudformation"
20
+ parameters = Hash[args.map { |t| t.split("=") }]
21
+ stack_name = parameters.fetch("stack")
22
+ output_key = parameters.fetch("output")
23
+ lookup_cfn_output_value(stack_name, output_key)
24
+ end
25
+
26
+ private
27
+
28
+ def lookup_cfn_output_value(stack_name, output_key)
29
+ found_stacks = @client.describe_stacks(:stack_name => stack_name)[:stacks]
30
+ found_stacks.first[:outputs].select do |output|
31
+ output.fetch(:output_key) == output_key
32
+ end.first.fetch(:output_value)
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -20,14 +20,13 @@ class Hiera
20
20
  return r if r
21
21
 
22
22
  args = key.split
23
- if args.shift == "rds_instances"
24
- if args.length > 0
25
- tags = Hash[args.map { |t| t.split("=") }]
26
- db_instances_with_tags(tags)
27
- else
28
- db_instances
29
- end.map { |i| prepare_instance_data(i) }
30
- end
23
+ return if args.shift != "rds_instances"
24
+ if args.length > 0
25
+ tags = Hash[args.map { |t| t.split("=") }]
26
+ db_instances_with_tags(tags)
27
+ else
28
+ db_instances
29
+ end.map { |i| prepare_instance_data(i) }
31
30
  end
32
31
 
33
32
  private
@@ -1,7 +1,7 @@
1
1
  class Hiera
2
2
  module Backend
3
3
  module Aws # rubocop:disable Documentation
4
- VERSION = "0.5.0"
4
+ VERSION = "0.6.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,5 +1,6 @@
1
1
  require "hiera/backend/aws/elasticache"
2
2
  require "hiera/backend/aws/rds"
3
+ require "hiera/backend/aws/cloudformation"
3
4
 
4
5
  class Hiera
5
6
  module Backend
@@ -73,6 +74,8 @@ class Hiera
73
74
  Hiera::Backend::Aws::ElastiCache.new
74
75
  when "rds"
75
76
  Hiera::Backend::Aws::RDS.new
77
+ when "cloudformation"
78
+ Hiera::Backend::Aws::Cloudformation.new
76
79
  else
77
80
  nil
78
81
  end
@@ -67,6 +67,12 @@ class Hiera
67
67
  backend.lookup(*params)
68
68
  end
69
69
 
70
+ it "properly forwards lookup to CloudFormation service" do
71
+ Backend.stub(:datasources).and_yield "aws/cloudformation"
72
+ expect_any_instance_of(Aws::Cloudformation).to receive(:lookup).with(key, scope)
73
+ backend.lookup(*params)
74
+ end
75
+
70
76
  it "returns nil if service returns empty result" do
71
77
  empty_result = []
72
78
  Backend.stub(:datasources).and_yield "aws/rds"
@@ -0,0 +1,75 @@
1
+ require "spec_helper"
2
+ require "hiera/backend/aws/cloudformation"
3
+
4
+ class Hiera
5
+ module Backend # rubocop:disable Documentation
6
+ describe Aws::Cloudformation do
7
+ let(:cfn) { Aws::Cloudformation.new }
8
+ let(:some_cfn_output_key) { "some_output_key" }
9
+ let(:some_cfn_output_value) { "some_value" }
10
+ let(:some_cfn_stack_name) { "some_stack_name" }
11
+
12
+ before do
13
+ AWS.stub(:config).and_return(double(:region => "some-region"))
14
+ cfn_client = double
15
+ allow(cfn_client).to receive(:describe_stacks).with(:stack_name => some_cfn_stack_name).and_return(
16
+ :stacks => [
17
+ {
18
+ :outputs => [
19
+ {
20
+ :output_key => "unrelated_key",
21
+ :output_value => "unrelated output",
22
+ :description => "foobar",
23
+ },
24
+ {
25
+ :output_key => some_cfn_output_key,
26
+ :output_value => some_cfn_output_value,
27
+ :description => "foobar",
28
+ },
29
+ {
30
+ :output_key => "another_unrelated_key",
31
+ :output_value => "another unrelated output",
32
+ :description => "foobar",
33
+ },
34
+ ]
35
+ }
36
+ ]
37
+ )
38
+ AWS::CloudFormation::Client.stub(:new).and_return(cfn_client)
39
+ end
40
+
41
+ describe "#lookup" do
42
+ let(:scope) { {} }
43
+
44
+ it "returns nil if Hiera key is unknown" do
45
+ expect(cfn.lookup("some_unknown_key", scope)).to be_nil
46
+ end
47
+
48
+ it "returns the value of the given cfn stack output" do
49
+ expect(cfn.lookup("cloudformation stack=#{some_cfn_stack_name} output=#{some_cfn_output_key}", scope)).to eq some_cfn_output_value
50
+ end
51
+
52
+ it "returns the value of the given cfn stack output regardless of parameter order" do
53
+ expect(cfn.lookup("cloudformation output=#{some_cfn_output_key} stack=#{some_cfn_stack_name}", scope)).to eq some_cfn_output_value
54
+ end
55
+
56
+ it "fails if stack is not given" do
57
+ expect { cfn.lookup("cloudformation output=#{some_cfn_output_key}", scope) }.to raise_exception
58
+ end
59
+
60
+ it "fails if output key is not given" do
61
+ expect { cfn.lookup("cloudformation stack=#{some_cfn_stack_name}", scope) }.to raise_exception
62
+ end
63
+
64
+ it "fails if queried stack does not exist" do
65
+ expect { cfn.lookup("cloudformation stack=some_non_existing_stack output=#{some_cfn_output_key}", scope) }.to raise_exception
66
+ end
67
+
68
+ it "fails if queried outputkey does not exist" do
69
+ expect { cfn.lookup("cloudformation stack=#{some_cfn_stack_name} output=non_existing_output_key", scope) }.to raise_exception
70
+ end
71
+
72
+ end
73
+ end
74
+ end
75
+ end
metadata CHANGED
@@ -1,73 +1,123 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hiera-aws
3
- version: !ruby/object:Gem::Version
4
- version: 0.5.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.6.0
5
+ prerelease:
5
6
  platform: ruby
6
- authors:
7
+ authors:
7
8
  - Mathias Lafeldt
8
9
  - Deniz Adrian
9
10
  - Soenke Ruempler
10
11
  autorequire:
11
12
  bindir: bin
12
13
  cert_chain: []
13
-
14
- date: 2014-05-15 00:00:00 Z
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
17
- prerelease: false
14
+ date: 2014-08-04 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
18
17
  name: aws-sdk
18
+ requirement: !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ! '>='
22
+ - !ruby/object:Gem::Version
23
+ version: '0'
19
24
  type: :runtime
20
- requirement: &id001 !ruby/object:Gem::Requirement
21
- requirements:
22
- - &id002
23
- - ">="
24
- - !ruby/object:Gem::Version
25
- version: "0"
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
25
  prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ none: false
28
+ requirements:
29
+ - - ! '>='
30
+ - !ruby/object:Gem::Version
31
+ version: '0'
32
+ - !ruby/object:Gem::Dependency
29
33
  name: bundler
34
+ requirement: !ruby/object:Gem::Requirement
35
+ none: false
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
30
40
  type: :development
31
- requirement: &id003 !ruby/object:Gem::Requirement
32
- requirements:
33
- - *id002
34
- version_requirements: *id003
35
- - !ruby/object:Gem::Dependency
36
41
  prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ - !ruby/object:Gem::Dependency
37
49
  name: rake
50
+ requirement: !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
38
56
  type: :development
39
- requirement: &id004 !ruby/object:Gem::Requirement
40
- requirements:
41
- - *id002
42
- version_requirements: *id004
43
- - !ruby/object:Gem::Dependency
44
57
  prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ none: false
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ - !ruby/object:Gem::Dependency
45
65
  name: rspec
66
+ requirement: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ type: :development
73
+ prerelease: false
74
+ version_requirements: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ - !ruby/object:Gem::Dependency
81
+ name: rubocop
82
+ requirement: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ~>
86
+ - !ruby/object:Gem::Version
87
+ version: 0.23.0
46
88
  type: :development
47
- requirement: &id005 !ruby/object:Gem::Requirement
48
- requirements:
49
- - *id002
50
- version_requirements: *id005
51
- - !ruby/object:Gem::Dependency
52
89
  prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ~>
94
+ - !ruby/object:Gem::Version
95
+ version: 0.23.0
96
+ - !ruby/object:Gem::Dependency
53
97
  name: webmock
98
+ requirement: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ! '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
54
104
  type: :development
55
- requirement: &id006 !ruby/object:Gem::Requirement
56
- requirements:
57
- - *id002
58
- version_requirements: *id006
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ! '>='
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
59
112
  description: Hiera AWS Backend
60
- email:
113
+ email:
61
114
  - mathias.lafeldt@jimdo.com
62
115
  - deniz.adrian@jimdo.com
63
116
  - soenke.ruempler@jimdo.com
64
117
  executables: []
65
-
66
118
  extensions: []
67
-
68
119
  extra_rdoc_files: []
69
-
70
- files:
120
+ files:
71
121
  - .gitignore
72
122
  - .rubocop.yml
73
123
  - .travis.yml
@@ -78,41 +128,46 @@ files:
78
128
  - Rakefile
79
129
  - hiera-aws.gemspec
80
130
  - lib/hiera/backend/aws/base.rb
131
+ - lib/hiera/backend/aws/cloudformation.rb
81
132
  - lib/hiera/backend/aws/elasticache.rb
82
133
  - lib/hiera/backend/aws/rds.rb
83
134
  - lib/hiera/backend/aws/version.rb
84
135
  - lib/hiera/backend/aws_backend.rb
85
136
  - spec/aws_backend_spec.rb
86
137
  - spec/aws_base_spec.rb
138
+ - spec/aws_cloudformation_spec.rb
87
139
  - spec/aws_elasticache_spec.rb
88
140
  - spec/aws_rds_spec.rb
89
141
  - spec/spec_helper.rb
90
142
  homepage: https://github.com/Jimdo/hiera-aws
91
- licenses:
143
+ licenses:
92
144
  - Apache 2.0
93
- metadata: {}
94
-
95
145
  post_install_message:
96
146
  rdoc_options: []
97
-
98
- require_paths:
147
+ require_paths:
99
148
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
101
- requirements:
102
- - *id002
103
- required_rubygems_version: !ruby/object:Gem::Requirement
104
- requirements:
105
- - *id002
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ none: false
157
+ requirements:
158
+ - - ! '>='
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
106
161
  requirements: []
107
-
108
162
  rubyforge_project:
109
- rubygems_version: 2.0.3
163
+ rubygems_version: 1.8.23
110
164
  signing_key:
111
- specification_version: 4
165
+ specification_version: 3
112
166
  summary: Hiera AWS Backend
113
- test_files:
167
+ test_files:
114
168
  - spec/aws_backend_spec.rb
115
169
  - spec/aws_base_spec.rb
170
+ - spec/aws_cloudformation_spec.rb
116
171
  - spec/aws_elasticache_spec.rb
117
172
  - spec/aws_rds_spec.rb
118
173
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: df09cbafee105c292fccfa418ce737723bcbdfe2
4
- data.tar.gz: c605c9aff9a2743e3f6a81bad3828ba4f98b370a
5
- SHA512:
6
- metadata.gz: 2f44cb460fc933f9caf7ae5f8e0e5f9370eeba2dd40b1d04e77dad2468707180df49712ee6a66e0046fc79b7d7fbfe7eeaeb4cbcbc65f7802604492fb17adf55
7
- data.tar.gz: d2aab23ef2d552d48b0f9b58dcdbf5e2ce88dbb86df42d9ddb78c0fcd8c6cd28585c2a16082a94f1ec97ae35c23b8aa2beccfc9c64d8f62760d9a38827f3727a