lono 6.1.11 → 7.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (240) hide show
  1. checksums.yaml +4 -4
  2. data/.cody/acceptance.sh +19 -3
  3. data/.gitignore +2 -2
  4. data/CHANGELOG.md +16 -1
  5. data/README.md +18 -20
  6. data/Rakefile +1 -0
  7. data/lib/lono.rb +7 -5
  8. data/lib/lono/abstract_base.rb +25 -0
  9. data/lib/lono/api/client.rb +30 -0
  10. data/lib/lono/api/proxy.rb +58 -0
  11. data/lib/lono/api/repos.rb +8 -0
  12. data/lib/lono/api/verify.rb +13 -0
  13. data/lib/lono/app_file/base.rb +4 -11
  14. data/lib/lono/app_file/build.rb +1 -1
  15. data/lib/lono/app_file/upload.rb +1 -4
  16. data/lib/lono/autoloader.rb +3 -1
  17. data/lib/lono/aws_services.rb +9 -9
  18. data/lib/lono/aws_services/helper.rb +14 -0
  19. data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
  20. data/lib/lono/aws_services/stack_set.rb +41 -0
  21. data/lib/lono/blueprint.rb +2 -2
  22. data/lib/lono/blueprint/configset/loader.rb +7 -0
  23. data/lib/lono/blueprint/helper.rb +8 -2
  24. data/lib/lono/blueprint/meta.rb +4 -12
  25. data/lib/lono/blueprint/new.rb +3 -3
  26. data/lib/lono/blueprint/root.rb +6 -26
  27. data/lib/lono/bundle.rb +54 -0
  28. data/lib/lono/cfn.rb +31 -75
  29. data/lib/lono/cfn/base.rb +39 -136
  30. data/lib/lono/cfn/cancel.rb +14 -9
  31. data/lib/lono/cfn/create.rb +15 -19
  32. data/lib/lono/cfn/delete.rb +9 -9
  33. data/lib/lono/cfn/deploy.rb +4 -4
  34. data/lib/lono/cfn/download.rb +27 -9
  35. data/lib/lono/cfn/opts.rb +80 -0
  36. data/lib/lono/cfn/preview/changeset.rb +23 -23
  37. data/lib/lono/cfn/preview/codediff.rb +5 -6
  38. data/lib/lono/cfn/preview/param.rb +10 -10
  39. data/lib/lono/cfn/rollback.rb +5 -5
  40. data/lib/lono/cfn/status.rb +0 -10
  41. data/lib/lono/cfn/update.rb +22 -27
  42. data/lib/lono/clean.rb +3 -3
  43. data/lib/lono/cli.rb +69 -34
  44. data/lib/lono/code.rb +22 -0
  45. data/lib/lono/command.rb +7 -0
  46. data/lib/lono/config_location.rb +6 -13
  47. data/lib/lono/configset.rb +9 -0
  48. data/lib/lono/configset/combiner.rb +128 -0
  49. data/lib/lono/configset/evaluate_file.rb +8 -0
  50. data/lib/lono/configset/list.rb +67 -0
  51. data/lib/lono/configset/loader.rb +98 -0
  52. data/lib/lono/configset/loader/dsl.rb +9 -0
  53. data/lib/lono/configset/materializer/final.rb +10 -0
  54. data/lib/lono/configset/materializer/gems_builder.rb +81 -0
  55. data/lib/lono/configset/materializer/jade.rb +15 -0
  56. data/lib/lono/configset/materializer/source.rb +54 -0
  57. data/lib/lono/configset/meta.rb +19 -0
  58. data/lib/lono/configset/meta/dsl.rb +12 -0
  59. data/lib/lono/configset/new.rb +84 -0
  60. data/lib/lono/configset/preparer.rb +44 -0
  61. data/lib/lono/configset/register/base.rb +121 -0
  62. data/lib/lono/configset/register/blueprint.rb +16 -0
  63. data/lib/lono/configset/register/dsl.rb +15 -0
  64. data/lib/lono/configset/register/project.rb +12 -0
  65. data/lib/lono/configset/registry.rb +34 -0
  66. data/lib/lono/configset/resolver.rb +42 -0
  67. data/lib/lono/conventions.rb +18 -7
  68. data/lib/lono/core.rb +16 -20
  69. data/lib/lono/default/settings.yml +2 -3
  70. data/lib/lono/ext/bundler.rb +7 -0
  71. data/lib/lono/file_uploader.rb +8 -5
  72. data/lib/lono/finder/base.rb +140 -0
  73. data/lib/lono/finder/blueprint.rb +11 -0
  74. data/lib/lono/finder/blueprint/configset.rb +17 -0
  75. data/lib/lono/finder/configset.rb +11 -0
  76. data/lib/lono/generate.rb +93 -0
  77. data/lib/lono/help/blueprint/new.md +0 -1
  78. data/lib/lono/help/cfn/delete.md +1 -1
  79. data/lib/lono/help/cfn/deploy.md +5 -76
  80. data/lib/lono/help/cfn/status.md +0 -4
  81. data/lib/lono/help/cfn/update.md +1 -1
  82. data/lib/lono/help/code/convert.md +51 -0
  83. data/lib/lono/help/code/import.md +30 -0
  84. data/lib/lono/help/configsets.md +24 -0
  85. data/lib/lono/help/generate.md +4 -4
  86. data/lib/lono/help/new.md +1 -2
  87. data/lib/lono/help/sets/delete.md +8 -0
  88. data/lib/lono/help/sets/deploy.md +76 -0
  89. data/lib/lono/help/sets/instances/delete.md +21 -0
  90. data/lib/lono/help/sets/instances/list.md +14 -0
  91. data/lib/lono/help/sets/instances/status.md +15 -0
  92. data/lib/lono/help/sets/instances/sync.md +88 -0
  93. data/lib/lono/help/sets/status.md +23 -0
  94. data/lib/lono/help/upgrade.md +1 -0
  95. data/lib/lono/importer.rb +22 -0
  96. data/lib/lono/importer/base.rb +59 -0
  97. data/lib/lono/importer/converter.rb +19 -0
  98. data/lib/lono/importer/download.rb +46 -0
  99. data/lib/lono/importer/dsl.rb +36 -0
  100. data/lib/lono/importer/erb.rb +31 -0
  101. data/lib/lono/importer/params.rb +56 -0
  102. data/lib/lono/importer/service/coder.rb +81 -0
  103. data/lib/lono/inspector/base.rb +12 -22
  104. data/lib/lono/inspector/graph.rb +1 -1
  105. data/lib/lono/inspector/summary.rb +41 -17
  106. data/lib/lono/jade.rb +103 -0
  107. data/lib/lono/jade/circular.rb +26 -0
  108. data/lib/lono/jadespec.rb +41 -0
  109. data/lib/lono/new.rb +2 -2
  110. data/lib/lono/opts.rb +43 -0
  111. data/lib/lono/output/template.rb +48 -0
  112. data/lib/lono/param.rb +3 -5
  113. data/lib/lono/param/generator.rb +13 -33
  114. data/lib/lono/pro.rb +15 -0
  115. data/lib/lono/pro/base.rb +16 -0
  116. data/lib/lono/pro/repo.rb +27 -0
  117. data/lib/lono/project_checker.rb +4 -29
  118. data/lib/lono/registration.rb +15 -0
  119. data/lib/lono/registration/base.rb +37 -0
  120. data/lib/lono/registration/check.rb +15 -0
  121. data/lib/lono/registration/temp.rb +60 -0
  122. data/lib/lono/registration/user.rb +54 -0
  123. data/lib/lono/script/base.rb +1 -10
  124. data/lib/lono/script/upload.rb +2 -12
  125. data/lib/lono/seed.rb +2 -11
  126. data/lib/lono/seed/base.rb +55 -110
  127. data/lib/lono/sets.rb +38 -0
  128. data/lib/lono/sets/base.rb +45 -0
  129. data/lib/lono/sets/create.rb +30 -0
  130. data/lib/lono/sets/delete.rb +47 -0
  131. data/lib/lono/sets/deploy.rb +11 -0
  132. data/lib/lono/sets/instances.rb +33 -0
  133. data/lib/lono/sets/instances/base.rb +30 -0
  134. data/lib/lono/sets/instances/delete.rb +69 -0
  135. data/lib/lono/sets/instances/list.rb +13 -0
  136. data/lib/lono/sets/instances/opts.rb +29 -0
  137. data/lib/lono/sets/instances/status.rb +12 -0
  138. data/lib/lono/sets/instances/sync.rb +182 -0
  139. data/lib/lono/sets/list.rb +35 -0
  140. data/lib/lono/sets/opts.rb +18 -0
  141. data/lib/lono/sets/preview/codediff.rb +35 -0
  142. data/lib/lono/sets/preview/param.rb +32 -0
  143. data/lib/lono/sets/status.rb +116 -0
  144. data/lib/lono/sets/status/instance.rb +20 -0
  145. data/lib/lono/sets/status/instance/base.rb +120 -0
  146. data/lib/lono/sets/status/instance/completed.rb +35 -0
  147. data/lib/lono/sets/status/instance/deleted.rb +32 -0
  148. data/lib/lono/sets/status/instance/show.rb +7 -0
  149. data/lib/lono/sets/status/instances.rb +111 -0
  150. data/lib/lono/sets/summarize.rb +20 -0
  151. data/lib/lono/sets/time_spent.rb +11 -0
  152. data/lib/lono/sets/update.rb +81 -0
  153. data/lib/lono/template.rb +5 -7
  154. data/lib/lono/template/configset_injector.rb +50 -0
  155. data/lib/lono/template/context.rb +4 -4
  156. data/lib/lono/template/context/loader.rb +4 -16
  157. data/lib/lono/template/evaluate.rb +2 -1
  158. data/lib/lono/template/generator.rb +17 -15
  159. data/lib/lono/template/helper.rb +7 -7
  160. data/lib/lono/template/post_processor.rb +2 -12
  161. data/lib/lono/template/strategy/base.rb +4 -0
  162. data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
  163. data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
  164. data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
  165. data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
  166. data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
  167. data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
  168. data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
  169. data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
  170. data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
  171. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
  172. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
  173. data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
  174. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
  175. data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
  176. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
  177. data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
  178. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
  179. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
  180. data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
  181. data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
  182. data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
  183. data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
  184. data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
  185. data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
  186. data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
  187. data/lib/lono/template/strategy/source.rb +8 -0
  188. data/lib/lono/template/template.rb +1 -1
  189. data/lib/lono/template/upload.rb +4 -9
  190. data/lib/lono/template/util.rb +0 -40
  191. data/lib/lono/upgrade.rb +12 -10
  192. data/lib/lono/user_data.rb +4 -4
  193. data/lib/lono/utils/pretty_time.rb +14 -0
  194. data/lib/lono/utils/sure.rb +23 -0
  195. data/lib/lono/version.rb +1 -1
  196. data/lib/lono/yamler/loader.rb +52 -0
  197. data/lib/lono/yamler/validator.rb +51 -0
  198. data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
  199. data/lib/templates/blueprint/README.md.tt +1 -1
  200. data/lib/templates/blueprint/seed/configs.rb +2 -2
  201. data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
  202. data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
  203. data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
  204. data/lib/templates/configset/.gitignore +11 -0
  205. data/lib/templates/configset/CHANGELOG.md +7 -0
  206. data/lib/templates/configset/Gemfile +4 -0
  207. data/lib/templates/configset/README.md.tt +3 -0
  208. data/lib/templates/configset/Rakefile.tt +9 -0
  209. data/lib/templates/configset/lib/configset.yml +20 -0
  210. data/lib/templates/skeleton/.gitignore +1 -0
  211. data/lib/templates/skeleton/Gemfile +0 -1
  212. data/lib/templates/skeleton/README.md +4 -4
  213. data/lib/templates/skeleton/configs/settings.yml +1 -1
  214. data/lono.gemspec +1 -4
  215. metadata +146 -79
  216. data/Guardfile +0 -19
  217. data/lib/lono/app_file.rb +0 -5
  218. data/lib/lono/blueprint/find.rb +0 -90
  219. data/lib/lono/blueprint/info.rb +0 -10
  220. data/lib/lono/blueprint/list.rb +0 -14
  221. data/lib/lono/cfn/current.rb +0 -95
  222. data/lib/lono/cfn/preview.rb +0 -4
  223. data/lib/lono/cfn/suffix.rb +0 -67
  224. data/lib/lono/cfn/util.rb +0 -27
  225. data/lib/lono/help/cfn/current.md +0 -18
  226. data/lib/lono/help/upgrade4.md +0 -25
  227. data/lib/lono/inspector.rb +0 -4
  228. data/lib/lono/output_template.rb +0 -35
  229. data/lib/lono/template/base.rb +0 -13
  230. data/lib/lono/template/dsl/builder/helpers.rb +0 -8
  231. data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
  232. data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
  233. data/lib/lono/template/dsl/builder/parameter.rb +0 -39
  234. data/lib/lono/upgrade/upgrade4.rb +0 -175
  235. data/lib/lono/upgrade/upgrade42.rb +0 -36
  236. data/lib/lono/upgrade/upgrade5.rb +0 -55
  237. data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
  238. data/lib/templates/skeleton/Guardfile +0 -12
  239. data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
  240. data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -3,15 +3,15 @@ class Lono::Cfn
