humidifier 1.0.6 → 1.2.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 +4 -4
- data/CloudFormationResourceSpecification.json +1424 -1287
- data/README.md +2 -2
- data/ext/humidifier/humidifier.c +8 -5
- data/lib/humidifier/aws_adapters/base.rb +0 -3
- data/lib/humidifier/aws_adapters/noop.rb +0 -2
- data/lib/humidifier/aws_adapters/sdkv1.rb +0 -2
- data/lib/humidifier/aws_adapters/sdkv2.rb +0 -2
- data/lib/humidifier/aws_shim.rb +0 -2
- data/lib/humidifier/condition.rb +0 -2
- data/lib/humidifier/configuration.rb +0 -2
- data/lib/humidifier/fn.rb +0 -2
- data/lib/humidifier/loader.rb +10 -7
- data/lib/humidifier/mapping.rb +0 -2
- data/lib/humidifier/output.rb +0 -2
- data/lib/humidifier/parameter.rb +0 -2
- data/lib/humidifier/props/base.rb +0 -1
- data/lib/humidifier/props/map_prop.rb +4 -7
- data/lib/humidifier/props/structure_prop.rb +5 -9
- data/lib/humidifier/props.rb +0 -1
- data/lib/humidifier/ref.rb +0 -2
- data/lib/humidifier/resource.rb +1 -3
- data/lib/humidifier/sdk_payload.rb +0 -2
- data/lib/humidifier/serializer.rb +1 -3
- data/lib/humidifier/sleeper.rb +0 -2
- data/lib/humidifier/stack.rb +4 -5
- data/lib/humidifier/utils.rb +3 -15
- data/lib/humidifier/version.rb +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Humidifier allows you to build AWS CloudFormation (CFN) templates programmatical
|
|
8
8
|
|
9
9
|
For the full docs, go to [https://localytics.github.io/humidifier/](http://localytics.github.io/humidifier/). For local development instructions, see the [Development](https://localytics.github.io/humidifier/#label-Development) section.
|
10
10
|
|
11
|
-
Humidifier is tested with Ruby 2.
|
11
|
+
Humidifier is tested with Ruby `2.1` and higher. The gem version is linked to AWS' CloudFormation resource specification version since `1.2.1`.
|
12
12
|
|
13
13
|
## Getting started
|
14
14
|
|
@@ -80,7 +80,7 @@ end
|
|
80
80
|
|
81
81
|
## Development
|
82
82
|
|
83
|
-
To get started, ensure you have ruby installed, version 2.
|
83
|
+
To get started, ensure you have ruby installed, version 2.1 or later. From there, install the `bundler` gem: `gem install bundler` and then `bundle install` in the root of the repository.
|
84
84
|
|
85
85
|
### Testing
|
86
86
|
|
data/ext/humidifier/humidifier.c
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
#include <humidifier.h>
|
2
2
|
|
3
|
-
// takes a substring from underscore_preprocess like EC2T or AWST and converts
|
3
|
+
// takes a substring from underscore_preprocess like EC2T or AWST and converts
|
4
|
+
// it to Ec2T or AwsT
|
4
5
|
static void format_substring(char* substr, const int substr_idx, const int capitalize)
|
5
6
|
{
|
6
7
|
int idx;
|
@@ -15,8 +16,8 @@ static void format_substring(char* substr, const int substr_idx, const int capit
|
|
15
16
|
}
|
16
17
|
}
|
17
18
|
|
18
|
-
// finds occurences of EC2Thing or AWSThing and makes them into Ec2Thing and
|
19
|
-
// simpler and just look for capitals
|
19
|
+
// finds occurences of EC2Thing or AWSThing and makes them into Ec2Thing and
|
20
|
+
// AwsThing so that underscore can be simpler and just look for capitals
|
20
21
|
static void preprocess(char* str)
|
21
22
|
{
|
22
23
|
char substr[strlen(str)];
|
@@ -41,7 +42,8 @@ static void preprocess(char* str)
|
|
41
42
|
}
|
42
43
|
}
|
43
44
|
|
44
|
-
// takes a string and returns a downcased version where capitals are now
|
45
|
+
// takes a string and returns a downcased version where capitals are now
|
46
|
+
// separated by underscores
|
45
47
|
static VALUE underscore(VALUE self, VALUE str)
|
46
48
|
{
|
47
49
|
if (TYPE(str) == T_NIL) return Qnil;
|
@@ -52,7 +54,8 @@ static VALUE underscore(VALUE self, VALUE str)
|
|
52
54
|
strcpy(orig_str, str_value);
|
53
55
|
preprocess(orig_str);
|
54
56
|
|
55
|
-
// manually null-terminating the string because on Fedora for strings of
|
57
|
+
// manually null-terminating the string because on Fedora for strings of
|
58
|
+
// length 16 this breaks otherwise
|
56
59
|
orig_str[strlen(str_value)] = '\0';
|
57
60
|
|
58
61
|
char new_str[strlen(orig_str) * 2];
|
data/lib/humidifier/aws_shim.rb
CHANGED
@@ -4,10 +4,8 @@ require 'humidifier/aws_adapters/sdkv1'
|
|
4
4
|
require 'humidifier/aws_adapters/sdkv2'
|
5
5
|
|
6
6
|
module Humidifier
|
7
|
-
|
8
7
|
# Optionally provides aws-sdk functionality if the gem is loaded
|
9
8
|
class AwsShim
|
10
|
-
|
11
9
|
# The AWS region, can be set through the environment, defaults to us-east-1
|
12
10
|
REGION = ENV['AWS_REGION'] || 'us-east-1'
|
13
11
|
|
data/lib/humidifier/condition.rb
CHANGED
data/lib/humidifier/fn.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Builds CFN function calls
|
4
3
|
class Fn
|
5
|
-
|
6
4
|
# The list of all internal functions provided by AWS from
|
7
5
|
# http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html
|
8
6
|
FUNCTIONS = Utils.underscored(%w[And Base64 Equals FindInMap GetAtt GetAZs
|
data/lib/humidifier/loader.rb
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
module Humidifier
|
2
|
-
# Pre-setting this module because AWS has a "Config" module and the below
|
3
|
-
# module to see whether or not it
|
2
|
+
# Pre-setting this module because AWS has a "Config" module and the below
|
3
|
+
# register method dynamically looks up the module to see whether or not it
|
4
|
+
# exists, which before ruby 2.2 would result in the warning:
|
4
5
|
# `const_defined?': Use RbConfig instead of obsolete and deprecated Config.
|
5
6
|
# @aws AWS::Config
|
6
7
|
module Config
|
7
8
|
end
|
8
9
|
|
9
|
-
# Reads the specs/CloudFormationResourceSpecification.json file and load each
|
10
|
+
# Reads the specs/CloudFormationResourceSpecification.json file and load each
|
11
|
+
# resource as a class
|
10
12
|
class Loader
|
11
13
|
# The path to the specification file
|
12
14
|
SPECPATH = File.expand_path(File.join('..', '..', '..', 'CloudFormationResourceSpecification.json'), __FILE__)
|
13
15
|
|
14
|
-
# Handles searching the PropertyTypes specifications for a specific
|
16
|
+
# Handles searching the PropertyTypes specifications for a specific
|
17
|
+
# resource type
|
15
18
|
class StructureContainer
|
16
19
|
attr_reader :structs
|
17
20
|
|
@@ -28,7 +31,7 @@ module Humidifier
|
|
28
31
|
private
|
29
32
|
|
30
33
|
def global
|
31
|
-
@global ||= structs.
|
34
|
+
@global ||= structs.reject { |key, _| key.match(/AWS/) }
|
32
35
|
end
|
33
36
|
end
|
34
37
|
|
@@ -54,10 +57,10 @@ module Humidifier
|
|
54
57
|
Class.new(Resource) do
|
55
58
|
self.aws_name = aws_name
|
56
59
|
self.props =
|
57
|
-
|
60
|
+
spec['Properties'].map do |(key, config)|
|
58
61
|
prop = Props.from(key, config, substructs)
|
59
62
|
[prop.name, prop]
|
60
|
-
end
|
63
|
+
end.to_h
|
61
64
|
end
|
62
65
|
end
|
63
66
|
|
data/lib/humidifier/mapping.rb
CHANGED
data/lib/humidifier/output.rb
CHANGED
data/lib/humidifier/parameter.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Represents a CFN stack parameter
|
4
3
|
class Parameter
|
5
|
-
|
6
4
|
# The allowed properties of all stack parameters
|
7
5
|
PROPERTIES = Utils.underscored(%w[AllowedPattern AllowedValues ConstraintDescription Default Description
|
8
6
|
MaxLength MaxValue MinLength MinValue NoEcho])
|
@@ -6,19 +6,16 @@ module Humidifier
|
|
6
6
|
|
7
7
|
# converts the value through mapping using the subprop unless it is valid
|
8
8
|
def convert(map)
|
9
|
-
valid?(map) ? map :
|
9
|
+
valid?(map) ? map : map.map { |key, value| [key, subprop.convert(value)] }.to_h
|
10
10
|
end
|
11
11
|
|
12
12
|
# CFN stack syntax
|
13
13
|
def to_cf(map)
|
14
|
-
|
15
|
-
Utils.enumerable_to_h(map) do |(subkey, subvalue)|
|
16
|
-
[subkey, subprop.to_cf(subvalue).last]
|
17
|
-
end
|
18
|
-
[key, dumped]
|
14
|
+
[key, map.map { |subkey, subvalue| [subkey, subprop.to_cf(subvalue).last] }.to_h]
|
19
15
|
end
|
20
16
|
|
21
|
-
# Valid if the value is whitelisted or every value in the map is valid on
|
17
|
+
# Valid if the value is whitelisted or every value in the map is valid on
|
18
|
+
# the subprop
|
22
19
|
def valid?(map)
|
23
20
|
whitelisted_value?(map) || (map.is_a?(Hash) && map.values.all? { |value| subprop.valid?(value) })
|
24
21
|
end
|
@@ -9,20 +9,16 @@ module Humidifier
|
|
9
9
|
if valid?(struct)
|
10
10
|
struct
|
11
11
|
else
|
12
|
-
|
12
|
+
struct.map do |subkey, subvalue|
|
13
13
|
subkey = Utils.underscore(subkey.to_s)
|
14
14
|
[subkey.to_sym, subprops[subkey].convert(subvalue)]
|
15
|
-
end
|
15
|
+
end.to_h
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
# CFN stack syntax
|
20
20
|
def to_cf(struct)
|
21
|
-
|
22
|
-
Utils.enumerable_to_h(struct) do |(subkey, subvalue)|
|
23
|
-
subprops[subkey.to_s].to_cf(subvalue)
|
24
|
-
end
|
25
|
-
[key, dumped]
|
21
|
+
[key, struct.map { |subkey, subvalue| subprops[subkey.to_s].to_cf(subvalue) }.to_h]
|
26
22
|
end
|
27
23
|
|
28
24
|
# true if the value is whitelisted or Hash and all keys are valid for their corresponding props
|
@@ -35,10 +31,10 @@ module Humidifier
|
|
35
31
|
def after_initialize(substructs)
|
36
32
|
type = spec['ItemType'] || spec['Type']
|
37
33
|
@subprops =
|
38
|
-
|
34
|
+
substructs.fetch(type, {}).fetch('Properties', {}).map do |key, config|
|
39
35
|
subprop = config['ItemType'] == type ? self : Props.from(key, config, substructs)
|
40
36
|
[Utils.underscore(key), subprop]
|
41
|
-
end
|
37
|
+
end.to_h
|
42
38
|
end
|
43
39
|
|
44
40
|
def valid_struct?(struct)
|
data/lib/humidifier/props.rb
CHANGED
data/lib/humidifier/ref.rb
CHANGED
data/lib/humidifier/resource.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Superclass for all AWS resources
|
4
3
|
class Resource
|
5
|
-
|
6
4
|
# Attributes that are available to every stack
|
7
5
|
COMMON_ATTRIBUTES =
|
8
6
|
Utils.underscored(%w[Condition CreationPolicy DeletionPolicy DependsOn Metadata UpdatePolicy])
|
@@ -35,7 +33,7 @@ module Humidifier
|
|
35
33
|
|
36
34
|
# CFN stack syntax
|
37
35
|
def to_cf
|
38
|
-
props_cf =
|
36
|
+
props_cf = properties.map { |key, value| self.class.props[key].to_cf(value) }.to_h
|
39
37
|
{ 'Type' => self.class.aws_name, 'Properties' => props_cf }.merge(common_attributes)
|
40
38
|
end
|
41
39
|
|
@@ -1,13 +1,11 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Dumps an object to CFN syntax
|
4
3
|
class Serializer
|
5
|
-
|
6
4
|
class << self
|
7
5
|
# dumps the given object out to CFN syntax recursively
|
8
6
|
def dump(node)
|
9
7
|
case node
|
10
|
-
when Hash then
|
8
|
+
when Hash then node.map { |key, value| [key, dump(value)] }.to_h
|
11
9
|
when Array then node.map { |value| dump(value) }
|
12
10
|
when Ref, Fn then dump(node.to_cf)
|
13
11
|
when Date then node.iso8601
|
data/lib/humidifier/sleeper.rb
CHANGED
data/lib/humidifier/stack.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Represents a CFN stack
|
4
3
|
class Stack
|
5
|
-
|
6
4
|
# Single settings on the stack
|
7
5
|
STATIC_RESOURCES = Utils.underscored(%w[AWSTemplateFormatVersion Description Metadata])
|
8
6
|
|
@@ -67,9 +65,10 @@ module Humidifier
|
|
67
65
|
ENUMERABLE_RESOURCES.each_with_object({}) do |(name, prop), list|
|
68
66
|
resources = send(prop)
|
69
67
|
next if resources.empty?
|
70
|
-
list[name] =
|
71
|
-
|
72
|
-
|
68
|
+
list[name] =
|
69
|
+
resources.map do |resource_name, resource|
|
70
|
+
[resource_name, resource.to_cf]
|
71
|
+
end.to_h
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
data/lib/humidifier/utils.rb
CHANGED
@@ -1,21 +1,9 @@
|
|
1
1
|
module Humidifier
|
2
|
-
|
3
2
|
# Dumps an object to CFN syntax
|
4
3
|
module Utils
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def enumerable_to_h(enumerable)
|
9
|
-
enumerable.each_with_object({}) do |item, result|
|
10
|
-
key, value = yield item
|
11
|
-
result[key] = value
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# a frozen hash of the given names mapped to their underscored version
|
16
|
-
def underscored(names)
|
17
|
-
names.each_with_object({}) { |name, map| map[name] = underscore(name).to_sym }.freeze
|
18
|
-
end
|
4
|
+
# a frozen hash of the given names mapped to their underscored version
|
5
|
+
def self.underscored(names)
|
6
|
+
names.map { |name| [name, underscore(name).to_sym] }.to_h.freeze
|
19
7
|
end
|
20
8
|
end
|
21
9
|
end
|
data/lib/humidifier/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: humidifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Localytics
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -196,7 +196,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
196
196
|
requirements:
|
197
197
|
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version: 2.
|
199
|
+
version: '2.1'
|
200
200
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
201
201
|
requirements:
|
202
202
|
- - ">="
|
@@ -204,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
204
204
|
version: '0'
|
205
205
|
requirements: []
|
206
206
|
rubyforge_project:
|
207
|
-
rubygems_version: 2.
|
207
|
+
rubygems_version: 2.6.8
|
208
208
|
signing_key:
|
209
209
|
specification_version: 4
|
210
210
|
summary: CloudFormation made easy
|