aws_provisioner 0.0.2
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +50 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +6 -0
- data/aws_provisioner.gemspec +40 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/aws_provisioner/dsl.rb +45 -0
- data/lib/aws_provisioner/extensions.rb +7 -0
- data/lib/aws_provisioner/properties.rb +126 -0
- data/lib/aws_provisioner/resource.rb +21 -0
- data/lib/aws_provisioner/runtime.rb +11 -0
- data/lib/aws_provisioner/template.rb +48 -0
- data/lib/aws_provisioner/version.rb +3 -0
- data/lib/aws_provisioner.rb +8 -0
- metadata +139 -0
    
        checksums.yaml
    ADDED
    
    | @@ -0,0 +1,7 @@ | |
| 1 | 
            +
            ---
         | 
| 2 | 
            +
            SHA256:
         | 
| 3 | 
            +
              metadata.gz: 1e02bb3f17568a4e08393c42abd39fdd819ca309478b08782d818b6dc9272ea5
         | 
| 4 | 
            +
              data.tar.gz: e350bb232a463f93d4fb9e070a53b67bef970a45b27a04b06c8f7378cebba410
         | 
| 5 | 
            +
            SHA512:
         | 
| 6 | 
            +
              metadata.gz: 74e1ec3fd2569616c44459941668818fe2e2e6798f516ee7036cb9f72e3b5e4d35f004f342eacce4571df9ee035bc20f9bb9ef5c0048917ea8336f8da7bc1f6f
         | 
| 7 | 
            +
              data.tar.gz: e03b3ca9b65b716ca8e4b7be68512f11de656bab9f49e3638c0ba5202698b3e5931e916a5f88defad85b45de85acac8f8e8f55bd3b6d1fd38e103dcddd027096
         | 
    
        data/.gitignore
    ADDED
    
    
    
        data/.rspec
    ADDED
    
    
    
        data/.travis.yml
    ADDED
    
    
    
        data/Gemfile
    ADDED
    
    
    
        data/Gemfile.lock
    ADDED
    
    | @@ -0,0 +1,50 @@ | |
| 1 | 
            +
            PATH
         | 
| 2 | 
            +
              remote: .
         | 
| 3 | 
            +
              specs:
         | 
| 4 | 
            +
                aws_provisioner (0.1.0)
         | 
| 5 | 
            +
                  activesupport (~> 5.2, >= 5.2.1)
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            GEM
         | 
| 8 | 
            +
              remote: https://rubygems.org/
         | 
| 9 | 
            +
              specs:
         | 
| 10 | 
            +
                activesupport (5.2.1)
         | 
| 11 | 
            +
                  concurrent-ruby (~> 1.0, >= 1.0.2)
         | 
| 12 | 
            +
                  i18n (>= 0.7, < 2)
         | 
| 13 | 
            +
                  minitest (~> 5.1)
         | 
| 14 | 
            +
                  tzinfo (~> 1.1)
         | 
| 15 | 
            +
                byebug (10.0.2)
         | 
| 16 | 
            +
                concurrent-ruby (1.0.5)
         | 
| 17 | 
            +
                diff-lcs (1.3)
         | 
| 18 | 
            +
                i18n (1.1.1)
         | 
| 19 | 
            +
                  concurrent-ruby (~> 1.0)
         | 
| 20 | 
            +
                minitest (5.11.3)
         | 
| 21 | 
            +
                rake (10.5.0)
         | 
| 22 | 
            +
                rspec (3.8.0)
         | 
| 23 | 
            +
                  rspec-core (~> 3.8.0)
         | 
| 24 | 
            +
                  rspec-expectations (~> 3.8.0)
         | 
| 25 | 
            +
                  rspec-mocks (~> 3.8.0)
         | 
| 26 | 
            +
                rspec-core (3.8.0)
         | 
| 27 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 28 | 
            +
                rspec-expectations (3.8.1)
         | 
| 29 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 30 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 31 | 
            +
                rspec-mocks (3.8.0)
         | 
| 32 | 
            +
                  diff-lcs (>= 1.2.0, < 2.0)
         | 
| 33 | 
            +
                  rspec-support (~> 3.8.0)
         | 
| 34 | 
            +
                rspec-support (3.8.0)
         | 
| 35 | 
            +
                thread_safe (0.3.6)
         | 
| 36 | 
            +
                tzinfo (1.2.5)
         | 
| 37 | 
            +
                  thread_safe (~> 0.1)
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            PLATFORMS
         | 
