hiera-cloudformation 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
- ---
2
- SHA512:
3
- data.tar.gz: 528e5773c1de04e1eb38d19c73ae8629fac0b0ebe235694c8bdb724b666d4aee0badafa093bd34e1f7b840b1ed92b8788ce3f3b045d390cd11f0ccfc66e6766c
4
- metadata.gz: 891a69aff5ed2455a88d4e3c008084bf7e964a4cd36227258977232881331e1f0a230ddf2d4504a5d43870779b4baf105ca5f0348d894ca55d2d8862e102d1b7
5
- SHA1:
6
- data.tar.gz: 048f0606a4b2313a1de2e20732a136b2fb071b33
7
- metadata.gz: 1fb1aba71ac1d4d39bf325d21a0af7ab1ae484b3
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1eba584b63db610211319c070fe1d0d6d4c1f087
4
+ data.tar.gz: dc817b92d7a69caedcc5d771e9c1371dd8254156
5
+ SHA512:
6
+ metadata.gz: 24d92d0ba85721c8fcb5aed60992128583762309dae4f68a2053b57970de074996044c8039ab5188b0a3dcddad0a4a641468dc9bdf891c814ce62c7994257356
7
+ data.tar.gz: abdfcc7971cbf4930b1236092878fd7ac3bb195d750aeaf1bba62c521aa931b2e12050e11907eace114a4279fbd26649d74801fa382c64a4f1d1d95d04ce67b9
data/LICENSE.txt CHANGED
@@ -1,22 +1,13 @@
1
- Copyright (c) 2013 Hugh Cole-Baker
1
+ Copyright 2013-2014 FanDuel Ltd.
2
2
 
3
- MIT License
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
7
+ http://www.apache.org/licenses/LICENSE-2.0
12
8
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
data/README.md CHANGED
@@ -29,6 +29,16 @@ If you do not add these keys to your configuration file, the access keys will be
29
29
  the `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` environment variables, or from an IAM
30
30
  instance role (if you are running Hiera on an EC2 instance with an IAM role assigned).
31
31
 
32
+ The AWS region to use can also be configured in the `:cloudformation` section of hiera.yaml.
33
+ You can also tell the backend to convert string literals "true", "false", "3.14", etc to Boolean
34
+ or Number types with the `:parse_metadata` configuration option; this may be useful as
35
+ CloudFormation will convert Booleans and Numbers in the template JSON metadata into Strings when
36
+ retrieved from a stack resource:
37
+
38
+ :cloudformation:
39
+ :region: 'us-west-1'
40
+ :parse_metadata: true
41
+
32
42
  To use this backend you also need to add entries to your "hierarchy" in your hiera.yaml file.
33
43
  If you put an entry of this form in your hierarchy:
34
44
 
@@ -101,3 +111,12 @@ and you include an entry:
101
111
 
102
112
  in your hierarchy, you can query hiera for the key "class::access_key_id" or "class::secret_access_key"
103
113
  and retrieve the attributes of the "MyIAMKey" resource created by CloudFormation.
114
+
115
+
116
+ ## Run tests
117
+
118
+ Requires ruby 1.9+ for minitest
119
+
120
+ ```bash
121
+ rake test
122
+ ```
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
1
  =begin
2
- Copyright 2013 FanDuel Ltd.
2
+ Copyright 2013-2014 FanDuel Ltd.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -16,10 +16,11 @@ limitations under the License.
16
16
 
17
17
  require 'rubygems'
18
18
  require 'rubygems/package_task'
19
+ require 'rake/testtask'
19
20
 
20
21
  spec = Gem::Specification.new do |gem|
21
22
  gem.name = "hiera-cloudformation"
22
- gem.version = '0.0.1'
23
+ gem.version = '0.0.2'
23
24
  gem.authors = ["Hugh Cole-Baker"]
24
25
  gem.email = ["hugh@fanduel.com"]
25
26
  gem.summary = %q{CloudFormation backend for Hiera}
@@ -41,3 +42,8 @@ end
41
42
  Gem::PackageTask.new(spec) do |pkg|
42
43
  pkg.need_tar = true
43
44
  end
45
+
46
+ Rake::TestTask.new do |t|
47
+ t.pattern = 'test/*_test.rb'
48
+ t.verbose = true
49
+ end
@@ -1,5 +1,5 @@
1
1
  =begin
2
- Copyright 2013 FanDuel Ltd.
2
+ Copyright 2013-2014 FanDuel Ltd.
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -31,18 +31,35 @@ class Hiera
31
31
  require 'json'
