rubycfn 0.1.10 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f48f2fd5a84ad9092cc5d23f7ecc427b1054a078
4
- data.tar.gz: 6d2a01e823d195c9434071e64124dd633a43a17b
3
+ metadata.gz: 7a89e4f19981be58c78f515a9d3889e6695720d6
4
+ data.tar.gz: 41c80d1691b6bf92c52aca43468860bec24168c9
5
5
  SHA512:
6
- metadata.gz: 17bcc704984776c553bfa46f3b35466ba0126a5360f2f8fac3d33e2e42bc159162edc29bd6f7ce461deb435596a064d7eedda475593e1f1ca9d281e356dba1fd
7
- data.tar.gz: f2d94563b2729e527f4e53123af2bb501f4fdc98e79f7cf3ed36cbe261a75dd53c7ba0cf6d946472d426dd6e29b1252a6d10b4722f2cf9bd6f9ecec31af3510b
6
+ metadata.gz: 0f1f7fb12c993d004a14959af5cecdb101345ba852efc4a1bd63964913e05e4f312e4b1bd179208a0de3db5a0a2837937daa72a2a6b997d5d63b85d1ab7d7e35
7
+ data.tar.gz: c5ede7352a5379fd501bb33dcb332a552c0fbf02da632f775f41db80436aa5491a9c98a0e07016da3723933071fb1259a6e44231b7bf199c6bde1b6ad36f1158
data/CHANGELOG.md CHANGED
@@ -2,7 +2,10 @@
2
2
  All notable changes to Rubycfn will be documented in this file.