| 40 | 
            +
              ruby
         | 
| 41 | 
            +
             | 
| 42 | 
            +
            DEPENDENCIES
         | 
| 43 | 
            +
              aws_provisioner!
         | 
| 44 | 
            +
              bundler (~> 1.16)
         | 
| 45 | 
            +
              byebug (~> 10.0)
         | 
| 46 | 
            +
              rake (~> 10.0)
         | 
| 47 | 
            +
              rspec (~> 3.0)
         | 
| 48 | 
            +
             | 
| 49 | 
            +
            BUNDLED WITH
         | 
| 50 | 
            +
               1.16.2
         | 
    
        data/LICENSE.txt
    ADDED
    
    | @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            The MIT License (MIT)
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Copyright (c) 2018 Wilberto Morales
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            Permission is hereby granted, free of charge, to any person obtaining a copy
         | 
| 6 | 
            +
            of this software and associated documentation files (the "Software"), to deal
         | 
| 7 | 
            +
            in the Software without restriction, including without limitation the rights
         | 
| 8 | 
            +
            to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         | 
| 9 | 
            +
            copies of the Software, and to permit persons to whom the Software is
         | 
| 10 | 
            +
            furnished to do so, subject to the following conditions:
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            The above copyright notice and this permission notice shall be included in
         | 
| 13 | 
            +
            all copies or substantial portions of the Software.
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         | 
| 16 | 
            +
            IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         | 
| 17 | 
            +
            FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         | 
| 18 | 
            +
            AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         | 
| 19 | 
            +
            LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         | 
| 20 | 
            +
            OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
         | 
| 21 | 
            +
            THE SOFTWARE.
         | 
    
        data/README.md
    ADDED
    
    | @@ -0,0 +1,39 @@ | |
| 1 | 
            +
            # AwsProvisioner
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/aws_provisioner`. To experiment with that code, run `bin/console` for an interactive prompt.
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            TODO: Delete this and the text above, and describe your gem
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            ## Installation
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            Add this line to your application's Gemfile:
         | 
| 10 | 
            +
             | 
| 11 | 
            +
            ```ruby
         | 
| 12 | 
            +
            gem 'aws_provisioner'
         | 
| 13 | 
            +
            ```
         | 
| 14 | 
            +
             | 
| 15 | 
            +
            And then execute:
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                $ bundle
         | 
| 18 | 
            +
             | 
| 19 | 
            +
            Or install it yourself as:
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                $ gem install aws_provisioner
         | 
| 22 | 
            +
             | 
| 23 | 
            +
            ## Usage
         | 
| 24 | 
            +
             | 
| 25 | 
            +
            TODO: Write usage instructions here
         | 
| 26 | 
            +
             | 
| 27 | 
            +
            ## Development
         | 
| 28 | 
            +
             | 
| 29 | 
            +
            After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
         | 
| 30 | 
            +
             | 
| 31 | 
            +
            To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
         | 
| 32 | 
            +
             | 
| 33 | 
            +
            ## Contributing
         | 
| 34 | 
            +
             | 
| 35 | 
            +
            Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_provisioner.
         | 
| 36 | 
            +
             | 
| 37 | 
            +
            ## License
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
         | 
    
        data/Rakefile
    ADDED
    
    
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
             | 
| 2 | 
            +
            lib = File.expand_path("../lib", __FILE__)
         | 
| 3 | 
            +
            $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
         | 
| 4 | 
            +
            require "aws_provisioner/version"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            Gem::Specification.new do |spec|
         | 
| 7 | 
            +
              spec.name          = "aws_provisioner"
         | 
| 8 | 
            +
              spec.version       = AwsProvisioner::VERSION
         | 
| 9 | 
            +
              spec.authors       = ["Wilberto Morales"]
         | 
| 10 | 
            +
              spec.email         = ["wil@coquisystems.com"]
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              spec.summary       = "A DSL that compiles to AWS CloudFormation and provisions AWS resources."
         | 
| 13 | 
            +
              # spec.description   = %q{Write a longer description or delete this line.}
         | 
| 14 | 
            +
              # spec.homepage      = "TODO: Put your gem's website or public repo URL here."
         | 
| 15 | 
            +
              spec.license       = "MIT"
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
         | 
| 18 | 
            +
              # to allow pushing to a single host or delete this section to allow pushing to any host.
         | 
| 19 | 
            +
              if spec.respond_to?(:metadata)
         | 
| 20 | 
            +
                # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
         | 
| 21 | 
            +
              else
         | 
| 22 | 
            +
                raise "RubyGems 2.0 or newer is required to protect against " \
         | 
| 23 | 
            +
                  "public gem pushes."
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              # Specify which files should be added to the gem when it is released.
         | 
| 27 | 
            +
              # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
         | 
| 28 | 
            +
              spec.files         = Dir.chdir(File.expand_path('..', __FILE__)) do
         | 
| 29 | 
            +
                `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
              spec.bindir        = "exe"
         | 