32
32
  end
33
33
 
34
- if Config.include?(:cloudformation) && !Config[:cloudformation].nil? &&
35
- Config[:cloudformation].include?(:access_key_id) && Config[:cloudformation].include?(:secret_access_key)
36
- Hiera.debug("Found AWS access key from configuration")
37
- AWS.config({
38
- :access_key_id => Config[:cloudformation][:access_key_id],
39
- :secret_access_key => Config[:cloudformation][:secret_access_key]
40
- })
34
+ if Config.include?(:cloudformation) && !Config[:cloudformation].nil? then
35
+ if Config[:cloudformation].fetch(:parse_metadata, false) then
36
+ Hiera.debug("Will convert CloudFormation stringified metadata back to numbers or booleans.")
37
+ @parse_metadata = true
38
+ else
39
+ @parse_metadata = false
40
+ end
41
+
42
+ aws_config = {}
43
+ if Config[:cloudformation].include?(:access_key_id) && Config[:cloudformation].include?(:secret_access_key) then
44
+ Hiera.debug("Found AWS access key #{Config[:cloudformation][:access_key_id]} from configuration")
45
+ aws_config[:access_key_id] = Config[:cloudformation][:access_key_id]
46
+ aws_config[:secret_access_key] = Config[:cloudformation][:secret_access_key]
47
+ end
48
+ if Config[:cloudformation].include?(:region) then
49
+ Hiera.debug("Found AWS region #{Config[:cloudformation][:region]} from configuration")
50
+ aws_config[:region] = Config[:cloudformation][:region]
51
+ end
52
+ if aws_config.length != 0 then
53
+ @cf = AWS::CloudFormation.new(aws_config)
54
+ else
55
+ Hiera.debug("No AWS configuration found, will fall back to env variables or IAM role")
56
+ @cf = AWS::CloudFormation.new
57
+ end
41
58
  else
42
59
  Hiera.debug("No configuration found, will fall back to env variables or IAM role")
60
+ @cf = AWS::CloudFormation.new
43
61
  end
44
62
 
45
- @cf = AWS::CloudFormation.new
46
63
  @output_cache = TimedCache.new
47
64
  @resource_cache = TimedCache.new
48
65
 
@@ -67,6 +84,10 @@ class Hiera
67
84
 
68
85
  next if raw_answer.nil?
69
86
 
87
+ if @parse_metadata then
88
+ raw_answer = convert_metadata(raw_answer)
89
+ end
90
+
70
91
  new_answer = Backend.parse_answer(raw_answer, scope)
71
92
 
72
93
  case resolution_type
@@ -131,6 +152,36 @@ class Hiera
131
152
 
132
153
  return nil
133
154
  end
155
+
156
+ def convert_metadata(json_object)
157
+ if json_object.is_a?(Hash) then
158
+ # convert each value of a Hash
159
+ converted_object = {}
160
+ json_object.each do |key, value|
161
+ converted_object[key] = convert_metadata(value)
162
+ end
163
+ return converted_object
164
+ elsif json_object.is_a?(Array) then
165
+ # convert each item in an Array
166
+ return json_object.map { |item| convert_metadata(item) }
167
+ elsif json_object == "true" then
168
+ # Boolean literals
169
+ return true
170
+ elsif json_object == "false" then
171
+ return false
172
+ elsif json_object == "null" then
173
+ return nil
174
+ elsif /^-?([1-9]\d*|0)(.\d+)?([eE][+-]?\d+)?$/.match(json_object) then
175
+ # Numeric literals
176
+ if json_object.include?('.') then
177
+ return json_object.to_f
178
+ else
179
+ return json_object.to_i
180
+ end
181
+ else
182
+ return json_object
183
+ end
184
+ end
134
185
  end
135
186
  end
136
187
  end
