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.
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.0.0 and higher.
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.0 or later. From there, install the `bundler` gem: `gem install bundler` and then `bundle install` in the root of the repository.
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
 
@@ -1,6 +1,7 @@
1
1
  #include <humidifier.h>
2
2
 
3
- // takes a substring from underscore_preprocess like EC2T or AWST and converts it to Ec2T or AwsT
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 AwsThing so that underscore can be
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 separated by underscores
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 length 16 this breaks otherwise
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];
@@ -1,11 +1,8 @@
1
1
  module Humidifier
2
-
3
2
  # A container module for all adapters for the SDK
4
3
  module AwsAdapters
5
-
6
4
  # The parent class for the adapters for both versions of the SDK
7
5
  class Base
8
-
9
6
  # Create a CFN stack
10
7
  def create(payload)
11
8
  try_valid do
@@ -1,9 +1,7 @@
1
1
  module Humidifier
2
2
  module AwsAdapters
3
-
4
3
  # An adapter used when neither SDK is loaded
5
4
  class Noop
6
-
7
5
  # Capture all STACK_METHODS method calls and warn that they will not be run
8
6
  def method_missing(method, *)
9
7
  if AwsShim::STACK_METHODS.include?(method)
@@ -1,9 +1,7 @@
1
1
  module Humidifier
2
2
  module AwsAdapters
3
-
4
3
  # The adapter for v1 of aws-sdk
5
4
  class SDKV1 < Base
6
-
7
5
  # Cannot create change sets in V1
8
6
  def create_change_set(*)
9
7
  unsupported('create change set')
@@ -1,9 +1,7 @@
1
1
  module Humidifier
2
2
  module AwsAdapters
3
-
4
3
  # The adapter for v2 of aws-sdk
5
4
  class SDKV2 < Base
6
-
7
5
  # Create a change set in CFN
8
6
  def create_change_set(payload)
9
7
  payload.merge(change_set_name: "changeset-#{Time.now.strftime('%Y-%m-%d-%H-%M-%S')}")
@@ -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
 
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # Represents a CFN stack condition
4
3
  class Condition
5
-
6
4
  attr_accessor :opts
7
5
 
8
6
  def initialize(opts)
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # a container for user params
4
3
  class Configuration
5
-
6
4
  # The message that gets displayed when the stack body is too large to use
7
5
  # the template_body option
8
6
  UPLOAD_MESSAGE = <<-MSG.freeze
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
@@ -1,17 +1,20 @@
1
1
  module Humidifier
2
- # Pre-setting this module because AWS has a "Config" module and the below register method dynamically looks up the
3
- # module to see whether or not it exists, which before ruby 2.2 would result in the warning:
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 resource as a class
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 resource type
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.select { |key, _| !key.match(/AWS/) }
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
- Utils.enumerable_to_h(spec['Properties']) do |(key, config)|
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
 
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # Represents a CFN stack mapping
4
3
  class Mapping
5
-
6
4
  attr_accessor :opts
7
5
 
8
6
  def initialize(opts = {})
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # Represents a CFN stack output
4
3
  class Output
5
-
6
4
  attr_accessor :description, :value
7
5
 
8
6
  def initialize(opts = {})
@@ -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])
@@ -2,7 +2,6 @@ module Humidifier
2
2
  module Props
3
3
  # Superclass for all CFN properties
4
4
  class Base
5
-
6
5
  # The list of classes that are valid beyond the normal values for each prop
7
6
  WHITELIST = [Fn, Ref].freeze
8
7
 
@@ -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 : Utils.enumerable_to_h(map) { |(key, value)| [key, subprop.convert(value)] }
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
- dumped =
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 the subprop
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
- Utils.enumerable_to_h(struct) do |(subkey, subvalue)|
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
- dumped =
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
- Utils.enumerable_to_h(substructs.fetch(type, {}).fetch('Properties', {})) do |(key, config)|
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)
@@ -1,5 +1,4 @@
1
1
  module Humidifier
2
-
3
2
  # Container for property of CFN resources
4
3
  module Props
5
4
  class << self
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # Builds CFN references
4
3
  class Ref
5
-
6
4
  attr_accessor :reference
7
5
 
8
6
  def initialize(reference)
@@ -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 = Utils.enumerable_to_h(properties) { |(key, value)| self.class.props[key].to_cf(value) }
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,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # The payload sent to the shim methods, representing the stack and the options
4
3
  class SdkPayload
5
-
6
4
  # The maximum size a template body can be before it has to be put somewhere and referenced through a URL
7
5
  MAX_TEMPLATE_BODY_SIZE = 51_200
8
6
 
@@ -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 Utils.enumerable_to_h(node) { |(key, value)| [key, dump(value)] }
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
@@ -1,8 +1,6 @@
1
1
  module Humidifier
2
-
3
2
  # Manages waiting for stack events for v1 of the SDK
4
3
  class Sleeper
5
-
6
4
  attr_accessor :attempts
7
5
 
8
6
  # Store attempts and wait for the block to return true
@@ -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] = Utils.enumerable_to_h(resources) do |resource_name, resource|
71
- [resource_name, resource.to_cf]
72
- end
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
 
@@ -1,21 +1,9 @@
1
1
  module Humidifier
2
-
3
2
  # Dumps an object to CFN syntax
4
3
  module Utils
5
-
6
- class << self
7
- # back-supporting ruby 2.0's lack of Enumerable#to_h
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
@@ -1,4 +1,4 @@
1
1
  module Humidifier
2
2
  # Gem version
3
- VERSION = '1.0.6'.freeze
3
+ VERSION = '1.2.1'.freeze
4
4
  end
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.0.6
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: 2016-12-12 00:00:00.000000000 Z
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.0.0
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.5.1
207
+ rubygems_version: 2.6.8
208
208
  signing_key:
209
209
  specification_version: 4
210
210
  summary: CloudFormation made easy