| 32 | 
            +
              spec.executables   = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
         | 
| 33 | 
            +
              spec.require_paths = ["lib"]
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              spec.add_dependency 'activesupport', '~> 5.2', '>= 5.2.1'
         | 
| 36 | 
            +
              spec.add_development_dependency "bundler", "~> 1.16"
         | 
| 37 | 
            +
              spec.add_development_dependency "rake", "~> 10.0"
         | 
| 38 | 
            +
              spec.add_development_dependency "rspec", "~> 3.0"
         | 
| 39 | 
            +
              spec.add_development_dependency "byebug", "~> 10.0"
         | 
| 40 | 
            +
            end
         | 
    
        data/bin/console
    ADDED
    
    | @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require "bundler/setup"
         | 
| 4 | 
            +
            require "aws_provisioner"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            # You can add fixtures and/or initialization code here to make experimenting
         | 
| 7 | 
            +
            # with your gem easier. You can also use a different console, if you like.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
            # (If you use this, don't forget to add pry to your Gemfile!)
         | 
| 10 | 
            +
            # require "pry"
         | 
| 11 | 
            +
            # Pry.start
         | 
| 12 | 
            +
             | 
| 13 | 
            +
            require "irb"
         | 
| 14 | 
            +
            IRB.start(__FILE__)
         | 
    
        data/bin/setup
    ADDED
    
    
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            require_relative 'runtime'
         | 
| 2 | 
            +
            require_relative 'template'
         | 
| 3 | 
            +
            require_relative 'resource'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            module AwsProvisioner
         | 
| 6 | 
            +
              module DSL
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                private
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def self.translate_resource_type(resource_type)
         | 
| 11 | 
            +
                  type = resource_type
         | 
| 12 | 
            +
                    .to_s
         | 
| 13 | 
            +
                    .split('_')
         | 
| 14 | 
            +
                    .map { |part| self.translate_resource_part_name(part) }
         | 
| 15 | 
            +
                    .join('::')
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                  "AWS::#{type}"
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                def self.translate_resource_part_name(part)
         | 
| 21 | 
            +
                  if part == 'ec2'
         | 
| 22 | 
            +
                    'EC2'
         | 
| 23 | 
            +
                  else
         | 
| 24 | 
            +
                    part.camelize
         | 
| 25 | 
            +
                  end
         | 
| 26 | 
            +
                end
         | 
| 27 | 
            +
              end
         | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
            def template(name=nil, description: nil, &block)
         | 
| 31 | 
            +
              t = AwsProvisioner::Template.new(name, description: description)
         | 
| 32 | 
            +
             | 
| 33 | 
            +
              t.instance_eval(&block)
         | 
| 34 | 
            +
              AwsProvisioner::Runtime.templates << t
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              t
         | 
| 37 | 
            +
            end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
            def resource(resource_type, name, &block)
         | 
| 40 | 
            +
              aws_type = AwsProvisioner::DSL.translate_resource_type(resource_type)
         | 
| 41 | 
            +
              r = AwsProvisioner::Resource.new(aws_type, name, {})
         | 
| 42 | 
            +
              r.properties.instance_eval(&block)
         | 
| 43 | 
            +
             | 
| 44 | 
            +
              r
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,126 @@ | |
| 1 | 
            +
            module AwsProvisioner
         | 
| 2 | 
            +
              class Properties
         | 
| 3 | 
            +
                attr_reader :properties
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(hash={})
         | 
| 6 | 
            +
                  @properties = hash.reduce({}) do |acc, entry|
         | 
| 7 | 
            +
                    key, value = entry
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    if value.instance_of?(Hash)
         | 
| 10 | 
            +
                      acc[key] = Properties.new(value)
         | 
| 11 | 
            +
                    else
         | 
| 12 | 
            +
                      acc[key] = value
         | 
| 13 | 
            +
                    end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    acc
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                def empty?
         | 
| 20 | 
            +
                  @properties.empty?
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def rename
         | 
| 24 | 
            +
                  renamed_properties = @properties.reduce({}) do |acc, entry|
         | 