3
3
  extend Memoist
4
4
  include Lono::AwsServices
5
5
 
6
- def initialize(stack_name)
7
- @stack_name = stack_name
6
+ def initialize(stack)
7
+ @stack = stack
8
8
  end
9
9
 
10
10
  def delete_stack
11
- stack = find_stack(@stack_name)
11
+ stack = find_stack(@stack)
12
12
  if stack && rollback_complete?(stack)
13
13
  puts "Existing stack in ROLLBACK_COMPLETE state. Deleting stack before continuing."
14
- cfn.delete_stack(stack_name: @stack_name)
14
+ cfn.delete_stack(stack_name: @stack)
15
15
  status.wait
16
16
  status.reset
17
17
  true
@@ -19,7 +19,7 @@ class Lono::Cfn
19
19
  end
20
20
 
21
21
  def status
22
- Lono::Cfn::Status.new(@stack_name)
22
+ Lono::Cfn::Status.new(@stack)
23
23
  end
24
24
  memoize :status
25
25
  end
@@ -1,14 +1,4 @@
1
1
  class Lono::Cfn
2
2
  class Status < CfnStatus
3
- include Util
4
-
5
- def initialize(stack_name, options={})
6
- super
7
- @stack_name = switch_current(stack_name)
8
- end
9
-
10
- def switch_current(stack_name)
11
- Lono::Cfn::Current.name!(stack_name)
12
- end
13
3
  end
