lono 8.0.0.pre.rc3 → 8.0.0.pre.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +84 -0
  3. data/.github/ISSUE_TEMPLATE/documentation.md +12 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +64 -0
  5. data/.github/ISSUE_TEMPLATE/question.md +14 -0
  6. data/.github/ISSUE_TEMPLATE.md +7 -0
  7. data/.github/PULL_REQUEST_TEMPLATE.md +50 -0
  8. data/CHANGELOG.md +33 -0
  9. data/lib/lono/app.rb +37 -3
  10. data/lib/lono/builder/allow.rb +1 -1
  11. data/lib/lono/builder/configset/definition/context.rb +50 -9
  12. data/lib/lono/builder/configset/definition/dsl/syntax/content.rb +3 -7
  13. data/lib/lono/builder/context.rb +1 -1
  14. data/lib/lono/builder/dsl/finalizer/files/build.rb +4 -12
  15. data/lib/lono/builder/dsl/finalizer/files/replace.rb +6 -1
  16. data/lib/lono/builder/dsl/helpers/files.rb +2 -2
  17. data/lib/lono/builder/dsl/helpers/s3.rb +5 -7
  18. data/lib/lono/builder/dsl/helpers/stack.rb +2 -4
  19. data/lib/lono/builder/dsl/helpers/template_file.rb +2 -2
  20. data/lib/lono/builder/dsl/syntax/core/squeezer.rb +3 -1
  21. data/lib/lono/builder/dsl/syntax/fn.rb +0 -2
  22. data/lib/lono/builder/dsl.rb +1 -1
  23. data/lib/lono/builder/param.rb +1 -1
  24. data/lib/lono/builder/template.rb +1 -3
  25. data/lib/lono/builder.rb +39 -0
  26. data/lib/lono/bundler/util/git.rb +18 -16
  27. data/lib/lono/cfn/base.rb +2 -2
  28. data/lib/lono/cfn/concerns/build.rb +1 -1
  29. data/lib/lono/cfn/delete.rb +5 -2
  30. data/lib/lono/cfn/deploy/rollback.rb +1 -3
  31. data/lib/lono/cfn/deploy.rb +16 -4
  32. data/lib/lono/cfn/plan/changeset.rb +1 -1
  33. data/lib/lono/cli/base.rb +1 -0
  34. data/lib/lono/cli/help/new/helper.md +27 -0
  35. data/lib/lono/cli/help/new/hook.md +14 -0
  36. data/lib/lono/cli/help/new/project.md +3 -10
  37. data/lib/lono/cli/iam.rb +27 -0
  38. data/lib/lono/cli/new/blueprint.rb +2 -4
  39. data/lib/lono/cli/new/helper.rb +35 -8
  40. data/lib/lono/cli/new/hook.rb +32 -0
  41. data/lib/lono/cli/new.rb +8 -4
  42. data/lib/lono/cli/script/build.rb +0 -5
  43. data/lib/lono/{inspector → cli}/summary.rb +23 -30
  44. data/lib/lono/cli.rb +9 -7
  45. data/lib/lono/command.rb +28 -1
  46. data/lib/lono/core.rb +10 -0
  47. data/lib/lono/{utils → files/builder/lambda_layer}/rsync.rb +3 -5
  48. data/lib/lono/files/builder/lambda_layer/ruby_packager.rb +178 -0
  49. data/lib/lono/files/builder/lambda_layer/ruby_version.rb +38 -0
  50. data/lib/lono/files/builder/lambda_layer.rb +17 -0
  51. data/lib/lono/files/concerns/post_processing.rb +19 -2
  52. data/lib/lono/files/concerns/registration.rb +4 -1
  53. data/lib/lono/files.rb +6 -2
  54. data/lib/lono/hooks/builder.rb +50 -0
  55. data/lib/lono/hooks/concern.rb +9 -0
  56. data/lib/lono/hooks/dsl.rb +20 -0
  57. data/lib/lono/hooks/runner.rb +46 -0
  58. data/lib/lono/layering/layer.rb +63 -41
  59. data/lib/lono/names.rb +6 -9
  60. data/lib/lono/s3/bucket.rb +17 -11
  61. data/lib/lono/s3/uploader.rb +4 -0
  62. data/lib/lono/script/build.rb +0 -5
  63. data/lib/lono/seeder.rb +1 -1
  64. data/lib/lono/utils/sh.rb +32 -0
  65. data/lib/lono/utils.rb +5 -0
  66. data/lib/lono/version.rb +1 -1
  67. data/lib/templates/hook/config/hooks.rb.tt +14 -0
  68. data/lono.gemspec +1 -1
  69. metadata +27 -30
  70. data/lib/lono/builder/template/post_processor.rb +0 -67
  71. data/lib/lono/cli/build.rb +0 -47
  72. data/lib/lono/cli/code.rb +0 -22
  73. data/lib/lono/cli/help/blueprint/new.md +0 -56
  74. data/lib/lono/cli/help/new/helper/blueprint.md +0 -17
  75. data/lib/lono/cli/help/new/helper/project.md +0 -16
  76. data/lib/lono/cli/new/extension.rb +0 -57
  77. data/lib/lono/cli/new/helper/blueprint.rb +0 -26
  78. data/lib/lono/cli/new/helper/project.rb +0 -24
  79. data/lib/lono/importer/base.rb +0 -48
  80. data/lib/lono/importer/converter.rb +0 -19
  81. data/lib/lono/importer/download.rb +0 -46
  82. data/lib/lono/importer/dsl.rb +0 -36
  83. data/lib/lono/importer/params.rb +0 -56
  84. data/lib/lono/importer/service/coder.rb +0 -85
  85. data/lib/lono/inspector/base.rb +0 -32
  86. data/lib/templates/extension/lib/%extension_name%/autoloader.rb.tt +0 -23
  87. data/lib/templates/extension/lib/%extension_name%/helpers/mappings.rb.tt +0 -24
  88. data/lib/templates/extension/lib/%extension_name%/helpers/outputs.rb.tt +0 -7
  89. data/lib/templates/extension/lib/%extension_name%/helpers/parameters.rb.tt +0 -10
  90. data/lib/templates/extension/lib/%extension_name%/helpers/resources/resource.rb.tt +0 -4
  91. data/lib/templates/extension/lib/%extension_name%/helpers/variables.rb.tt +0 -6
  92. data/lib/templates/extension/lib/%extension_name%/version.rb.tt +0 -3
  93. data/lib/templates/extension/lib/%extension_name%.rb.tt +0 -8