| 25 | 
            +
                    key, value = entry
         | 
| 26 | 
            +
                    template_key = template_name(key)
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                    if value.instance_of? self.class
         | 
| 29 | 
            +
                      acc[template_key] = value.rename
         | 
| 30 | 
            +
                    else
         | 
| 31 | 
            +
                      acc[template_key] = value
         | 
| 32 | 
            +
                    end
         | 
| 33 | 
            +
             | 
| 34 | 
            +
                    acc
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  Properties.new(renamed_properties)
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def to_t
         | 
| 41 | 
            +
                  self.rename.reformat_keys.to_h
         | 
| 42 | 
            +
                end
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                def reformat_keys
         | 
| 45 | 
            +
                  # TODO: rename and make private
         | 
| 46 | 
            +
                  @properties.reduce({}) do |acc, entry|
         | 
| 47 | 
            +
                    key, value = entry
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    if value.instance_of? self.class
         | 
| 50 | 
            +
                      acc[key.to_s] = value.reformat_keys
         | 
| 51 | 
            +
                    else
         | 
| 52 | 
            +
                      acc[key.to_s] = value
         | 
| 53 | 
            +
                    end
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    acc
         | 
| 56 | 
            +
                  end
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                def to_h
         | 
| 60 | 
            +
                  @properties.reduce({}) do |acc, property|
         | 
| 61 | 
            +
                    key, value = property
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                    if value.instance_of? self.class
         | 
| 64 | 
            +
                      acc[key] = value.to_h
         | 
| 65 | 
            +
                    else
         | 
| 66 | 
            +
                      acc[key] = value
         | 
| 67 | 
            +
                    end
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                    acc
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
                private
         | 
| 74 | 
            +
             | 
| 75 | 
            +
                def method_missing(m, *args, &block)
         | 
| 76 | 
            +
                  if @properties.include? m
         | 
| 77 | 
            +
                      return @properties[m]
         | 
| 78 | 
            +
                  elsif assignment?(m, args, block)
         | 
| 79 | 
            +
                      return assign(m, args, block)
         | 
| 80 | 
            +
                  else
         | 
| 81 | 
            +
                    property = Properties.new
         | 
| 82 | 
            +
                    @properties[m] = property
         | 
| 83 | 
            +
                    return property
         | 
| 84 | 
            +
                  end
         | 
| 85 | 
            +
                end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
                def assign(m, args, block)
         | 
| 88 | 
            +
                  # require 'byebug'; byebug
         | 
| 89 | 
            +
                  if standard_assignment?(m, args, block)
         | 
| 90 | 
            +
                    attribute = m.to_s[0...-1].to_sym
         | 
| 91 | 
            +
                    @properties[attribute] = args.first
         | 
| 92 | 
            +
                  elsif dsl_simple_assignment?(m, args, block)
         | 
| 93 | 
            +
                    attribute = m
         | 
| 94 | 
            +
                    @properties[attribute] = args.first
         | 
| 95 | 
            +
                  elsif dsl_nested_assignment?(m, args, block)
         | 
| 96 | 
            +
                    attribute = m
         | 
| 97 | 
            +
                    self.send("#{attribute}").instance_eval(&block)
         | 
| 98 | 
            +
                  end
         | 
| 99 | 
            +
                end
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                def assignment?(m, args, block)
         | 
| 102 | 
            +
                   standard_assignment?(m, args, block) \
         | 
| 103 | 
            +
                    or dsl_simple_assignment?(m, args, block) \
         | 
| 104 | 
            +
                    or dsl_nested_assignment?(m, args, block)
         | 
| 105 | 
            +
                end
         | 
| 106 | 
            +
             | 
| 107 | 
            +
                def standard_assignment?(m, _args, _block)
         | 
| 108 | 
            +
                  # example: properties.something = 20
         | 
| 109 | 
            +
                  m.to_s.end_with?('=')
         | 
| 110 | 
            +
                end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                def dsl_simple_assignment?(_m, args, _block)
         | 
| 113 | 
            +
                  # example: properties.instance_eval { something 20 }
         | 
| 114 | 
            +
                  !args.first.nil?
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
                def dsl_nested_assignment?(_m, _args, block)
         | 
| 118 | 
            +
                  # example: properties.instance_eval { something { else 20 } }
         | 
| 119 | 
            +
                  !block.nil?
         | 
| 120 | 
            +
                end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
                def template_name(key)
         | 