14
4
  end
@@ -1,13 +1,9 @@
1
1
  class Lono::Cfn
2
2
  class Update < Base
3
- # save_stack is the interface method
4
- def save_stack(params)
5
- update_stack(params)
6
- end
7
-
3
+ # save is the interface method
8
4
  # aws cloudformation update-stack --stack-name prod-hi-123456789 --parameters file://output/params/prod-hi-123456789.json --template-body file://output/prod-hi.json
9
- def update_stack(params)
10
- message = "Updating #{@stack_name} stack"
5
+ def save(parameters)
6
+ message = "Updating #{@stack} stack"
11
7
  if @options[:noop]
12
8
  puts "NOOP #{message}"
13
9
  return
@@ -15,60 +11,59 @@ class Lono::Cfn
15
11
 
16
12
  deleted = delete_rollback_stack
17
13
  if deleted
18
- Create.new(@stack_name, @options).create_stack(params)
14
+ Create.new(@options).save(parameters)
19
15
  return
20
16
  end
21
17
 
22
- unless stack_exists?(@stack_name)
23
- puts "Cannot update a stack because the #{@stack_name} does not exists."
18
+ unless stack_exists?(@stack)
19
+ puts "Cannot update a stack because the #{@stack} does not exists."
24
20
  return
25
21
  end
