Permalink
Browse files

initial commit

  • Loading branch information...
kddeisz committed Apr 4, 2016
0 parents commit f05157832951fe43755ecb27e4b23ffd66eb9184
Showing with 1,783 additions and 0 deletions.
  1. +9 −0 .gitignore
  2. +4 −0 .travis.yml
  3. +3 −0 Gemfile
  4. +21 −0 LICENSE.txt
  5. +41 −0 README.md
  6. +10 −0 Rakefile
  7. +35 −0 aws_cf.gemspec
  8. +7 −0 bin/console
  9. +23 −0 bin/get-docs
  10. +13 −0 lib/aws_cf.rb
  11. +23 −0 lib/aws_cf/parser.rb
  12. +28 −0 lib/aws_cf/props.rb
  13. +18 −0 lib/aws_cf/props/array_prop.rb
  14. +27 −0 lib/aws_cf/props/base.rb
  15. +9 −0 lib/aws_cf/props/boolean_prop.rb
  16. +9 −0 lib/aws_cf/props/integer_prop.rb
  17. +9 −0 lib/aws_cf/props/string_prop.rb
  18. +53 −0 lib/aws_cf/resource.rb
  19. +3 −0 lib/aws_cf/version.rb
  20. +21 −0 specs/AutoScaling-AutoScalingGroup.cf
  21. +22 −0 specs/AutoScaling-LaunchConfiguration.cf
  22. +12 −0 specs/AutoScaling-LifecycleHook.cf
  23. +14 −0 specs/AutoScaling-ScalingPolicy.cf
  24. +12 −0 specs/AutoScaling-ScheduledAction.cf
  25. +8 −0 specs/CloudFormation-CustomResource.cf
  26. +10 −0 specs/CloudFormation-Stack.cf
  27. +8 −0 specs/CloudFormation-WaitCondition.cf
  28. +5 −0 specs/CloudFormation-WaitConditionHandle.cf
  29. +6 −0 specs/CloudFront-Distribution.cf
  30. +16 −0 specs/CloudTrail-Trail.cf
  31. +20 −0 specs/CloudWatch-Alarm.cf
  32. +6 −0 specs/CodeDeploy-Application.cf
  33. +7 −0 specs/CodeDeploy-DeploymentConfig.cf
  34. +13 −0 specs/CodeDeploy-DeploymentGroup.cf
  35. +12 −0 specs/CodePipeline-CustomActionType.cf
  36. +11 −0 specs/CodePipeline-Pipeline.cf
  37. +11 −0 specs/Config-ConfigRule.cf
  38. +8 −0 specs/Config-ConfigurationRecorder.cf
  39. +10 −0 specs/Config-DeliveryChannel.cf
  40. +12 −0 specs/DataPipeline-Pipeline.cf
  41. +11 −0 specs/DirectoryService-MicrosoftAD.cf
  42. +13 −0 specs/DirectoryService-SimpleAD.cf
  43. +12 −0 specs/DynamoDB-Table.cf
  44. +9 −0 specs/EC2-CustomerGateway.cf
  45. +11 −0 specs/EC2-DHCPOptions.cf
  46. +7 −0 specs/EC2-EIP.cf
  47. +10 −0 specs/EC2-EIPAssociation.cf
  48. +30 −0 specs/EC2-Instance.cf
  49. +6 −0 specs/EC2-InternetGateway.cf
  50. +7 −0 specs/EC2-NatGateway.cf
  51. +7 −0 specs/EC2-NetworkAcl.cf
  52. +13 −0 specs/EC2-NetworkAclEntry.cf
  53. +13 −0 specs/EC2-NetworkInterface.cf
  54. +9 −0 specs/EC2-NetworkInterfaceAttachment.cf
  55. +6 −0 specs/EC2-PlacementGroup.cf
  56. +12 −0 specs/EC2-Route.cf
  57. +7 −0 specs/EC2-RouteTable.cf
  58. +10 −0 specs/EC2-SecurityGroup.cf
  59. +6 −0 specs/EC2-SpotFleet.cf
  60. +10 −0 specs/EC2-Subnet.cf
  61. +5 −0 specs/EC2-SubnetNetworkAclAssociation.cf
  62. +7 −0 specs/EC2-SubnetRouteTableAssociation.cf
  63. +10 −0 specs/EC2-VPC.cf
  64. +7 −0 specs/EC2-VPCDHCPOptionsAssociation.cf
  65. +9 −0 specs/EC2-VPCEndpoint.cf
  66. +8 −0 specs/EC2-VPCGatewayAttachment.cf
  67. +8 −0 specs/EC2-VPCPeeringConnection.cf
  68. +10 −0 specs/EC2-VPNConnection.cf
  69. +7 −0 specs/EC2-VPNConnectionRoute.cf
  70. +7 −0 specs/EC2-VPNGateway.cf
  71. +7 −0 specs/EC2-VPNGatewayRoutePropagation.cf
  72. +14 −0 specs/EC2-Volume.cf
  73. +8 −0 specs/EC2-VolumeAttachment.cf
  74. +7 −0 specs/ECR-Repository.cf
  75. +10 −0 specs/ECS-Service.cf
  76. +7 −0 specs/ECS-TaskDefinition.cf
  77. +6 −0 specs/EFS-FileSystem.cf
  78. +9 −0 specs/EFS-MountTarget.cf
  79. +18 −0 specs/EMR-Cluster.cf
  80. +14 −0 specs/EMR-InstanceGroupConfig.cf
  81. +9 −0 specs/EMR-Step.cf
  82. +27 −0 specs/ElastiCache-CacheCluster.cf
  83. +8 −0 specs/ElastiCache-ParameterGroup.cf
  84. +23 −0 specs/ElastiCache-ReplicationGroup.cf
  85. +7 −0 specs/ElastiCache-SecurityGroup.cf
  86. +9 −0 specs/ElastiCache-SecurityGroupIngress.cf
  87. +7 −0 specs/ElastiCache-SubnetGroup.cf
  88. +7 −0 specs/ElasticBeanstalk-Application.cf
  89. +8 −0 specs/ElasticBeanstalk-ApplicationVersion.cf
  90. +11 −0 specs/ElasticBeanstalk-ConfigurationTemplate.cf
  91. +15 −0 specs/ElasticBeanstalk-Environment.cf
  92. +21 −0 specs/ElasticLoadBalancing-LoadBalancer.cf
  93. +12 −0 specs/Elasticsearch-Domain.cf
  94. +8 −0 specs/GameLift-Alias.cf
  95. +8 −0 specs/GameLift-Build.cf
  96. +14 −0 specs/GameLift-Fleet.cf
  97. +8 −0 specs/IAM-AccessKey.cf
  98. +8 −0 specs/IAM-Group.cf
  99. +7 −0 specs/IAM-InstanceProfile.cf
  100. +11 −0 specs/IAM-ManagedPolicy.cf
  101. +10 −0 specs/IAM-Policy.cf
  102. +9 −0 specs/IAM-Role.cf
  103. +10 −0 specs/IAM-User.cf
  104. +7 −0 specs/IAM-UserToGroupAddition.cf
  105. +9 −0 specs/KMS-Key.cf
  106. +7 −0 specs/Kinesis-Stream.cf
  107. +9 −0 specs/Lambda-Alias.cf
  108. +10 −0 specs/Lambda-EventSourceMapping.cf
  109. +14 −0 specs/Lambda-Function.cf
  110. +10 −0 specs/Lambda-Permission.cf
  111. +8 −0 specs/Lambda-Version.cf
  112. +9 −0 specs/Logs-Destination.cf
  113. +6 −0 specs/Logs-LogGroup.cf
  114. +7 −0 specs/Logs-LogStream.cf
  115. +8 −0 specs/Logs-MetricFilter.cf
  116. +9 −0 specs/Logs-SubscriptionFilter.cf
  117. +16 −0 specs/OpsWorks-App.cf
  118. +7 −0 specs/OpsWorks-ElasticLoadBalancerAttachment.cf
  119. +19 −0 specs/OpsWorks-Instance.cf
  120. +21 −0 specs/OpsWorks-Layer.cf
  121. +23 −0 specs/OpsWorks-Stack.cf
  122. +23 −0 specs/RDS-DBCluster.cf
  123. +9 −0 specs/RDS-DBClusterParameterGroup.cf
  124. +39 −0 specs/RDS-DBInstance.cf
  125. +9 −0 specs/RDS-DBParameterGroup.cf
  126. +10 −0 specs/RDS-DBSecurityGroup.cf
  127. +8 −0 specs/RDS-DBSubnetGroup.cf
  128. +10 −0 specs/RDS-EventSubscription.cf
  129. +10 −0 specs/RDS-OptionGroup.cf
  130. +30 −0 specs/Redshift-Cluster.cf
  131. +8 −0 specs/Redshift-ClusterParameterGroup.cf
  132. +6 −0 specs/Redshift-ClusterSecurityGroup.cf
  133. +9 −0 specs/Redshift-ClusterSecurityGroupIngress.cf
  134. +7 −0 specs/Redshift-ClusterSubnetGroup.cf
  135. +7 −0 specs/Route53-HealthCheck.cf
  136. +9 −0 specs/Route53-HostedZone.cf
  137. +19 −0 specs/Route53-RecordSet.cf
  138. +9 −0 specs/Route53-RecordSetGroup.cf
  139. +15 −0 specs/S3-Bucket.cf
  140. +7 −0 specs/S3-BucketPolicy.cf
  141. +6 −0 specs/SDB-Domain.cf
  142. +8 −0 specs/SNS-Topic.cf
  143. +8 −0 specs/SNS-TopicPolicy.cf
  144. +12 −0 specs/SQS-Queue.cf
  145. +7 −0 specs/SQS-QueuePolicy.cf
  146. +6 −0 specs/SSM-Document.cf
  147. +7 −0 specs/WAF-ByteMatchSet.cf
  148. +7 −0 specs/WAF-IPSet.cf
  149. +8 −0 specs/WAF-Rule.cf
  150. +7 −0 specs/WAF-SqlInjectionMatchSet.cf
  151. +9 −0 specs/WAF-WebACL.cf
  152. +11 −0 specs/WorkSpaces-Workspace.cf
  153. +4 −0 test/test_helper.rb
  154. +7 −0 test/version_test.rb