| 123 | 
            +
                   key.camelize.to_sym
         | 
| 124 | 
            +
                end
         | 
| 125 | 
            +
              end
         | 
| 126 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            require_relative 'extensions'
         | 
| 2 | 
            +
            require_relative 'properties'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module AwsProvisioner
         | 
| 5 | 
            +
              class Resource
         | 
| 6 | 
            +
                attr_reader :name, :properties, :type
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                def initialize(type, name, hash={})
         | 
| 9 | 
            +
                  @name = name or raise ArgumentError
         | 
| 10 | 
            +
                  @properties = Properties.new(hash)
         | 
| 11 | 
            +
                  @type = type
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                def to_h
         | 
| 15 | 
            +
                  h  = properties.to_t
         | 
| 16 | 
            +
                  h["Type"] = type
         | 
| 17 | 
            +
             | 
| 18 | 
            +
                  h
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,48 @@ | |
| 1 | 
            +
            require 'json'
         | 
| 2 | 
            +
            require 'yaml'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            module AwsProvisioner
         | 
| 5 | 
            +
              class Template
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_accessor :name
         | 
| 8 | 
            +
                attr_reader :format_version, :description, :resources
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                def initialize(name=nil, description: nil)
         | 
| 11 | 
            +
                  @format_version = "2010-09-09"
         | 
| 12 | 
            +
                  @description = description
         | 
| 13 | 
            +
                  @resources = []
         | 
| 14 | 
            +
                  @name = name
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def add(resource)
         | 
| 18 | 
            +
                  resources << resource
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                def to_h
         | 
| 22 | 
            +
                  {
         | 
| 23 | 
            +
                    "AWSTemplateFormatVersion" => format_version,
         | 
| 24 | 
            +
                    "Description" => description,
         | 
| 25 | 
            +
                    "Resources" => resources_to_h,
         | 
| 26 | 
            +
                  }
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def compile(format)
         | 
| 30 | 
            +
                  case format
         | 
| 31 | 
            +
                  when :json
         | 
| 32 | 
            +
                    JSON.pretty_generate(to_h)
         | 
| 33 | 
            +
                  when :yaml
         | 
| 34 | 
            +
                    YAML.dump(to_h)
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                private
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                def resources_to_h
         | 
| 41 | 
            +
                  resources.reduce({}) do |acc, resource|
         | 
| 42 | 
            +
                    acc[resource.name] = resource.to_h
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                    acc
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
                end
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
            end
         | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,139 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: aws_provisioner
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.2
         | 
| 5 | 
            +
            platform: ruby
         | 
| 6 | 
            +
            authors:
         | 
| 7 | 
            +
            - Wilberto Morales
         | 
| 8 | 
            +
            autorequire: 
         | 
| 9 | 
            +
            bindir: exe
         | 
| 10 | 
            +
            cert_chain: []
         | 
| 11 | 
            +
            date: 2018-10-30 00:00:00.000000000 Z
         | 
| 12 | 
            +
            dependencies:
         | 
| 13 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 14 | 
            +
              name: activesupport
         | 
| 15 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 16 | 
            +
                requirements:
         | 
| 17 | 
            +
                - - "~>"
         | 
| 18 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 19 | 
            +
                    version: '5.2'
         | 
| 20 | 
            +
                - - ">="
         | 
| 21 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            +
                    version: 5.2.1
         | 
| 23 | 
            +
              type: :runtime
         | 
| 24 | 
            +
              prerelease: false
         | 
| 25 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 26 | 
            +
                requirements:
         | 
| 27 | 
            +
                - - "~>"
         | 
| 28 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 29 | 
            +
                    version: '5.2'
         | 
| 30 | 
            +
                - - ">="
         | 
| 31 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            +
                    version: 5.2.1
         | 
| 33 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 34 | 
            +
              name: bundler
         | 
| 35 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 36 | 
            +
                requirements:
         | 
| 37 | 
            +
                - - "~>"
         | 
| 38 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 39 | 
            +
                    version: '1.16'
         | 
| 40 | 
            +
              type: :development
         | 
| 41 | 
            +
              prerelease: false
         | 
| 42 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 43 | 
            +
                requirements:
         | 
| 44 | 
            +
                - - "~>"
         | 
| 45 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 46 | 
            +
                    version: '1.16'
         | 
| 47 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 48 | 
            +
              name: rake
         | 
| 49 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 50 | 
            +
                requirements:
         | 
| 51 | 
            +
                - - "~>"
         | 