@@ -0,0 +1,51 @@
1
+ require 'minitest/autorun'
2
+ require_relative '../lib/hiera/backend/cloudformation_backend'
3
+
4
+ class ConvertMetadataTest < MiniTest::Unit::TestCase
5
+
6
+ class CloudformationBackendNoInit < Hiera::Backend::Cloudformation_backend
7
+ def initialize
8
+ # nope
9
+ end
10
+ end
11
+
12
+ def setup
13
+ @cfb = CloudformationBackendNoInit.new
14
+ end
15
+
16
+ def test_boolean
17
+ assert_equal true, @cfb.convert_metadata("true")
18
+ assert_equal false, @cfb.convert_metadata("false")
19
+ end
20
+
21
+ def test_nil
22
+ assert_equal nil, @cfb.convert_metadata("null")
23
+ end
24
+
25
+ def test_integer
26
+ assert_equal 1, @cfb.convert_metadata("1")
27
+ assert_equal -1, @cfb.convert_metadata("-1")
28
+ end
29
+
30
+ def test_float
31
+ assert_in_delta 1.0, @cfb.convert_metadata("1.0"), 0.001
32
+ assert_in_delta -1.0, @cfb.convert_metadata("-1.0"), 0.001
33
+ end
34
+
35
+ def test_string
36
+ assert_equal "monkey", @cfb.convert_metadata("monkey")
37
+ assert_equal "1.0.1", @cfb.convert_metadata("1.0.1")
38
+ assert_equal "True", @cfb.convert_metadata("True")
39
+ end
40
+
41
+ def test_array
42
+ expected = [1, 2, 3, [4, 5, 6]]
43
+ assert_equal expected, @cfb.convert_metadata(["1", "2", "3", ["4", "5", "6"]])
44
+ end
45
+
46
+ def test_hash
47
+ expected = {"monkey" => {"fez" => [1, 2, 3]}}
48
+ assert_equal expected, @cfb.convert_metadata({"monkey" => {"fez" => ["1", "2", "3"]}})
49
+ end
50
+
51
+ end
metadata CHANGED
@@ -1,93 +1,106 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: hiera-cloudformation
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Hugh Cole-Baker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
-
12
- date: 2013-07-19 00:00:00 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
15
14
  name: rake
16
- prerelease: false
17
- requirement: &id001 !ruby/object:Gem::Requirement
18
- requirements:
19
- - &id005
20
- - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0"
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
23
20
  type: :development
24
- version_requirements: *id001
25
- - !ruby/object:Gem::Dependency
26
- name: aws-sdk
27
21
  prerelease: false
28
- requirement: &id002 !ruby/object:Gem::Requirement
29
- requirements:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: aws-sdk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
30
31
  - - ~>
31
- - !ruby/object:Gem::Version
32
+ - !ruby/object:Gem::Version
32
33
  version: 1.11.2
33
34
  type: :runtime
34
- version_requirements: *id002
35
- - !ruby/object:Gem::Dependency
36
- name: timedcache
37
35
  prerelease: false
38
- requirement: &id003 !ruby/object:Gem::Requirement
39
- requirements:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 1.11.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: timedcache
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
40
45
  - - ~>
41
- - !ruby/object:Gem::Version
46
+ - !ruby/object:Gem::Version
42
47
  version: 0.4.0
43
48
  type: :runtime
44
- version_requirements: *id003
45
- - !ruby/object:Gem::Dependency
46
- name: json
47
49
  prerelease: false
48
- requirement: &id004 !ruby/object:Gem::Requirement
49
- requirements:
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: json
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
50
59
  - - ~>
51
- - !ruby/object:Gem::Version
60
+ - !ruby/object:Gem::Version
52
61
  version: 1.8.0
53
62
  type: :runtime
54
- version_requirements: *id004
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: 1.8.0
55
69
  description: Queries CloudFormation stack outputs or resource metadata for Hiera data
56
- email:
70
+ email:
57
71
  - hugh@fanduel.com
58
72
  executables: []
59
-
60
73
  extensions: []
61
-
62
74
  extra_rdoc_files: []
63
-
64
- files:
75
+ files:
65
76
  - lib/hiera/backend/cloudformation_backend.rb
77
+ - test/convert_metadata_test.rb
66
78
  - Rakefile
67
79
  - README.md
68
80
  - LICENSE.txt
69
81
  homepage: https://github.com/fanduel/hiera-cloudformation
70
- licenses:
82
+ licenses:
71
83
  - Apache License (2.0)
72
84
  metadata: {}
73
-
74
85
  post_install_message:
75
86
  rdoc_options: []
76
-
77
- require_paths:
87
+ require_paths:
78
88
  - lib
79
- required_ruby_version: !ruby/object:Gem::Requirement
80
- requirements:
81
- - *id005
82
- required_rubygems_version: !ruby/object:Gem::Requirement
83
- requirements:
84
- - *id005
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
85
99
  requirements: []
86
-
87
100
  rubyforge_project:
88
- rubygems_version: 2.0.5
101
+ rubygems_version: 2.0.14
89
102
  signing_key:
90
103
  specification_version: 4
91
104
  summary: CloudFormation backend for Hiera
92
- test_files: []
93
-
105
+ test_files:
106
+ - test/convert_metadata_test.rb