@@ -0,0 +1,9 @@
/.bundle/
/.yardoc
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
@@ -0,0 +1,4 @@
language: ruby
rvm:
- 2.2.2
before_install: gem install bundler -v 1.11.2
@@ -0,0 +1,3 @@
source 'https://rubygems.org'
gemspec
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Kevin Deisz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,41 @@
# AwsCF
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_cf`. To experiment with that code, run `bin/console` for an interactive prompt.
TODO: Delete this and the text above, and describe your gem
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'aws_cf'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install aws_cf
## Usage
TODO: Write usage instructions here
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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).
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/aws_cf.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
require 'bundler/gem_tasks'
require 'rake/testtask'
Rake::TestTask.new(:test) do |t|
t.libs << 'test'
t.libs << 'lib'
t.test_files = FileList['test/**/*_test.rb']
end
task default: :test
@@ -0,0 +1,35 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'aws_cf/version'
Gem::Specification.new do |spec|
spec.name = 'aws_cf'
spec.version = AwsCF::VERSION
spec.authors = ['Kevin Deisz']
spec.email = ['kevin.deisz@gmail.com']
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.}
spec.description = %q{TODO: Write a longer description or delete this line.}
spec.homepage = "TODO: Put your gem's website or public repo URL here."
spec.license = "MIT"
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
# delete this section to allow pushing this gem to any host.
if spec.respond_to?(:metadata)
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
else
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
end
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency 'bundler', '~> 1.11'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'nokogiri'
spec.add_development_dependency 'pry'
end
@@ -0,0 +1,7 @@
#!/usr/bin/env ruby
require 'bundler/setup'
require 'aws_cf'
require 'irb'
IRB.start
@@ -0,0 +1,23 @@
#!/usr/bin/env ruby
require 'bundler/setup'
require 'aws_cf'
require 'fileutils'
require 'net/http'
require 'nokogiri'
require 'uri'
def get_url(page)
base_url = 'http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/'
listing = Net::HTTP.get_response(URI.parse(base_url + page)).body
end
Nokogiri::HTML(get_url('aws-template-resource-type-ref.html')).css('.highlights ul li a').each do |link|
contents = Nokogiri::HTML(get_url(link['href'])).at_css('.programlisting').text.strip.split("\n")
next unless (type_line = contents.grep(/Type/).first) && contents.grep(/Properties/).first
File.open(File.join('specs', type_line.scan(/AWS::(.*?)::(.*?)\"/).first.join('-') + '.cf'), 'w') do |file|
file.write(contents.join("\n"))
end
end
@@ -0,0 +1,13 @@
require 'json'
require 'pathname'
require 'aws_cf/parser'
require 'aws_cf/props'
require 'aws_cf/resource'
require 'aws_cf/version'
Dir[File.expand_path(File.join('..', '..', 'specs', '*'), __FILE__)].each do |filepath|
group, resource = Pathname.new(filepath).basename('.cf').to_s.split('-')
spec = File.readlines(filepath).slice_after { |line| line.include?('Properties') }.to_a[1].slice_before { |line| line.strip == '}' }.to_a[0]
AwsCF::Resource.register(group, resource, spec.join)
end
@@ -0,0 +1,23 @@
module AwsCF
class Parser
attr_accessor :props, :spec
def initialize(spec)
self.spec = spec
end
def parse
self.props = spec.split("\n").map do |spec_line|
prop = Props.from(spec_line)
[prop.name, prop]
end.to_h
end
def self.parse(spec)
parser = new(spec)
parser.parse
parser
end
end
end
@@ -0,0 +1,28 @@
module AwsCF
module Props
def self.from(spec_line)
if spec_line.include?(':')
key, type = spec_line.strip.gsub(/,\z/, '').split(' : ')
key = key[1..-2]
else
key, type = nil, spec_line.strip
end
case type
when 'Boolean' then BooleanProp.new(key: key)
when 'Integer' then IntegerProp.new(key: key)
when 'String' then StringProp.new(key: key)
when /\[ (.*?),.*?\]/ then ArrayProp.new(key: key, spec: $1)
else
StringProp.new(key: key)
#TODO fail ArgumentError, "Invalid spec: #{spec_line}"
end
end
end
end
require 'aws_cf/props/base'
require 'aws_cf/props/array_prop'
require 'aws_cf/props/boolean_prop'
require 'aws_cf/props/integer_prop'
require 'aws_cf/props/string_prop'
@@ -0,0 +1,18 @@
module AwsCF
module Props
class ArrayProp < Base
attr_accessor :sub_prop
def valid?(value)
value.is_a?(Array) && value.all? { |sub_value| sub_prop.valid?(sub_value) }
end
private
def after_initialize(args)
self.sub_prop = Props.from(args[:spec])
end
end
end
end
@@ -0,0 +1,27 @@
module AwsCF
module Props
class Base
attr_accessor :key
attr_reader :value
def initialize(args = {})
self.key = args[:key]
after_initialize(args)
end
def name
@name ||= key && key.gsub(/(.)([A-Z])/, '\1_\2').downcase
end
def to_cf(value)
[key, value]
end
private
def after_initialize(args)
end
end
end
end
@@ -0,0 +1,9 @@
module AwsCF
module Props
class BooleanProp < Base
def valid?(value)
value.is_a?(TrueClass) || value.is_a?(FalseClass)
end
end
end
end
@@ -0,0 +1,9 @@
module AwsCF
module Props
class IntegerProp < Base
def valid?(value)
value.is_a?(Fixnum)
end
end
end
end
@@ -0,0 +1,9 @@
module AwsCF
module Props
class StringProp < Base
def valid?(value)
value.is_a?(String)
end
end
end
end
@@ -0,0 +1,53 @@
module AwsCF
class Resource
attr_accessor :properties
def initialize
self.properties = {}
end
def method_missing(name, *args)
sname = name.to_s
if (self.class.props.keys & [sname, sname[0..-2]]).empty?
super
elsif self.class.props.key?(sname)
properties[sname]
elsif !self.class.props[sname[0..-2]].valid?(args.first)
fail ArgumentError, "Invalid value for #{sname[0..-2]}: #{args.first.inspect}"
else
properties[sname[0..-2]] = args.first
end
end
def respond_to_missing?(name, include_private = false)
sname = name.to_s
(self.class.props.keys & [sname, sname[0..-2]]).any? || super
end
def to_cf
props_cf = properties.map do |key, value|
self.class.props[key].to_cf(value)
end.to_h
JSON.pretty_generate({ 'Type' => self.class.aws_name, 'Properties' => props_cf })
end
class << self
attr_accessor :aws_name, :props
def register(group, resource, spec)
parser = Parser.parse(spec)
self.props = parser.props
resource_class = Class.new(Resource)
resource_class.props = parser.props
resource_class.aws_name = "AWS::#{group}::#{resource}"
AwsCF.const_set(group, Module.new) unless AwsCF.const_defined?(group)
AwsCF.const_get(group).const_set(resource, resource_class)
end
end
end
end
@@ -0,0 +1,3 @@
module AwsCF
VERSION = '0.0.1'
end
@@ -0,0 +1,21 @@
{
"Type" : "AWS::AutoScaling::AutoScalingGroup",
"Properties" : {
"AvailabilityZones" : [ String, ... ],
"Cooldown" : String,
"DesiredCapacity" : String,
"HealthCheckGracePeriod" : Integer,
"HealthCheckType" : String,
"InstanceId" : String,
"LaunchConfigurationName" : String,
"LoadBalancerNames" : [ String, ... ],
"MaxSize" : String,
"MetricsCollection" : [ MetricsCollection, ... ]
"MinSize" : String,
"NotificationConfigurations" : [ NotificationConfigurations, ... ],
"PlacementGroup" : String,
"Tags" : [ Auto Scaling Tag, ..., ],
"TerminationPolicies" : [ String, ..., ],
"VPCZoneIdentifier" : [ String, ... ]
}
}
Oops, something went wrong.

0 comments on commit f051578

Please sign in to comment.