| 52 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 53 | 
            +
                    version: '10.0'
         | 
| 54 | 
            +
              type: :development
         | 
| 55 | 
            +
              prerelease: false
         | 
| 56 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 57 | 
            +
                requirements:
         | 
| 58 | 
            +
                - - "~>"
         | 
| 59 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 60 | 
            +
                    version: '10.0'
         | 
| 61 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 62 | 
            +
              name: rspec
         | 
| 63 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 64 | 
            +
                requirements:
         | 
| 65 | 
            +
                - - "~>"
         | 
| 66 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 67 | 
            +
                    version: '3.0'
         | 
| 68 | 
            +
              type: :development
         | 
| 69 | 
            +
              prerelease: false
         | 
| 70 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
                requirements:
         | 
| 72 | 
            +
                - - "~>"
         | 
| 73 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 74 | 
            +
                    version: '3.0'
         | 
| 75 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 76 | 
            +
              name: byebug
         | 
| 77 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 78 | 
            +
                requirements:
         | 
| 79 | 
            +
                - - "~>"
         | 
| 80 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 81 | 
            +
                    version: '10.0'
         | 
| 82 | 
            +
              type: :development
         | 
| 83 | 
            +
              prerelease: false
         | 
| 84 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 85 | 
            +
                requirements:
         | 
| 86 | 
            +
                - - "~>"
         | 
| 87 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 88 | 
            +
                    version: '10.0'
         | 
| 89 | 
            +
            description: 
         | 
| 90 | 
            +
            email:
         | 
| 91 | 
            +
            - wil@coquisystems.com
         | 
| 92 | 
            +
            executables: []
         | 
| 93 | 
            +
            extensions: []
         | 
| 94 | 
            +
            extra_rdoc_files: []
         | 
| 95 | 
            +
            files:
         | 
| 96 | 
            +
            - ".gitignore"
         | 
| 97 | 
            +
            - ".rspec"
         | 
| 98 | 
            +
            - ".travis.yml"
         | 
| 99 | 
            +
            - Gemfile
         | 
| 100 | 
            +
            - Gemfile.lock
         | 
| 101 | 
            +
            - LICENSE.txt
         | 
| 102 | 
            +
            - README.md
         | 
| 103 | 
            +
            - Rakefile
         | 
| 104 | 
            +
            - aws_provisioner.gemspec
         | 
| 105 | 
            +
            - bin/console
         | 
| 106 | 
            +
            - bin/setup
         | 
| 107 | 
            +
            - lib/aws_provisioner.rb
         | 
| 108 | 
            +
            - lib/aws_provisioner/dsl.rb
         | 
| 109 | 
            +
            - lib/aws_provisioner/extensions.rb
         | 
| 110 | 
            +
            - lib/aws_provisioner/properties.rb
         | 
| 111 | 
            +
            - lib/aws_provisioner/resource.rb
         | 
| 112 | 
            +
            - lib/aws_provisioner/runtime.rb
         | 
| 113 | 
            +
            - lib/aws_provisioner/template.rb
         | 
| 114 | 
            +
            - lib/aws_provisioner/version.rb
         | 
| 115 | 
            +
            homepage: 
         | 
| 116 | 
            +
            licenses:
         | 
| 117 | 
            +
            - MIT
         | 
| 118 | 
            +
            metadata: {}
         | 
| 119 | 
            +
            post_install_message: 
         | 
| 120 | 
            +
            rdoc_options: []
         | 
| 121 | 
            +
            require_paths:
         | 
| 122 | 
            +
            - lib
         | 
| 123 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 124 | 
            +
              requirements:
         | 
| 125 | 
            +
              - - ">="
         | 
| 126 | 
            +
                - !ruby/object:Gem::Version
         | 
| 127 | 
            +
                  version: '0'
         | 
| 128 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 129 | 
            +
              requirements:
         | 
| 130 | 
            +
              - - ">="
         | 
| 131 | 
            +
                - !ruby/object:Gem::Version
         | 
| 132 | 
            +
                  version: '0'
         | 
| 133 | 
            +
            requirements: []
         | 
| 134 | 
            +
            rubyforge_project: 
         | 
| 135 | 
            +
            rubygems_version: 2.7.7
         | 
| 136 | 
            +
            signing_key: 
         | 
| 137 | 
            +
            specification_version: 4
         | 
| 138 | 
            +
            summary: A DSL that compiles to AWS CloudFormation and provisions AWS resources.
         | 
| 139 | 
            +
            test_files: []
         |