@@ -1,19 +0,0 @@
1
- class Lono::Importer
2
- class Converter
3
- include Download
4
-
5
- # source is a path
6
- def initialize(options={})
7
- @options = options
8
- @source = options[:source]
9
- end
10
-
11
- def run
12
- tmp_path = "/tmp/lono/import/template.yml"
13
- tmp_template_path = download_template(@source, tmp_path)
14
- template = IO.read(tmp_template_path)
15
- coder = Service::Coder.new(template, @options)
16
- coder.translate
17
- end
18
- end
19
- end
@@ -1,46 +0,0 @@
1
- require "json"
2
- require "open-uri"
3
- require "yaml"
4
-
5
- class Lono::Importer
6
- module Download
7
- def download_template(source, dest_path)
8
- template = read_source(source)
9
-
10
- result = if json?(template)
11
- # abusing YAML.dump(YAML.load()) to convert json to yaml
12
- YAML.dump(YAML.load(template))
13
- else
14
- template # template is already in YAML format
15
- end
16
-
17
- folder = File.dirname(dest_path)
18
- FileUtils.mkdir_p(folder) unless File.exist?(folder)
19
- IO.write(dest_path, result)
20
- dest_path
21
- end
22
-
23
- def read_source(source)
24
- open(source).read
25
- rescue OpenURI::HTTPError, SocketError, Errno::ENOENT
26
- logger.info "ERROR: Unable to read source template provided: #{source}".color(:red)
27
- e = $!
28
- logger.info "#{e.class}: #{e.message}"
29
- logger.info "Please double check the source provided."
30
- exit 1
31
- rescue Exception => e
32
- logger.info "ERROR: Unable to read source template provided: #{source}".color(:red)
33
- logger.info "General Exception Error:"
34
- logger.info "#{e.class}: #{e.message}"
35
- logger.info "Please double check the source provided."
36
- exit 1
37
- end
38
-
39
- def json?(text)
40
- JSON.load(text)
41
- true # if reach here than it's just
42
- rescue JSON::ParserError
43
- false # not json
44
- end
45
- end
46
- end
@@ -1,36 +0,0 @@
1
- class Lono::Importer
2
- class Dsl < Base
3
- def run
4
- tmp_template_path = download_template(@source, @tmp_path)
5
- template = IO.read(tmp_template_path)
6
-
7
- Lono::Blueprint::New.start([@blueprint.name, "--import", "--type", "dsl"])
8
-
9
- translate_to_dsl(template)
10
- create_params(tmp_template_path)
11
- # Let's not summarize the template in case the Ruby syntax is invalid with the import coder.
12
- # Add summarize back in later
13
- # summarize
14
-
15
- final_message
16
- end
17
-
18
- def translate_to_dsl(template)
19
- coder = Service::Coder.new(template, @options)
20
- result = coder.translate
21
-
22
- path = "#{Lono.config.paths.templates}/#{@template}.rb"
23
- FileUtils.mkdir_p(File.dirname(path))
24
- create_file(path, result) # Thor::Action
25
- end
26
-
27
- def final_message
28
- logger.info <<~EOL
29
- #{"="*64}
30
- Congrats 🎉 You have successfully imported a lono blueprint.
31
-
32
- More info: https://lono.cloud/docs/core/blueprints
33
- EOL
34
- end
35
- end
36
- end
@@ -1,56 +0,0 @@
1
- class Lono::Importer
2
- class Params
3
- include Thor::Actions
4
- include Thor::Base
5
- extend Memoist
6
-
7
- attr_reader :options
8
- def initialize(template_path, params_path)
9
- @template_path, @params_path = template_path, params_path
10
- @params_path = normalize_path(@params_path)
11
- self.destination_root = Dir.pwd # Thor::Actions require destination_root to be set
12
- @options = {} # For Thor::Actions to work
13
- end
14
-
15
- # Creates starter params/base/[stack-name].txt file
16
- def create
17
- result = []
18
- required_parameters.each do |name, attributes|
19
- result << "#{name}=#{attributes["Default"]}"
20
- end
21
- optional_parameters.each do |name, attributes|
22
- key = "#{name}=".ljust(20, ' ')
23
- result << "##{key} # optional"
24
- end
25
- content = result.join("\n") + "\n"
26
-
27
-
28
- folder = File.dirname(@params_path)
29
- FileUtils.mkdir_p(folder) unless File.exist?(folder)
30
- create_file(@params_path, content) # Thor::Action
31
- end
32
-
33
- def required_parameters
34
- parameters.reject { |logical_id, p| p["Default"] }
35
- end
36
-
37
- def optional_parameters
38
- parameters.select { |logical_id, p| p["Default"] }
39
- end
40
-
41
- def parameters
42
- template_data["Parameters"] || []
43
- end
44
-
45
- def template_data
46
- YAML.load(IO.read(@template_path))
47
- end
48
- memoize :template_data
49
-
50
- private
51
- # Add Lono.root if not already there, helps cli_spec.rb to pass
52
- def normalize_path(path)
53
- path.include?(Lono.root.to_s) ? path : "#{Lono.root}/#{path}"
54
- end
55
- end
56
- end
@@ -1,85 +0,0 @@
1
- require 'base64'
2
- require 'json'
3
- require 'net/http'
4
-
5
- module Lono::Importer::Service
6
- class Coder
7
- include Lono::Utils::Logging
8
-
9
- def initialize(template, options={})
10
- @template, @options = template, options
11
- end
12
-
13
- def translate
14
- url = "#{Lono::API}/code"
15
- http = net_http_client(url)
16
- req = net_http_request(url,
17
- template: Base64.encode64(@template), # Base64 JSON for special chars that Rack::LintWrapper cannot process
18
- lono_version: Lono::VERSION,
19
- lono_command: lono_command,
20
- )
21
- res = http.request(req) # send request
22
-
23
- if res.code == "200"
24
- data = JSON.load(res.body)
25
- ruby_code = print(data) # returns data["ruby_code"] / passthrough
26
- ruby_code
27
- else
28
- logger.info "Error: Unable to convert template to Ruby code."
29
- logger.info "The error has been reported."
30
- logger.info "Non-successful http response status code: #{res.code}"
31
- # logger.info "headers: #{res.each_header.to_h.inspect}"
32
- exit 1
33
- end
34
- end
35
-
36
- private
37
- def print(data)
38
- return if ENV['LONO_PRO_TEST']
39
-
40
- if data["error"]
41
- # Code was processed but there was this error with an HTTP 200 OK
42
- logger.info "ERROR: #{data["error"]}".color(:red)
43
- if data["message"]
44
- logger.info data["message"]
45
- end
46
- return
47
- end
48
-
49
- validity = data["valid_ruby"] ? "valid" : "invalid"
50
- if validity == "valid"
51
- logger.info "INFO: The generated Ruby code is has #{validity} syntax."
52
- else
53
- logger.info "WARN: The generated Ruby code is has #{validity} syntax. Providing because it may be small errors.".color(:yellow) # note redirection disables color
54
- end
55
-
56
- logger.info <<~EOL
57
- Translated ruby code below:
58
-
59
- EOL
60
- ruby_code = data["ruby_code"]
61
- logger.info ruby_code
62
- ruby_code
63
- end
64
-
65
- def net_http_client(url)
66
- uri = URI(url)
67
- http = Net::HTTP.new(uri.host, uri.port)
68
- http.open_timeout = http.read_timeout = 30
69
- http.use_ssl = true if uri.scheme == 'https'
70
- http
71
- end
72
-
73
- def net_http_request(url, data)
74
- req = Net::HTTP::Post.new(url) # url includes query string and uri.path does not, must used url
75
- text = JSON.dump(data)
76
- req.body = text
77
- req.content_length = text.bytesize
78
- req
79
- end
80
-
81
- def lono_command
82
- "#{$0} #{ARGV.join(' ')}"
83
- end
84
- end
85
- end
@@ -1,32 +0,0 @@
1
- module Lono::Inspector
2
- class Base < Lono::CLI::Base
3
- extend Memoist
4
-
5
- def run
6
- build
7
- templates = @template_name ? [@template_name] : all_templates
8
- templates.each do |template_name|
9
- perform(template_name)
10
- end
11
- end
12
-
13
- def build
14
- if @options[:source]
15
- Lono::Cfn::Download.new(@options).run
16
- else
17
- build_templates
18
- end
19
- end
20
-
21
- def build_templates
22
- Lono::Builder::Template.new(@options.merge(quiet: false)).run
23
- end
24
-
25
- def all_templates
26
- templates_path = "#{Lono.root}/output/#{@blueprint.name}/templates"
27
- Dir.glob("#{templates_path}/**").map do |path|
28
- path.sub("#{templates_path}/", '').sub('.yml','') # template_name
29
- end
30
- end
31
- end
32
- end
@@ -1,23 +0,0 @@
1
- require "zeitwerk"
2
-
3
- module <%= extension_class_name %>
4
- class Autoloader
5
- class Inflector < Zeitwerk::Inflector
6
- def camelize(basename, _abspath)
7
- map = { cli: "CLI", version: "VERSION" }
8
- map[basename.to_sym] || super
9
- end
10
- end
11
-
12
- class << self
13
- def setup
14
- loader = Zeitwerk::Loader.new
15
- loader.inflector = Inflector.new
16
- loader.push_dir(File.dirname(__dir__)) # lib
17
- # loader.log!
18
- loader.ignore("#{__dir__}/user_data")
19
- loader.setup
20
- end
21
- end
22
- end
23
- end
@@ -1,24 +0,0 @@
1
- module <%= extension_class_name %>::Helpers
2
- module Mappings
3
- def ami_mappings
4
- mapping("AmiMap",
5
- "ap-northeast-1": { Ami: "ami-011facbea5ec0363b" },
6
- "ap-northeast-2": { Ami: "ami-0bea7fd38fabe821a" },
7
- "ap-south-1": { Ami: "ami-0217a85e28e625474" },
8
- "ap-southeast-1": { Ami: "ami-05c64f7b4062b0a21" },
9
- "ap-southeast-2": { Ami: "ami-0b8b10b5bf11f3a22" },
10
- "ca-central-1": { Ami: "ami-0a269ca7cc3e3beff" },
11
- "eu-central-1": { Ami: "ami-07cda0db070313c52" },
12
- "eu-north-1": { Ami: "ami-0662eb9b9b8685935" },
13
- "eu-west-1": { Ami: "ami-0713f98de93617bb4" },
14
- "eu-west-2": { Ami: "ami-0089b31e09ac3fffc" },
15
- "eu-west-3": { Ami: "ami-007fae589fdf6e955" },
16
- "sa-east-1": { Ami: "ami-09de7b4017733e2af" },
17
- "us-east-1": { Ami: "ami-062f7200baf2fa504" },
18
- "us-east-2": { Ami: "ami-02ccb28830b645a41" },
19
- "us-west-1": { Ami: "ami-03caa3f860895f82e" },
20
- "us-west-2": { Ami: "ami-04590e7389a6e577c" }
21
- )
22
- end
23
- end
24
- end
@@ -1,7 +0,0 @@
1
- module <%= extension_class_name %>::Helpers
2
- module Outputs
3
- def resource1_output
4
- output("Resource1")
5
- end
6
- end
7
- end
@@ -1,10 +0,0 @@
1
- module <%= extension_class_name %>::Helpers
2
- module Parameters
3
- def example_parameters
4
- parameter_group("AWS::Service::Resource") do
5
- parameter("Parameter1")
6
- parameter("Parameter2")
7
- end
8
- end
9
- end
10
- end
@@ -1,4 +0,0 @@
1
- module <%= extension_class_name %>::Helpers::Resources
2
- module Resource
3
- end
4
- end
@@ -1,6 +0,0 @@
1
- module <%= extension_class_name %>::Helpers
2
- module Variables
3
- # AWS::Service::Resource example
4
- attr_reader :property1, :property2
5
- end
6
- end
@@ -1,3 +0,0 @@
1
- module <%= extension_class_name %>
2
- VERSION = "0.1.0"
3
- end
@@ -1,8 +0,0 @@
1
- $:.unshift(File.expand_path("../", __FILE__))
2
- require "<%= extension_underscore_name %>/version"
3
-
4
- require "<%= extension_underscore_name %>/autoloader"
5
- <%= extension_class_name %>::Autoloader.setup
6
-
7
- module <%= extension_class_name %>
8
- end