3
3
  This project uses [Semantic Versioning](http://semver.org/).
4
4
 
5
- ## 0.1.11 (Next Release)
5
+ ## 0.1.12 (Next Release)
6
+
7
+ ## 0.1.11
8
+ * Added small script to convert a CloudFormation template to Rubycfn code -- [@dennisvink][@dennisvink]
6
9
 
7
10
  ## 0.1.10
8
11
  * Added conditions section support, condition in resources, and added several missing intrinsic functions. -- [@dennisvink][@dennisvink]
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rubycfn (0.1.10)
4
+ rubycfn (0.1.11)
5
5
  activesupport (~> 5.1.5)
6
6
  dotenv (~> 2.4.0)
7
7
  json (~> 2.1.0)
@@ -44,7 +44,7 @@ GEM
44
44
  guard-compat (~> 1.1)
45
45
  rspec (>= 2.99.0, < 4.0)
46
46
  hitimes (1.3.0)
47
- i18n (1.1.0)
47
+ i18n (1.1.1)
48
48
  concurrent-ruby (~> 1.0)
49
49
  json (2.1.0)
50
50
  launchy (2.4.3)
@@ -79,7 +79,7 @@ GEM
79
79
  rspec-mocks (~> 3.8.0)
80
80
  rspec-core (3.8.0)
81
81
  rspec-support (~> 3.8.0)
82
- rspec-expectations (3.8.1)
82
+ rspec-expectations (3.8.2)
83
83
  diff-lcs (>= 1.2.0, < 2.0)
84
84
  rspec-support (~> 3.8.0)
85
85
  rspec-given (3.8.0)
data/bin/rubycfn CHANGED
@@ -44,6 +44,8 @@ project_concern = render('project_concern.rb', { name: project_name.capitalize }
44
44
  project_stack = render('project_stack.rb', { name: project_name.capitalize }, path)
45
45
  rakefile = render('Rakefile', {}, path)
46
46
  spec_helper = render('spec_helper.rb', {}, path)
47
+ converter = render('cfn2rubycfn', {}, path)
48
+ vimfile = render('format.vim', {}, path)
47
49
 
48
50
  # Create directory structure
49
51
  FileUtils.mkdir_p project_path + '/lib/stacks/' + project_name + '_stack'
@@ -55,6 +57,9 @@ File.open("#{project_path}/.env", 'w') { |file| file.write(dotenv) }
55
57
  File.open("#{project_path}/.env.test", 'w') { |file| file.write(dotenv_test) }
56
58
  File.open("#{project_path}/Gemfile", 'w') { |file| file.write(gemfile) }
57
59
  File.open("#{project_path}/Rakefile", 'w') { |file| file.write(rakefile) }
60
+ File.open("#{project_path}/cfn2rubycfn", 'w') { |file| file.write(converter) }
61
+ File.chmod(0777,"#{project_path}/cfn2rubycfn")
62
+ File.open("#{project_path}/format.vim", 'w') { |file| file.write(vimfile) }
58
63
  File.open("#{project_path}/config/buildspec.yml", 'w') { |file| file.write(buildspec) }
59
64
  File.open("#{project_path}/lib/main.rb", 'w') { |file| file.write(main) }
60
65
  File.open("#{project_path}/lib/compile.rb", 'w') { |file| file.write(compile) }
@@ -1,4 +1,4 @@
1
1
  # Rubycfn version
2
2
  module Rubycfn
3
- VERSION = "0.1.10"
3
+ VERSION = "0.1.11"
4
4
  end
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "json"
4
+
5
+ class String
6
+ def snake
7
+ self.gsub(/::/, '/').
8
+ gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
9
+ gsub(/([a-z\d])([A-Z])/,'\1_\2').
10
+ tr("-", "_").
11
+ downcase
12
+ end
13
+ end
14
+
15
+
16
+ def add_code(line, append = false)
17
+ if append === true
18
+ orig_line = @code.pop
19
+ line = "#{orig_line}#{line}"
20
+ end
21
+ @code.push(line)
22
+ end
23
+
24
+ def wash(input = {}, target = :Ref)
25
+ return input unless input.respond_to?("each")
26
+ hash = {}
27
+ input.map do |key, value|
28
+ case key
29
+ when 'Ref'
30
+ hash = "###'" + value.to_s + "'." + key.downcase.to_s + '###'
31
+ else
32
+ if value.respond_to?("each")
33
+ hash[key] = wash(value, :Ref)
34
+ else
35
+ return input
36
+ end
37
+ end
38
+ end
39
+ hash
40
+ end
41
+
42
+ raise "Filename required" unless ARGV[0]
43
+ raise "File does not exist" unless File.file?(ARGV[0])
44
+
45
+ @code = []
46
+ template = JSON.parse(File.read(ARGV[0]))
47
+ resources = template["Resources"]
48
+ outadd_code = template["Outadd_code"]
49
+ parameters = template["Parameters"]
50
+ outputs = template["Outputs"]
51
+
52
+ add_code "module ConvertedStack"
53
+ add_code " module Main"
54
+ add_code " extend ActiveSupport::Concern"
55
+ add_code " included do"
56
+
57
+ # Convert parameters
58
+ parameters.each do |param_name, param_attr|
59
+ add_code " parameter :#{param_name.snake}"
60
+ add_code(parameters.count > 1 ? "," : "", true)
61
+ param_attr.each_with_index do |attr, index|
62
+ add_code " #{attr.first.snake}: \"#{attr.last}\""
63
+ add_code(index+1 == param_attr.count ? "" : ",", true)
64
+ end
65
+ add_code("")
66
+ end
67
+
68
+ # Convert resources
69
+ resources.each do |resource_name, resource_attr|
70
+ properties = resource_attr["Properties"]
71
+ unless resource_attr["Properties"].empty?
72
+ add_code " resource :#{resource_name.snake},"
73
+ add_code " type: \"#{resource_attr["Type"]}\" do |r|"
74
+ properties.each do |k,v|
75
+ if v.respond_to?("each")
76
+ v = wash(v)
77
+ v = JSON.pretty_generate(v)
78
+ v = v.gsub(/\"\#\#\#/, "")
79
+ v = v.gsub(/\#\#\#\"/, "")
80
+
81
+ add_code " r.property(:#{k.snake}) do"
82
+ add_code " #{v}"
83
+ add_code " end"
84
+ else
85
+ add_code " r.property(:#{k.snake}) { #{v.to_json} }"
86
+ end
87
+ end
88
+ add_code " end"
89
+ else
90
+ add_code " resource :#{resource_name.snake},"
91
+ add_code " type: \"#{resource_attr["Type"]}\""
92
+ end
93
+ add_code("")
94
+ end
95
+
96
+ outputs.each do |output_name, output_attr|
97
+ add_code " output :#{output_name.snake}"
98
+ add_code(output_attr.count > 0 ? "," : "", true)
99
+ output_attr.each_with_index do |attr, index|
100
+ add_code " #{attr.first.snake}: "
101
+ if attr.last.class == Hash
102
+ add_code(wash(attr.last), true)
103
+ else
104
+ add_code("\"#{attr.last}\"", true)
105
+ end
106
+ add_code(index+1 == output_attr.count ? "" : ",", true)
107
+ end
108
+ add_code("")
109
+ end
110
+
111
+ add_code " end"
112
+ add_code " end"
113
+ add_code "end"
114
+
115
+ @code = @code.join("\n")
116
+ @code = @code.gsub(/\"\#\#\#/, "")
117
+ @code = @code.gsub(/\#\#\#\"/, "")
118
+ @code = @code.gsub(/\'\#\#\#/, "'")
119
+ @code = @code.gsub(/\#\#\#\'/, "'")
120
+ @code = @code.gsub(/\#\#\#${1}/, "")
121
+
122
+ File.open("generated.rb", "w") do |f|
123
+ f.puts(@code)
124
+ end
125
+
126
+ puts "Reformatting code..."
127
+ `vim generated.rb -s format.vim 2>&1 >/dev/null`
@@ -0,0 +1,3 @@
1
+ gg=G
2
+ :retab
3
+ ZZ
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubycfn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Vink
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-27 00:00:00.000000000 Z
11
+ date: 2018-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: neatjson
@@ -277,9 +277,11 @@ files:
277
277
  - templates/Gemfile.erb
278
278
  - templates/Rakefile.erb
279
279
  - templates/buildspec.yml.erb
280
+ - templates/cfn2rubycfn.erb
280
281
  - templates/cicd.rb.erb
281
282
  - templates/compile.rb.erb
282
283
  - templates/example_stack_spec.rb.erb
284
+ - templates/format.vim.erb
283
285
  - templates/global_variables.rb.erb
284
286
  - templates/main.rb.erb
285
287
  - templates/project_concern.rb.erb