lono-pro 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +1 -1
- data/lib/lono/pro/code.rb +1 -1
- data/lib/lono/pro/help/convert.md +50 -2
- data/lib/lono/pro/help/import.md +11 -2
- data/lib/lono/pro/importer/base.rb +3 -28
- data/lib/lono/pro/importer/converter.rb +6 -1
- data/lib/lono/pro/importer/download.rb +46 -0
- data/lib/lono/pro/importer/dsl.rb +5 -4
- data/lib/lono/pro/importer/erb.rb +2 -3
- data/lib/lono/pro/importer/service/coder.rb +24 -20
- data/lib/lono/pro/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d3d921141c36b14bbfedbe78646c6e09966fd55dfd0d13f809cfbb50b7fb44a
|
4
|
+
data.tar.gz: 54d5618c7985e3a578f2f9f51c88e0e56dda900f1d5542308e728b09d07b3cee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0228935145363b2238c72b9f61245043d233bbce07c39ad0a3b9a4722f6aaf6894e2d33168170bd0e5d272ac4397b2411b243ff656877f1287673a925e97f2f3'
|
7
|
+
data.tar.gz: 3507512cf1e0c40e0b42d3d36322c61425e4725d01d877f6211cabc7dc26fb1bde8fce3ec028ea8972293ecc09b8a93c094473a1d7d4c5ce8b7a8ff47c609d97
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,10 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *tries* to adhere to [Semantic Versioning](http://semver.org/), even before v1.0.
|
5
5
|
|
6
|
+
## [0.3.0]
|
7
|
+
- only print ruby code to stdout with lono code convert
|
8
|
+
- source can be file or url source
|
9
|
+
|
6
10
|
## [0.2.0]
|
7
11
|
- lono code convert
|
8
12
|
- lono code import
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Lono pro is a paid addon that adds additional features to [lono](https://lono.cloud). Notably, the `lono code import` and `lono code convert` commands.
|
4
4
|
|
5
|
-
The conversion process
|
5
|
+
The conversion process gets you 80% of the way here. It saves you time.
|
6
6
|
|
7
7
|
## Usage
|
8
8
|
|
data/lib/lono/pro/code.rb
CHANGED
@@ -16,7 +16,7 @@ module Lono::Pro
|
|
16
16
|
long_desc Help.text(:convert)
|
17
17
|
option :casing, default: "as-is", desc: "Controls casing of logical ids. IE: as-is, camelcase or underscore"
|
18
18
|
def convert(source)
|
19
|
-
Importer::Converter.new(source, options).run
|
19
|
+
Importer::Converter.new(source, options.merge(print: true)).run
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
@@ -1,3 +1,51 @@
|
|
1
|
-
##
|
1
|
+
## Examples
|
2
2
|
|
3
|
-
lono code convert path/to/file
|
3
|
+
lono code convert path/to/file
|
4
|
+
lono code convert http://example.com/url/to/template.yml
|
5
|
+
lono code convert http://example.com/url/to/template.json
|
6
|
+
|
7
|
+
## Example with Output
|
8
|
+
|
9
|
+
$ lono code convert https://s3-us-east-2.amazonaws.com/cloudformation-templates-us-east-2/AutoScalingMultiAZWithNotifications.template
|
10
|
+
INFO: The ruby syntax is invalid
|
11
|
+
INFO: Translated ruby code below:
|
12
|
+
|
13
|
+
aws_template_format_version "2010-09-09"
|
14
|
+
parameter("VpcId",
|
15
|
+
type: "AWS::EC2::VPC::Id",
|
16
|
+
description: "VpcId of your existing Virtual Private Cloud (VPC)",
|
17
|
+
constraint_description: "must be the VPC Id of an existing Virtual Private Cloud."
|
18
|
+
)
|
19
|
+
...
|
20
|
+
...
|
21
|
+
...
|
22
|
+
resource("InstanceSecurityGroup", "AWS::EC2::SecurityGroup",
|
23
|
+
group_description: "Enable SSH access and HTTP from the load balancer only",
|
24
|
+
security_group_ingress: [
|
25
|
+
{
|
26
|
+
ip_protocol: "tcp",
|
27
|
+
from_port: "22",
|
28
|
+
to_port: "22",
|
29
|
+
cidr_ip: ref("SSHLocation")
|
30
|
+
},
|
31
|
+
{
|
32
|
+
ip_protocol: "tcp",
|
33
|
+
from_port: "80",
|
34
|
+
to_port: "80",
|
35
|
+
source_security_group_id: select(0,get_att("ApplicationLoadBalancer","SecurityGroups"))
|
36
|
+
}
|
37
|
+
],
|
38
|
+
vpc_id: ref("VpcId")
|
39
|
+
)
|
40
|
+
output("URL",
|
41
|
+
description: "The URL of the website",
|
42
|
+
value: join("",[
|
43
|
+
"http://",
|
44
|
+
get_att("ApplicationLoadBalancer","DNSName")
|
45
|
+
])
|
46
|
+
)
|
47
|
+
|
48
|
+
The `INFO` messages are written to stderr so you can grab the translated template Ruby code by directing it to a file. Example:
|
49
|
+
|
50
|
+
lono code convert https://s3-us-east-2.amazonaws.com/cloudformation-templates-us-east-2/AutoScalingMultiAZWithNotifications.template > autoscaling.rb
|
51
|
+
cat autoscaling.rb
|
data/lib/lono/pro/help/import.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
-
##
|
1
|
+
## Examples
|
2
2
|
|
3
|
-
lono code import path/to/file
|
3
|
+
lono code import path/to/file
|
4
|
+
lono code import http://example.com/url/to/template.yml
|
5
|
+
lono code import http://example.com/url/to/template.json
|
6
|
+
|
7
|
+
## Example with Output
|
8
|
+
|
9
|
+
$ lono code import https://s3-us-east-2.amazonaws.com/cloudformation-templates-us-east-2/asg.template
|
10
|
+
Template imported to: blueprints/asg/app/templates/asg.rb
|
11
|
+
Params file created at configs/asg/development.txt
|
12
|
+
$
|
@@ -1,9 +1,7 @@
|
|
1
|
-
require "open-uri"
|
2
|
-
require "json"
|
3
|
-
require "yaml"
|
4
|
-
|
5
1
|
class Lono::Pro::Importer
|
6
2
|
class Base
|
3
|
+
include Download
|
4
|
+
|
7
5
|
def initialize(source, options)
|
8
6
|
@source, @options = source, options
|
9
7
|
@blueprint = @options[:blueprint] || blueprint_name
|
@@ -39,7 +37,7 @@ class Lono::Pro::Importer
|
|
39
37
|
end
|
40
38
|
|
41
39
|
def create_dot_lono(type)
|
42
|
-
dot_lono = "#{Lono.blueprint_root}/.
|
40
|
+
dot_lono = "#{Lono.blueprint_root}/.meta"
|
43
41
|
FileUtils.mkdir_p(dot_lono)
|
44
42
|
config = {
|
45
43
|
"blueprint_name" => @blueprint,
|
@@ -55,28 +53,5 @@ class Lono::Pro::Importer
|
|
55
53
|
name = File.basename(@source, ".*")
|
56
54
|
@options[:casing] == "camelcase" ? name.camelize : name.underscore.dasherize
|
57
55
|
end
|
58
|
-
|
59
|
-
def download_template(dest_path)
|
60
|
-
template = open(@source).read
|
61
|
-
|
62
|
-
result = if json?(template)
|
63
|
-
# abusing YAML.dump(YAML.load()) to convert json to yaml
|
64
|
-
YAML.dump(YAML.load(template))
|
65
|
-
else
|
66
|
-
template # template is already in YAML format
|
67
|
-
end
|
68
|
-
|
69
|
-
folder = File.dirname(dest_path)
|
70
|
-
FileUtils.mkdir_p(folder) unless File.exist?(folder)
|
71
|
-
IO.write(dest_path, result)
|
72
|
-
dest_path
|
73
|
-
end
|
74
|
-
|
75
|
-
def json?(text)
|
76
|
-
JSON.load(text)
|
77
|
-
true # if reach here than it's just
|
78
|
-
rescue JSON::ParserError
|
79
|
-
false # not json
|
80
|
-
end
|
81
56
|
end
|
82
57
|
end
|
@@ -1,12 +1,17 @@
|
|
1
1
|
class Lono::Pro::Importer
|
2
2
|
class Converter
|
3
|
+
include Download
|
4
|
+
|
3
5
|
# source is a path
|
4
6
|
def initialize(source, options)
|
5
7
|
@source, @options = source, options
|
6
8
|
end
|
7
9
|
|
8
10
|
def run
|
9
|
-
|
11
|
+
tmp_path = "/tmp/lono/import/template.yml"
|
12
|
+
tmp_template_path = download_template(@source, tmp_path)
|
13
|
+
template = IO.read(tmp_template_path)
|
14
|
+
coder = Service::Coder.new(template, @options)
|
10
15
|
puts coder.translate
|
11
16
|
end
|
12
17
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require "json"
|
2
|
+
require "open-uri"
|
3
|
+
require "yaml"
|
4
|
+
|
5
|
+
class Lono::Pro::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
|
+
puts "ERROR: Unable to read source template provided: #{source}".color(:red)
|
27
|
+
e = $!
|
28
|
+
puts "#{e.class}: #{e.message}"
|
29
|
+
puts "Please double check the source provided."
|
30
|
+
exit 1
|
31
|
+
rescue Exception => e
|
32
|
+
puts "ERROR: Unable to read source template provided: #{source}".color(:red)
|
33
|
+
puts "General Exception Error:"
|
34
|
+
puts "#{e.class}: #{e.message}"
|
35
|
+
puts "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,8 +1,9 @@
|
|
1
1
|
class Lono::Pro::Importer
|
2
2
|
class Dsl < Base
|
3
3
|
def run
|
4
|
-
tmp_template_path = download_template(@tmp_path)
|
5
|
-
|
4
|
+
tmp_template_path = download_template(@source, @tmp_path)
|
5
|
+
template = IO.read(tmp_template_path)
|
6
|
+
translate_to_dsl(template)
|
6
7
|
create_dot_lono("dsl")
|
7
8
|
create_params(tmp_template_path)
|
8
9
|
# Let's not summarize the template in case the Ruby syntax is invalid with the import coder.
|
@@ -10,8 +11,8 @@ class Lono::Pro::Importer
|
|
10
11
|
# summarize
|
11
12
|
end
|
12
13
|
|
13
|
-
def translate_to_dsl(
|
14
|
-
coder = Service::Coder.new(
|
14
|
+
def translate_to_dsl(template)
|
15
|
+
coder = Service::Coder.new(template, @options)
|
15
16
|
result = coder.translate
|
16
17
|
|
17
18
|
path = "#{Lono.config.templates_path}/#{@template}.rb"
|
@@ -1,10 +1,9 @@
|
|
1
1
|
class Lono::Pro::Importer
|
2
2
|
class Erb < Base
|
3
3
|
def run
|
4
|
-
template_path = "#{Lono.config.templates_path}/#{@template}.yml"
|
5
|
-
|
6
4
|
puts "=> Imported CloudFormation template.".color(:green)
|
7
|
-
|
5
|
+
template_path = "#{Lono.config.templates_path}/#{@template}.yml"
|
6
|
+
download_template(@source, template_path)
|
8
7
|
puts "Template downloaded to #{pretty_path(template_path)}"
|
9
8
|
|
10
9
|
create_dot_lono("erb")
|
@@ -5,18 +5,16 @@ require 'net/http'
|
|
5
5
|
class Lono::Pro::Importer::Service::Coder
|
6
6
|
LONO_API = ENV['LONO_API'] || 'https://api.lono.cloud/v1'
|
7
7
|
|
8
|
-
def initialize(
|
9
|
-
@
|
10
|
-
@template = File.exist?(@source) ? IO.read(@source) : @source
|
8
|
+
def initialize(template, options={})
|
9
|
+
@template, @options = template, options
|
11
10
|
end
|
12
11
|
|
13
12
|
def translate
|
14
13
|
url = "#{LONO_API}/code"
|
14
|
+
|
15
15
|
http = net_http_client(url)
|
16
|
-
req =
|
17
|
-
|
18
|
-
# Base64 JSON to handle special chars that Rack::LintWrapper cannot process
|
19
|
-
template: Base64.encode64(@template),
|
16
|
+
req = net_http_request(url,
|
17
|
+
template: Base64.encode64(@template), # Base64 JSON for special chars that Rack::LintWrapper cannot process
|
20
18
|
lono_version: Lono::VERSION,
|
21
19
|
lono_pro_version: Lono::Pro::VERSION,
|
22
20
|
lono_command: lono_command,
|
@@ -25,24 +23,29 @@ class Lono::Pro::Importer::Service::Coder
|
|
25
23
|
|
26
24
|
if res.code == "200"
|
27
25
|
data = JSON.load(res.body)
|
28
|
-
|
29
|
-
|
30
|
-
INFO: The ruby syntax is #{validity}
|
31
|
-
Translated ruby code below:
|
32
|
-
|
33
|
-
EOL
|
34
|
-
ruby_code = data["ruby_code"]
|
35
|
-
puts ruby_code
|
36
|
-
ruby_code
|
37
|
-
# TODO: improve error messaging
|
26
|
+
print(data)
|
27
|
+
data["ruby_code"]
|
38
28
|
else
|
39
|
-
puts "
|
40
|
-
puts "
|
29
|
+
puts "Unable to convert template to ruby code."
|
30
|
+
puts "The error has been reported."
|
31
|
+
puts "Non-successful http response status code: #{res.code}"
|
41
32
|
# puts "headers: #{res.each_header.to_h.inspect}"
|
42
33
|
end
|
43
34
|
end
|
44
35
|
|
45
36
|
private
|
37
|
+
def print(data)
|
38
|
+
return unless @options[:print]
|
39
|
+
validity = data["valid_ruby"] ? "valid" : "invalid"
|
40
|
+
$stderr.puts <<~EOL
|
41
|
+
INFO: The ruby syntax is #{validity}
|
42
|
+
INFO: Translated ruby code below:
|
43
|
+
|
44
|
+
EOL
|
45
|
+
ruby_code = data["ruby_code"]
|
46
|
+
puts ruby_code
|
47
|
+
end
|
48
|
+
|
46
49
|
def net_http_client(url)
|
47
50
|
uri = URI(url)
|
48
51
|
http = Net::HTTP.new(uri.host, uri.port)
|
@@ -51,7 +54,8 @@ private
|
|
51
54
|
http
|
52
55
|
end
|
53
56
|
|
54
|
-
def
|
57
|
+
def net_http_request(url, data)
|
58
|
+
req = Net::HTTP::Post.new(url) # url includes query string and uri.path does not, must used url
|
55
59
|
text = JSON.dump(data)
|
56
60
|
req.body = text
|
57
61
|
req.content_length = text.bytesize
|
data/lib/lono/pro/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lono-pro
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- lib/lono/pro/importer.rb
|
93
93
|
- lib/lono/pro/importer/base.rb
|
94
94
|
- lib/lono/pro/importer/converter.rb
|
95
|
+
- lib/lono/pro/importer/download.rb
|
95
96
|
- lib/lono/pro/importer/dsl.rb
|
96
97
|
- lib/lono/pro/importer/erb.rb
|
97
98
|
- lib/lono/pro/importer/params.rb
|