26
- exit_unless_updatable!(stack_status(@stack_name))
22
+ exit_unless_updatable!
27
23
 
28
24
  options = @options.merge(mute_params: true, mute_using: true, keep: true)
29
25
  # create new copy of preview when update_stack is called because of IAM retry logic
30
- changeset_preview = Lono::Cfn::Preview::Changeset.new(@stack_name, options)
26
+ changeset_preview = Lono::Cfn::Preview::Changeset.new(options)
31
27
 
32
- error = nil
33
28
  param_preview.run if @options[:param_preview]
34
29
  codediff_preview.run if @options[:codediff_preview]
35
30
  changeset_preview.run if @options[:changeset_preview]
36
- are_you_sure?(@stack_name, :update)
31
+ sure?("Are you sure you want to update the #{@stack} stack?")
37
32
 
38
33
  if @options[:change_set] # defaults to this
39
34
  message << " via change set: #{changeset_preview.change_set_name}"
40
35
  changeset_preview.execute_change_set
41
36
  else
42
- standard_update(params)
37
+ standard_update(parameters)
43
38
  end
44
- puts message unless @options[:mute] || error
39
+ puts message unless @options[:mute]
45
40
  end
46
41
 
47
- def standard_update(params)
48
- params = {
49
- stack_name: @stack_name,
50
- parameters: params,
42
+ def standard_update(parameters)
43
+ options = {
44
+ stack_name: @stack,
45
+ parameters: parameters,
51
46
  capabilities: capabilities, # ["CAPABILITY_IAM", "CAPABILITY_NAMED_IAM"]
52
47
  disable_rollback: !@options[:rollback],
53
48
  }
54
- params[:tags] = tags unless tags.empty?
55
- set_template_body!(params)
56
- show_parameters(params, "cfn.update_stack")
49
+ options[:tags] = tags unless tags.empty?
50
+ set_template_url!(options)
51
+ show_options(options, "cfn.update_stack")
57
52
  begin
58
- cfn.update_stack(params)
53
+ cfn.update_stack(options)
59
54
  rescue Aws::CloudFormation::Errors::ValidationError => e
60
- puts "ERROR: #{e.message}".red
55
+ puts "ERROR: #{e.message}".color(:red)
61
56
  false
62
57
  end
63
58
  end
64
59
 
65
60
  def codediff_preview
66
- Lono::Cfn::Preview::Codediff.new(@stack_name, @options.merge(mute_params: true, mute_using: true))
61
+ Lono::Cfn::Preview::Codediff.new(@options.merge(mute_params: true, mute_using: true))
67
62
  end
68
63
  memoize :codediff_preview
69
64
 
70
65
  def param_preview
71
- Lono::Cfn::Preview::Param.new(@stack_name, @options)
66
+ Lono::Cfn::Preview::Param.new(@options)
72
67
  end
73
68
  memoize :param_preview
74
69
  end
@@ -2,13 +2,13 @@ require "fileutils"
2
2
 
3
3
  class Lono::Clean
4
4
  attr_reader :options
5
- def initialize(options)
5
+ def initialize(options={})
6
6
  @options = options
7
7
  end
8
8
 
9
9
  def run
10
- puts "Cleaning up"
11
- puts "Removing output/ folder"
10
+ puts "Clean: removing output/ and tmp/ folder"
12
11
  FileUtils.rm_rf("#{Lono.config.output_path}")
12
+ FileUtils.rm_rf("#{Lono.root}/tmp")
13
13
  end
14
14
  end
@@ -1,6 +1,7 @@
1
1
  module Lono
2
2
  class CLI < Command
3
3
  include Thor::Actions # for add_runtime_options
4
+ opts = Opts.new(self)
4
5
 
5
6
  long_desc Help.text(:new)
6
7
  New.cli_options.each do |args|
@@ -8,58 +9,71 @@ module Lono
8
9
  end
9
10
  register(New, "new", "new NAME", "Generates new lono project.")
10
11
 
11
- desc "blueprints", "Lists project blueprints"
12
+ desc "blueprints", "Lists blueprints"
12
13
  long_desc Help.text(:blueprints)
13
14
  def blueprints
14
- Blueprint::List.available
15
+ Finder::Blueprint.list
15
16
  end
16
17
 
17
- desc "generate", "Generate both CloudFormation templates and parameters files."
18
+ desc "configsets [BLUEPRINT]", "Lists configsets"
19
+ long_desc Help.text(:configsets)
20
+ opts.source
21
+ opts.stack
22
+ def configsets(blueprint=nil)
23
+ Configset::List.new(options.merge(blueprint: blueprint)).run
24
+ end
25
+
26
+ desc "generate BLUEPRINT", "Generate both CloudFormation templates and parameters files."
18
27
  long_desc Help.text(:generate)
19
- option :clean, type: :boolean, default: false, desc: "remove all output files before generating"
20
28
  option :quiet, type: :boolean, desc: "silence the output"
21
- option :stack, desc: "stack name. defaults to blueprint name."
22
- def generate(blueprint=nil)
23
- Blueprint::Find.one_or_all(blueprint).each do |b|
24
- Script::Build.new(b, options).run
25
- Template::Generator.new(b, options).run
26
- Param::Generator.new(b, options).generate
27
- end
29
+ opts.clean
30
+ opts.source
31
+ opts.stack
32
+ opts.template
33
+ def generate(blueprint)
34
+ o = options.merge(blueprint: blueprint)
35
+ Script::Build.new(o).run
36
+ Template::Generator.new(o).run
37
+ Param::Generator.new(o).generate
28
38
  end
29
39
 
30
40
  desc "user_data NAME", "Generates user_data script for debugging."
31
41
  long_desc Help.text(:user_data)
32
- option :clean, type: :boolean, default: true, desc: "remove all output/user_data files before generating"
42
+ opts.clean
33
43
  def user_data(blueprint, name)
34
44
  Script::Build.new(blueprint, options).run
35
45
  UserData.new(blueprint, options.merge(name: name)).generate
36
46
  end
37
47
 
38
- desc "summary BLUEPRINT TEMPLATE", "Prints summary of CloudFormation templates."
48
+ desc "summary BLUEPRINT", "Prints summary of CloudFormation templates."
39
49
  long_desc Help.text("summary")
40
- def summary(blueprint=nil, template=nil)
41
- Lono::Inspector::Summary.new(blueprint, template, options).run
50
+ opts.source
51
+ opts.template
52
+ def summary(blueprint)
53
+ Lono::Inspector::Summary.new(options.merge(blueprint: blueprint)).run
42
54
  end
43
55
 
44
56
  desc "xgraph STACK", "Graphs dependencies tree of CloudFormation template resources."
45
57
  long_desc Help.text("xgraph")
46
58
  option :display, type: :string, desc: "graph or text", default: "graph"
47
59
  option :noop, type: :boolean, desc: "noop mode"
48
- def xgraph(blueprint, template=nil)
49
- template ||= blueprint
50
- Lono::Inspector::Graph.new(blueprint, template, options).run
60
+ opts.source
61
+ opts.template
62
+ def xgraph(blueprint)
63
+ Lono::Inspector::Graph.new(options.merge(blueprint: blueprint)).run
51
64
  end
52
65
 
53
66
  desc "seed BLUEPRINT", "Generates starter configs for a blueprint."
54
67
  long_desc Help.text("seed")
55
68
  option :param, desc: "override convention and specify the param file to use"
56
- option :template, desc: "override convention and specify the template file to use"
69
+ opts.source
70
+ opts.template
57
71
  add_runtime_options! # Thor::Action options like --force
58
72
  def seed(blueprint)
59
- Seed.new(blueprint, options).create
73
+ Seed.new(options.merge(blueprint: blueprint)).create
60
74
  end
61
75
 
62
- desc "app_files BLUEPRINT", "Builds app files"
76
+ desc "app_files BLUEPRINT", "Builds app files", hide: true
63
77
  long_desc Help.text("app_files")
64
78
  add_runtime_options! # Thor::Action options like --force
65
79
  def app_files(blueprint)
@@ -71,6 +85,12 @@ module Lono
71
85
  Clean.new(options).run
72
86
  end
73
87
 
88
+ desc "upgrade", "Upgrade lono"
89
+ long_desc Help.text("upgrade")
90
+ def upgrade
91
+ Upgrade.new(options).run
92
+ end
93
+
74
94
  desc "completion *PARAMS", "Prints words for auto-completion."
75
95
  long_desc Help.text("completion")
76
96
  def completion(*params)
@@ -86,35 +106,50 @@ module Lono
86
106
  desc "version", "Prints version"
87
107
  def version
88
108
  puts "Lono: #{VERSION}"
89
- puts "Lono Pro Addon: #{Lono.pro_version}"
90
109
  end
91
110
 
92
- desc "template SUBCOMMAND", "template subcommands"
93
- long_desc Help.text(:template)
94
- subcommand "template", Template
111
+ desc "blueprint SUBCOMMAND", "blueprint subcommands"
112
+ long_desc Help.text(:blueprint)
113
+ subcommand "blueprint", Blueprint
95
114
 
96
115
  desc "cfn SUBCOMMAND", "cfn subcommands"
97
116
  long_desc Help.text(:cfn)
98
117
  subcommand "cfn", Cfn
99
118
 
119
+ desc "code SUBCOMMAND", "code subcommands"
120
+ long_desc Help.text(:code)
121
+ subcommand "code", Code
122
+
123
+ desc "configset SUBCOMMAND", "configset subcommands"
124
+ long_desc Help.text(:configset)
125
+ subcommand "configset", Configset
126
+
100
127
  desc "param SUBCOMMAND", "param subcommands"
101
128
  long_desc Help.text(:param)
102
129
  subcommand "param", Param
103
130
 
104
- desc "script SUBCOMMAND", "script subcommands"
105
- long_desc Help.text(:script)
106
- subcommand "script", Script
131
+ desc "pro SUBCOMMAND", "pro subcommands"
132
+ long_desc Help.text(:pro)
133
+ subcommand "pro", Pro
107
134
 
108
- desc "upgrade SUBCOMMAND", "upgrade subcommands"
109
- long_desc Help.text(:upgrade)
110
- subcommand "upgrade", Upgrade
135
+ desc "registration SUBCOMMAND", "registration subcommands"
136
+ long_desc Help.text(:registration)
137
+ subcommand "registration", Registration
111
138
 
112
139
  desc "s3 SUBCOMMAND", "s3 subcommands"
113
140
  long_desc Help.text(:s3)
114
141
  subcommand "s3", S3
115
142
 
116
- desc "blueprint SUBCOMMAND", "blueprint subcommands"
117
- long_desc Help.text(:blueprint)
118
- subcommand "blueprint", Blueprint
143
+ desc "script SUBCOMMAND", "script subcommands"
144
+ long_desc Help.text(:script)
145
+ subcommand "script", Script
146
+
147
+ desc "sets SUBCOMMAND", "sets subcommands"
148
+ long_desc Help.text(:sets)
149
+ subcommand "sets", Sets
150
+
151
+ desc "template SUBCOMMAND", "template subcommands"
152
+ long_desc Help.text(:template)
153
+ subcommand "template", Template
119
154
  end
120
155
  end
@@ -0,0 +1,22 @@
1
+ module Lono
2
+ class Code < Lono::Command
3
+ desc "import SOURCE", "Imports CloudFormation template and converts it to Ruby code."
4
+ long_desc Help.text("code/import")
5
+ option :blueprint, default: nil, desc: "final blueprint name"
6
+ option :casing, default: "as-is", desc: "Controls casing of logical ids. IE: as-is, camelcase or underscore"
7
+ option :summary, default: true, type: :boolean, desc: "provide template summary after import"
8
+ option :template, default: nil, desc: "final template name of downloaded template without extension"
9
+ option :template_name_casing, default: "dasherize", desc: "camelcase or dasherize the template name"
10
+ option :type, default: "dsl", desc: "import as a DSL or ERB template"
11
+ def import(source)
12
+ Importer.new(options.merge(source: source)).run
13
+ end
14
+
15
+ desc "convert SOURCE", "Converts snippet of JSON or YAML CloudFormation templates to Ruby code."
16
+ long_desc Help.text("code/convert")
17
+ option :casing, default: "as-is", desc: "Controls casing of logical ids. IE: as-is, camelcase or underscore"
18
+ def convert(source)
19
+ Importer::Converter.new(options.merge(source: source)).run
20
+ end
21
+ end
22
+ end
@@ -91,6 +91,13 @@ module Lono
91
91
  def website
92
92
  "http://lono.cloud"
93
93
  end
94
+
95
+ # https://github.com/erikhuda/thor/issues/244
96
+ # Deprecation warning: Thor exit with status 0 on errors. To keep this behavior, you must define `exit_on_failure?` in `Lono::CLI`
97
+ # You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION.
98
+ def exit_on_failure?
99
+ true
100
+ end
94
101
  end
95
102
  end
96
103
  end
@@ -1,16 +1,11 @@
1
1
  module Lono
2
- class ConfigLocation
2
+ class ConfigLocation < AbstractBase
3
3
  extend Memoist
4
- include Lono::Conventions
5
4
 
6
5
  def initialize(config, options={}, env=Lono.env, root=Lono.root)
6
+ super(options)
7
7
  # config can be params or variables
8
- @config, @options, @root, @env = config, options, root, env
9
-
10
- @stack = options[:stack]
11
- @blueprint = options[:blueprint] || @stack
12
- @template, @param = template_param_convention(options)
13
-
8
+ @config, @options, @env, @root = config, options, env, root
14
9
  @requested = determine_requested
15
10
  end
16
11
 
@@ -73,14 +68,12 @@ module Lono
73
68
  def determine_requested
74
69
  # param is usually set from the convention. when set from convention stack name takes higher precedence
75
70
  config_key = @config.singularize.to_sym # param or variable
76
- @options[config_key] || @options[:config] || @options[:stack]
71
+ @options[config_key] || @options[:config] || @stack
77
72
  end
78
73
 
79
74
  def requested_file(path)
80
- # List of paths to consider from initial path provided
81
- paths = @config == "params" ?
82
- [path, "#{path}.txt", "#{path}.sh"] :
83
- [path, "#{path}.rb"]
75
+ # List of paths to consider from initial path provided. Combine params and variables possible paths for simplicity.
76
+ paths = [path, "#{path}.txt", "#{path}.sh", "#{path}.rb"].compact
84
77
  paths.find { |p| File.file?(p) }
85
78
  end
86
79
  memoize :requested_file
@@ -0,0 +1,9 @@
1
+ module Lono
2
+ class Configset < Command
3
+ long_desc Help.text("configset/new")
4
+ New.cli_options.each do |args|
5
+ option(*args)
6
+ end
7
+ register(New, "new", "new NAME", "Generates new lono configset.")
8
+ end
9
+ end
@@ -0,0 +1,128 @@
1
+ require "yaml"
2
+
3
+ class Lono::Configset
4
+ class Combiner
5
+ def initialize(cfn, options={})
6
+ @cfn, @options = cfn, options
7
+
8
+ @sets = []
9
+ @map = {} # stores resource logical id => metadata cfn-init
10
+ end
11
+
12
+ def metadata_map
13
+ return {} unless additional_configsets?
14
+
15
+ existing_configsets.each do |data|
16
+ add(data[:registry], data[:metdata_configset])
17
+ end
18
+
19
+ Register::Blueprint.configsets.each do |registry|
20
+ loader = Lono::Blueprint::Configset::Loader.new(registry, @options)
21
+ add(registry, loader.metdata_configset)
22
+ end
23
+ Register::Project.configsets.each do |registry|
24
+ loader = Loader.new(registry, @options)
25
+ add(registry, loader.metdata_configset)
26
+ end
27
+
28
+ combine
29
+ Register::Blueprint.clear! # in case of lono generate for all templates
30
+ Register::Project.clear! # in case of lono generate for all templates
31
+ @map
32
+ end
33
+
34
+ def add(registry, metadata)
35
+ @sets << [registry, metadata.dup]
36
+ end
37
+
38
+ def additional_configsets?
39
+ !Register::Blueprint.configsets.empty? || !Register::Project.configsets.empty?
40
+ end
41
+
42
+ # Normalized/convert cfn template to mimic the registry format
43
+ def existing_configsets
44
+ configsets = []
45
+ @cfn["Resources"].each do |logical_id, attributes|
46
+ init = attributes.dig("Metadata", "AWS::CloudFormation::Init")
47
+
48
+ next unless init
49
+
50
+ data = {
51
+ registry: Lono::Configset::Registry.new(["#{logical_id}OriginalConfigset"], resource: logical_id),
52
+ metdata_configset: attributes["Metadata"]
53
+ }
54
+ configsets << data
55
+ end
56
+ configsets
57
+ end
58
+
59
+ def combine
60
+ # Remove duplicate configsets. Can happen if same configset is in blueprint and project.
61
+ # Ugly because of the sets structure.
62
+ @sets.uniq! do |array|
63
+ registry, _ = array
64
+ registry.name
65
+ end
66
+
67
+ metadata_map = {}
68
+
69
+ @sets.each_with_index do |array, i|
70
+ padded_i = "%03d" % i
71
+ registry, metadata = array
72
+ name, resource = registry.name, registry.resource
73
+
74
+ metadata_map[resource] ||= {"AWS::CloudFormation::Init" => {"configSets" => {}}}
75
+ configSets = metadata_map[resource]["AWS::CloudFormation::Init"]["configSets"]
76
+
77
+ configSets["default"] ||= []
78
+ configSets["default"] << {"ConfigSet" => name}
79
+
80
+ validate_structure!(name, metadata)
81
+ init = metadata["AWS::CloudFormation::Init"]
82
+
83
+ if init.key?("configSets")
84
+ cs = init.delete("configSets") # Only support configSets with simple Array of Strings
85
+ validate_simple!(registry, cs)
86
+ configSets[name] = cs["default"].map {|c| "#{padded_i}_#{c}" }
87
+ init.transform_keys! { |c| "#{padded_i}_#{c}" }
88
+ else # simple config
89
+ config_key = "#{padded_i}_single_generated"
90
+ configSets[name] = [config_key]
91
+ init = {config_key => init["config"]}
92
+ end
93
+
94
+ metadata_map[resource]["AWS::CloudFormation::Init"].merge!(init)
95
+ @map[resource] = metadata_map[resource]
96
+ end
97
+ @map
98
+ end
99
+
100
+ def validate_structure!(name, metadata)
101
+ return if metadata.is_a?(Hash) && metadata.key?("AWS::CloudFormation::Init")
102
+
103
+ puts "ERROR: The #{name} configset does not appear to have a AWS::CloudFormation::Init key".color(:red)
104
+ puts "Please double check the #{name} configset.yml structure"
105
+ exit 1
106
+ end
107
+
108
+ def validate_simple!(registry, cs)
109
+ has_complex_type = cs["default"].detect { |s| !s.is_a?(String) }
110
+ if has_complex_type
111
+ message =<<~EOL
112
+ ERROR: The configset #{registry.name} has a configSets property with a complex type.
113
+ configSets:
114
+
115
+ #{cs}
116
+
117
+ lono configsets only supports combining configSets with an Array of Strings.
118
+ EOL
119
+ if ENV['LONO_TEST']
120
+ raise message
121
+ else
122
+ puts message.color(:red)
123
+ exit 1
124
+ end
125
+ end
126
+ end
127
+ end
128
+ end