lono 6.1.11 → 7.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.cody/acceptance.sh +19 -3
- data/.gitignore +2 -2
- data/CHANGELOG.md +16 -1
- data/README.md +18 -20
- data/Rakefile +1 -0
- data/lib/lono.rb +7 -5
- data/lib/lono/abstract_base.rb +25 -0
- data/lib/lono/api/client.rb +30 -0
- data/lib/lono/api/proxy.rb +58 -0
- data/lib/lono/api/repos.rb +8 -0
- data/lib/lono/api/verify.rb +13 -0
- data/lib/lono/app_file/base.rb +4 -11
- data/lib/lono/app_file/build.rb +1 -1
- data/lib/lono/app_file/upload.rb +1 -4
- data/lib/lono/autoloader.rb +3 -1
- data/lib/lono/aws_services.rb +9 -9
- data/lib/lono/aws_services/helper.rb +14 -0
- data/lib/lono/aws_services/{util.rb → stack.rb} +1 -9
- data/lib/lono/aws_services/stack_set.rb +41 -0
- data/lib/lono/blueprint.rb +2 -2
- data/lib/lono/blueprint/configset/loader.rb +7 -0
- data/lib/lono/blueprint/helper.rb +8 -2
- data/lib/lono/blueprint/meta.rb +4 -12
- data/lib/lono/blueprint/new.rb +3 -3
- data/lib/lono/blueprint/root.rb +6 -26
- data/lib/lono/bundle.rb +54 -0
- data/lib/lono/cfn.rb +31 -75
- data/lib/lono/cfn/base.rb +39 -136
- data/lib/lono/cfn/cancel.rb +14 -9
- data/lib/lono/cfn/create.rb +15 -19
- data/lib/lono/cfn/delete.rb +9 -9
- data/lib/lono/cfn/deploy.rb +4 -4
- data/lib/lono/cfn/download.rb +27 -9
- data/lib/lono/cfn/opts.rb +80 -0
- data/lib/lono/cfn/preview/changeset.rb +23 -23
- data/lib/lono/cfn/preview/codediff.rb +5 -6
- data/lib/lono/cfn/preview/param.rb +10 -10
- data/lib/lono/cfn/rollback.rb +5 -5
- data/lib/lono/cfn/status.rb +0 -10
- data/lib/lono/cfn/update.rb +22 -27
- data/lib/lono/clean.rb +3 -3
- data/lib/lono/cli.rb +69 -34
- data/lib/lono/code.rb +22 -0
- data/lib/lono/command.rb +7 -0
- data/lib/lono/config_location.rb +6 -13
- data/lib/lono/configset.rb +9 -0
- data/lib/lono/configset/combiner.rb +128 -0
- data/lib/lono/configset/evaluate_file.rb +8 -0
- data/lib/lono/configset/list.rb +67 -0
- data/lib/lono/configset/loader.rb +98 -0
- data/lib/lono/configset/loader/dsl.rb +9 -0
- data/lib/lono/configset/materializer/final.rb +10 -0
- data/lib/lono/configset/materializer/gems_builder.rb +81 -0
- data/lib/lono/configset/materializer/jade.rb +15 -0
- data/lib/lono/configset/materializer/source.rb +54 -0
- data/lib/lono/configset/meta.rb +19 -0
- data/lib/lono/configset/meta/dsl.rb +12 -0
- data/lib/lono/configset/new.rb +84 -0
- data/lib/lono/configset/preparer.rb +44 -0
- data/lib/lono/configset/register/base.rb +121 -0
- data/lib/lono/configset/register/blueprint.rb +16 -0
- data/lib/lono/configset/register/dsl.rb +15 -0
- data/lib/lono/configset/register/project.rb +12 -0
- data/lib/lono/configset/registry.rb +34 -0
- data/lib/lono/configset/resolver.rb +42 -0
- data/lib/lono/conventions.rb +18 -7
- data/lib/lono/core.rb +16 -20
- data/lib/lono/default/settings.yml +2 -3
- data/lib/lono/ext/bundler.rb +7 -0
- data/lib/lono/file_uploader.rb +8 -5
- data/lib/lono/finder/base.rb +140 -0
- data/lib/lono/finder/blueprint.rb +11 -0
- data/lib/lono/finder/blueprint/configset.rb +17 -0
- data/lib/lono/finder/configset.rb +11 -0
- data/lib/lono/generate.rb +93 -0
- data/lib/lono/help/blueprint/new.md +0 -1
- data/lib/lono/help/cfn/delete.md +1 -1
- data/lib/lono/help/cfn/deploy.md +5 -76
- data/lib/lono/help/cfn/status.md +0 -4
- data/lib/lono/help/cfn/update.md +1 -1
- data/lib/lono/help/code/convert.md +51 -0
- data/lib/lono/help/code/import.md +30 -0
- data/lib/lono/help/configsets.md +24 -0
- data/lib/lono/help/generate.md +4 -4
- data/lib/lono/help/new.md +1 -2
- data/lib/lono/help/sets/delete.md +8 -0
- data/lib/lono/help/sets/deploy.md +76 -0
- data/lib/lono/help/sets/instances/delete.md +21 -0
- data/lib/lono/help/sets/instances/list.md +14 -0
- data/lib/lono/help/sets/instances/status.md +15 -0
- data/lib/lono/help/sets/instances/sync.md +88 -0
- data/lib/lono/help/sets/status.md +23 -0
- data/lib/lono/help/upgrade.md +1 -0
- data/lib/lono/importer.rb +22 -0
- data/lib/lono/importer/base.rb +59 -0
- data/lib/lono/importer/converter.rb +19 -0
- data/lib/lono/importer/download.rb +46 -0
- data/lib/lono/importer/dsl.rb +36 -0
- data/lib/lono/importer/erb.rb +31 -0
- data/lib/lono/importer/params.rb +56 -0
- data/lib/lono/importer/service/coder.rb +81 -0
- data/lib/lono/inspector/base.rb +12 -22
- data/lib/lono/inspector/graph.rb +1 -1
- data/lib/lono/inspector/summary.rb +41 -17
- data/lib/lono/jade.rb +103 -0
- data/lib/lono/jade/circular.rb +26 -0
- data/lib/lono/jadespec.rb +41 -0
- data/lib/lono/new.rb +2 -2
- data/lib/lono/opts.rb +43 -0
- data/lib/lono/output/template.rb +48 -0
- data/lib/lono/param.rb +3 -5
- data/lib/lono/param/generator.rb +13 -33
- data/lib/lono/pro.rb +15 -0
- data/lib/lono/pro/base.rb +16 -0
- data/lib/lono/pro/repo.rb +27 -0
- data/lib/lono/project_checker.rb +4 -29
- data/lib/lono/registration.rb +15 -0
- data/lib/lono/registration/base.rb +37 -0
- data/lib/lono/registration/check.rb +15 -0
- data/lib/lono/registration/temp.rb +60 -0
- data/lib/lono/registration/user.rb +54 -0
- data/lib/lono/script/base.rb +1 -10
- data/lib/lono/script/upload.rb +2 -12
- data/lib/lono/seed.rb +2 -11
- data/lib/lono/seed/base.rb +55 -110
- data/lib/lono/sets.rb +38 -0
- data/lib/lono/sets/base.rb +45 -0
- data/lib/lono/sets/create.rb +30 -0
- data/lib/lono/sets/delete.rb +47 -0
- data/lib/lono/sets/deploy.rb +11 -0
- data/lib/lono/sets/instances.rb +33 -0
- data/lib/lono/sets/instances/base.rb +30 -0
- data/lib/lono/sets/instances/delete.rb +69 -0
- data/lib/lono/sets/instances/list.rb +13 -0
- data/lib/lono/sets/instances/opts.rb +29 -0
- data/lib/lono/sets/instances/status.rb +12 -0
- data/lib/lono/sets/instances/sync.rb +182 -0
- data/lib/lono/sets/list.rb +35 -0
- data/lib/lono/sets/opts.rb +18 -0
- data/lib/lono/sets/preview/codediff.rb +35 -0
- data/lib/lono/sets/preview/param.rb +32 -0
- data/lib/lono/sets/status.rb +116 -0
- data/lib/lono/sets/status/instance.rb +20 -0
- data/lib/lono/sets/status/instance/base.rb +120 -0
- data/lib/lono/sets/status/instance/completed.rb +35 -0
- data/lib/lono/sets/status/instance/deleted.rb +32 -0
- data/lib/lono/sets/status/instance/show.rb +7 -0
- data/lib/lono/sets/status/instances.rb +111 -0
- data/lib/lono/sets/summarize.rb +20 -0
- data/lib/lono/sets/time_spent.rb +11 -0
- data/lib/lono/sets/update.rb +81 -0
- data/lib/lono/template.rb +5 -7
- data/lib/lono/template/configset_injector.rb +50 -0
- data/lib/lono/template/context.rb +4 -4
- data/lib/lono/template/context/loader.rb +4 -16
- data/lib/lono/template/evaluate.rb +2 -1
- data/lib/lono/template/generator.rb +17 -15
- data/lib/lono/template/helper.rb +7 -7
- data/lib/lono/template/post_processor.rb +2 -12
- data/lib/lono/template/strategy/base.rb +4 -0
- data/lib/lono/template/{dsl.rb → strategy/dsl.rb} +4 -6
- data/lib/lono/template/{dsl → strategy/dsl}/builder.rb +11 -15
- data/lib/lono/template/{dsl → strategy/dsl}/builder/fn.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/helpers.rb +11 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/core_helper.rb +14 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/file_helper.rb +48 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/lookup_helper.rb +27 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/s3_helper.rb +13 -0
- data/lib/lono/template/strategy/dsl/builder/helpers/tags_helper.rb +39 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/base.rb +6 -17
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/condition.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/section/extensions.rb +9 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/mapping.rb +1 -1
- data/lib/lono/template/{dsl/builder/section_methods.rb → strategy/dsl/builder/section/methods.rb} +9 -2
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/output.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/section/parameter.rb +69 -0
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource.rb +1 -1
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/resource/property_mover.rb +1 -1
- data/lib/lono/template/{dsl/builder → strategy/dsl/builder/section}/section.rb +1 -1
- data/lib/lono/template/{dsl → strategy/dsl}/builder/squeezer.rb +1 -1
- data/lib/lono/template/strategy/dsl/builder/stringify.rb +15 -0
- data/lib/lono/template/{dsl → strategy/dsl}/builder/syntax.rb +3 -2
- data/lib/lono/template/strategy/dsl/finalizer.rb +12 -0
- data/lib/lono/template/strategy/dsl/finalizer/parameter_groups.rb +56 -0
- data/lib/lono/template/{erb.rb → strategy/erb.rb} +5 -5
- data/lib/lono/template/strategy/source.rb +8 -0
- data/lib/lono/template/template.rb +1 -1
- data/lib/lono/template/upload.rb +4 -9
- data/lib/lono/template/util.rb +0 -40
- data/lib/lono/upgrade.rb +12 -10
- data/lib/lono/user_data.rb +4 -4
- data/lib/lono/utils/pretty_time.rb +14 -0
- data/lib/lono/utils/sure.rb +23 -0
- data/lib/lono/version.rb +1 -1
- data/lib/lono/yamler/loader.rb +52 -0
- data/lib/lono/yamler/validator.rb +51 -0
- data/lib/templates/blueprint/%blueprint_name%.gemspec.tt +4 -0
- data/lib/templates/blueprint/README.md.tt +1 -1
- data/lib/templates/blueprint/seed/configs.rb +2 -2
- data/lib/templates/blueprint_types/dsl/app/templates/%blueprint_name%.rb +17 -18
- data/lib/templates/blueprint_types/erb/app/templates/%blueprint_name%.yml +63 -4
- data/lib/templates/configset/%configset_name%.gemspec.tt +41 -0
- data/lib/templates/configset/.gitignore +11 -0
- data/lib/templates/configset/CHANGELOG.md +7 -0
- data/lib/templates/configset/Gemfile +4 -0
- data/lib/templates/configset/README.md.tt +3 -0
- data/lib/templates/configset/Rakefile.tt +9 -0
- data/lib/templates/configset/lib/configset.yml +20 -0
- data/lib/templates/skeleton/.gitignore +1 -0
- data/lib/templates/skeleton/Gemfile +0 -1
- data/lib/templates/skeleton/README.md +4 -4
- data/lib/templates/skeleton/configs/settings.yml +1 -1
- data/lono.gemspec +1 -4
- metadata +146 -79
- data/Guardfile +0 -19
- data/lib/lono/app_file.rb +0 -5
- data/lib/lono/blueprint/find.rb +0 -90
- data/lib/lono/blueprint/info.rb +0 -10
- data/lib/lono/blueprint/list.rb +0 -14
- data/lib/lono/cfn/current.rb +0 -95
- data/lib/lono/cfn/preview.rb +0 -4
- data/lib/lono/cfn/suffix.rb +0 -67
- data/lib/lono/cfn/util.rb +0 -27
- data/lib/lono/help/cfn/current.md +0 -18
- data/lib/lono/help/upgrade4.md +0 -25
- data/lib/lono/inspector.rb +0 -4
- data/lib/lono/output_template.rb +0 -35
- data/lib/lono/template/base.rb +0 -13
- data/lib/lono/template/dsl/builder/helpers.rb +0 -8
- data/lib/lono/template/dsl/builder/helpers/core_helper.rb +0 -107
- data/lib/lono/template/dsl/builder/helpers/param_helper.rb +0 -61
- data/lib/lono/template/dsl/builder/parameter.rb +0 -39
- data/lib/lono/upgrade/upgrade4.rb +0 -175
- data/lib/lono/upgrade/upgrade42.rb +0 -36
- data/lib/lono/upgrade/upgrade5.rb +0 -55
- data/lib/templates/blueprint/.meta/config.yml.tt +0 -4
- data/lib/templates/skeleton/Guardfile +0 -12
- data/lib/templates/upgrade5/blueprints/main/.lono/config.yml +0 -3
- data/lib/templates/upgrade5/blueprints/main/.meta/config.yml +0 -3
@@ -0,0 +1,48 @@
|
|
1
|
+
module Lono::Output
|
2
|
+
class Template
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def initialize(blueprint, template)
|
6
|
+
@blueprint, @template = blueprint, template
|
7
|
+
end
|
8
|
+
|
9
|
+
def required_parameters
|
10
|
+
parameters.select { |logical_id, p| p["Default"].nil? }
|
11
|
+
end
|
12
|
+
|
13
|
+
def optional_parameters
|
14
|
+
parameters.reject { |logical_id, p| p["Default"].nil? }
|
15
|
+
end
|
16
|
+
|
17
|
+
def parameters
|
18
|
+
data["Parameters"] || []
|
19
|
+
end
|
20
|
+
|
21
|
+
def parameter_groups
|
22
|
+
interface = data.dig("Metadata", "AWS::CloudFormation::Interface")
|
23
|
+
return unless interface
|
24
|
+
pgs = interface["ParameterGroups"]
|
25
|
+
pgs.inject({}) do |result, pg|
|
26
|
+
k = pg["Label"]["default"]
|
27
|
+
v = pg["Parameters"]
|
28
|
+
result.merge(k => v)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def data
|
33
|
+
template_path = "#{Lono.config.output_path}/#{@blueprint}/templates/#{@template}.yml"
|
34
|
+
check_template_exists!(template_path)
|
35
|
+
YAML.load(IO.read(template_path))
|
36
|
+
end
|
37
|
+
memoize :data
|
38
|
+
|
39
|
+
private
|
40
|
+
# Check if the template exists and print friendly error message. Exits if it
|
41
|
+
# does not exist.
|
42
|
+
def check_template_exists!(template_path)
|
43
|
+
return if File.exist?(template_path)
|
44
|
+
puts "The template #{template_path} does not exist. Are you sure you use the right template name? The template name does not require the extension.".color(:red)
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/lono/param.rb
CHANGED
@@ -4,13 +4,11 @@ module Lono
|
|
4
4
|
class_option :noop, type: :boolean
|
5
5
|
class_option :mute, type: :boolean
|
6
6
|
|
7
|
-
desc "generate", "Generate parameter output files to `output/params`."
|
7
|
+
desc "generate BLUEPRINT", "Generate parameter output files to `output/params`."
|
8
8
|
long_desc Lono::Help.text("param/generate")
|
9
9
|
option :stack, desc: "stack name. defaults to blueprint name."
|
10
|
-
def generate(blueprint
|
11
|
-
|
12
|
-
Generator.new(b, options).generate
|
13
|
-
end
|
10
|
+
def generate(blueprint)
|
11
|
+
Generator.new(options.merge(blueprint: blueprint)).generate
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
data/lib/lono/param/generator.rb
CHANGED
@@ -1,32 +1,22 @@
|
|
1
1
|
class Lono::Param
|
2
|
-
class Generator
|
3
|
-
include Lono::Blueprint::Root
|
4
|
-
include Lono::Conventions
|
5
|
-
|
2
|
+
class Generator < Lono::AbstractBase
|
6
3
|
attr_reader :env_path, :base_path # set when generate is called
|
7
|
-
def initialize(blueprint, options={})
|
8
|
-
# dup because we're modifying the Thor frozen hash
|
9
|
-
# HashWithIndifferentAccess.new again because .dup changes it to a normal Hash
|
10
|
-
@blueprint, @options = blueprint, ActiveSupport::HashWithIndifferentAccess.new(options.dup)
|
11
|
-
@options[:stack] ||= @blueprint
|
12
|
-
set_blueprint_root(@blueprint)
|
13
|
-
@template, @param = template_param_convention(options)
|
14
|
-
end
|
15
4
|
|
16
5
|
def generate
|
17
6
|
puts "Generating parameter files for blueprint #{@blueprint.color(:green)}:"
|
18
7
|
|
19
8
|
@base_path, @env_path = config_locations
|
20
9
|
|
21
|
-
return unless @base_path || @env_path
|
10
|
+
return {} unless @base_path || @env_path
|
22
11
|
|
23
12
|
# useful option for lono cfn, since some templates dont require params
|
24
|
-
return if @options[:allow_not_exists] && !params_exist?
|
13
|
+
return {} if @options[:allow_not_exists] && !params_exist?
|
25
14
|
|
26
15
|
if params_exist?
|
27
16
|
contents = process_erb
|
28
17
|
data = convert_to_cfn_format(contents)
|
29
|
-
|
18
|
+
camel_data = convert_to_cfn_format(contents, :camel)
|
19
|
+
json = JSON.pretty_generate(camel_data)
|
30
20
|
write_output(json)
|
31
21
|
unless @options[:mute]
|
32
22
|
short_output_path = output_path.sub("#{Lono.root}/","")
|
@@ -36,7 +26,11 @@ class Lono::Param
|
|
36
26
|
puts "#{@base_path} or #{@env_path} could not be found? Are you sure it exist?"
|
37
27
|
exit 1
|
38
28
|
end
|
39
|
-
|
29
|
+
data
|
30
|
+
end
|
31
|
+
|
32
|
+
def parameters
|
33
|
+
generate
|
40
34
|
end
|
41
35
|
|
42
36
|
def config_locations
|
@@ -53,10 +47,7 @@ class Lono::Param
|
|
53
47
|
end
|
54
48
|
|
55
49
|
def lookup_config_location(env)
|
56
|
-
|
57
|
-
options[:blueprint] = @blueprint
|
58
|
-
options[:stack] ||= @blueprint
|
59
|
-
location = Lono::ConfigLocation.new("params", options, env)
|
50
|
+
location = Lono::ConfigLocation.new("params", @options, env)
|
60
51
|
env == "base" ? location.lookup_base : location.lookup
|
61
52
|
end
|
62
53
|
|
@@ -78,17 +69,6 @@ class Lono::Param
|
|
78
69
|
@env_path && File.exist?(@env_path)
|
79
70
|
end
|
80
71
|
|
81
|
-
# useful for when calling CloudFormation via the aws-sdk gem
|
82
|
-
def params(casing = :underscore)
|
83
|
-
@base_path, @env_path = config_locations
|
84
|
-
|
85
|
-
# useful option for lono cfn
|
86
|
-
return {} if @options[:allow_not_exists] && !params_exist?
|
87
|
-
|
88
|
-
contents = process_erb
|
89
|
-
convert_to_cfn_format(contents, casing)
|
90
|
-
end
|
91
|
-
|
92
72
|
# Reads both the base source and env source and overlay the two
|
93
73
|
# Example 1:
|
94
74
|
# params/base/mystack.txt - base path
|
@@ -126,7 +106,7 @@ class Lono::Param
|
|
126
106
|
# Context for ERB rendering.
|
127
107
|
# This is where we control what references get passed to the ERB rendering.
|
128
108
|
def context
|
129
|
-
@context ||= Lono::Template::Context.new(@
|
109
|
+
@context ||= Lono::Template::Context.new(@options)
|
130
110
|
end
|
131
111
|
|
132
112
|
def parse_contents(contents)
|
@@ -140,7 +120,7 @@ class Lono::Param
|
|
140
120
|
lines
|
141
121
|
end
|
142
122
|
|
143
|
-
def convert_to_cfn_format(contents, casing=:
|
123
|
+
def convert_to_cfn_format(contents, casing=:underscore)
|
144
124
|
lines = parse_contents(contents)
|
145
125
|
|
146
126
|
# First use a Hash structure so that overlay env files will override
|
data/lib/lono/pro.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lono
|
2
|
+
class Pro < Lono::Command
|
3
|
+
desc "blueprints", "Lists available BoltOps Pro blueprints"
|
4
|
+
long_desc Help.text(:blueprints)
|
5
|
+
def blueprints
|
6
|
+
Repo.new(options.merge(type: "blueprint")).run
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "configsets", "Lists available BoltOps Pro configsets"
|
10
|
+
long_desc Help.text(:configsets)
|
11
|
+
def configsets
|
12
|
+
Repo.new(options.merge(type: "configset")).run
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Lono::Pro
|
2
|
+
class Repo < Base
|
3
|
+
def run
|
4
|
+
data = api.repos(@options[:type])
|
5
|
+
header = ["Name", "Docs", "Description"]
|
6
|
+
rows = data.map do |d|
|
7
|
+
desc = truncate(d[:description])
|
8
|
+
[d[:name], d[:docs_url], desc]
|
9
|
+
end
|
10
|
+
show_table(header, rows)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def truncate(string, max=36)
|
15
|
+
string.length > max ? "#{string[0...max]}..." : string
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_table(header, data)
|
19
|
+
table = Text::Table.new
|
20
|
+
table.head = header
|
21
|
+
data.each do |item|
|
22
|
+
table.rows << item
|
23
|
+
end
|
24
|
+
puts table
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/lono/project_checker.rb
CHANGED
@@ -4,43 +4,18 @@ module Lono
|
|
4
4
|
# If not, provide a friendly message and possibly exit.
|
5
5
|
class ProjectChecker
|
6
6
|
class << self
|
7
|
-
# 2 ways to use lono.
|
8
|
-
#
|
9
|
-
# 1. A standalone project - not available below version 5
|
10
|
-
# 2. A multimode project - available after version 5
|
11
|
-
#
|
12
7
|
@@checked = false
|
13
8
|
def check
|
14
9
|
return if @@checked
|
15
10
|
|
16
|
-
unless
|
17
|
-
puts "ERROR:
|
11
|
+
unless File.exist?("#{Lono.root}/configs/settings.yml")
|
12
|
+
puts "ERROR: Could not find configs/settings.yml file. Are you sure you are in lono project?".color(:red)
|
18
13
|
quit 1
|
19
14
|
end
|
20
15
|
|
21
|
-
@@mode = standalone? ? :standalone : :multimode
|
22
|
-
|
23
16
|
@@checked = true
|
24
17
|
end
|
25
18
|
|
26
|
-
def mode
|
27
|
-
@@mode
|
28
|
-
end
|
29
|
-
|
30
|
-
def standalone?
|
31
|
-
paths = %w[
|
32
|
-
app/definitions
|
33
|
-
app/templates
|
34
|
-
]
|
35
|
-
paths.all? do |path|
|
36
|
-
File.exist?("#{Lono.root}/#{path}")
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def multimode?
|
41
|
-
File.exist?("#{Lono.root}/configs/settings.yml")
|
42
|
-
end
|
43
|
-
|
44
19
|
# Dont exit for this one. It's okay. But show a warning.
|
45
20
|
def empty_templates
|
46
21
|
if Dir["#{Lono.config.templates_path}/**/*"].empty?
|
@@ -49,8 +24,8 @@ module Lono
|
|
49
24
|
end
|
50
25
|
|
51
26
|
def quit(signal)
|
52
|
-
if ENV['
|
53
|
-
signal == 0 || raise("Not in lono project")
|
27
|
+
if ENV['LONO_TEST'] == '1'
|
28
|
+
signal == 0 || raise("Not in lono project. pwd: #{Dir.pwd}")
|
54
29
|
else
|
55
30
|
exit(signal)
|
56
31
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Lono
|
2
|
+
class Registration < Command
|
3
|
+
desc "check", "Check .lono/registration.yml file"
|
4
|
+
long_desc Help.text(:check)
|
5
|
+
option :debug, type: :boolean, desc: "Enable debug mode"
|
6
|
+
def check
|
7
|
+
User.new(options.merge(cli: true)).check
|
8
|
+
end
|
9
|
+
|
10
|
+
desc "temp_check", "Check .lono/temp.yml file", hide: true
|
11
|
+
def temp_check
|
12
|
+
Temp.new.check
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Lono::Registration
|
2
|
+
class Base
|
3
|
+
extend Memoist
|
4
|
+
|
5
|
+
def initialize(options={})
|
6
|
+
@options = options
|
7
|
+
end
|
8
|
+
|
9
|
+
# Same api call for temp_key and registration_key
|
10
|
+
def request_verification(info)
|
11
|
+
with_safety do
|
12
|
+
api.verify(info)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_temp_key
|
17
|
+
with_safety do
|
18
|
+
api.temp_key # grab temp registration key
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def with_safety
|
23
|
+
yield
|
24
|
+
rescue Errno::ECONNREFUSED, Errno::EAFNOSUPPORT
|
25
|
+
raise if Lono::API != Lono::API_DEFAULT
|
26
|
+
end
|
27
|
+
|
28
|
+
def api
|
29
|
+
Lono::Api::Client.new
|
30
|
+
end
|
31
|
+
memoize :api
|
32
|
+
|
33
|
+
def say(msg)
|
34
|
+
puts msg if @options[:cli]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# Incentive to register. Not meant for security.
|
2
|
+
class Lono::Registration
|
3
|
+
class Check
|
4
|
+
extend Memoist
|
5
|
+
|
6
|
+
def initialize(options={})
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def check
|
11
|
+
return true if User.new(@options).check
|
12
|
+
Temp.new(@options).check
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# Incentive to register. Not meant for security.
|
2
|
+
class Lono::Registration
|
3
|
+
class Temp < Base
|
4
|
+
def check
|
5
|
+
info = read_registration
|
6
|
+
if info
|
7
|
+
resp = request_verification(info)
|
8
|
+
puts "request_verification resp #{resp.inspect}" if ENV['LONO_DEBUG_REGISTRATION']
|
9
|
+
# resp nil means non-200 http response. Failsafe behavior is to continue.
|
10
|
+
return true if resp.nil?
|
11
|
+
end
|
12
|
+
|
13
|
+
prompt unless resp && resp[:valid]
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
def read_registration
|
18
|
+
YAML.load_file(temp_path) if File.exist?(temp_path)
|
19
|
+
end
|
20
|
+
|
21
|
+
def prompt
|
22
|
+
return if ENV['LONO_TEST']
|
23
|
+
|
24
|
+
# We get the api first before the prompt to check if api is up
|
25
|
+
resp = get_temp_key
|
26
|
+
# resp nil means non-200 http response. Failsafe behavior is to continue.
|
27
|
+
if resp.nil?
|
28
|
+
return true
|
29
|
+
end
|
30
|
+
|
31
|
+
puts <<~EOL
|
32
|
+
Lono is not registered. To remove this prompt, please set up your registration
|
33
|
+
info in .lono/registration.yml. Registration is free. You can register at:
|
34
|
+
|
35
|
+
https://register.lono.cloud
|
36
|
+
|
37
|
+
More info: https://lono.cloud/docs/register/
|
38
|
+
|
39
|
+
Continue temporarily without registration? (y/N)
|
40
|
+
EOL
|
41
|
+
|
42
|
+
answer = $stdin.gets.to_s.strip # nil on CI
|
43
|
+
if answer !~ /^y/i
|
44
|
+
puts "Exiting."
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
save_temp_key(resp) # save key if user confirms
|
49
|
+
end
|
50
|
+
|
51
|
+
def save_temp_key(info)
|
52
|
+
FileUtils.mkdir_p(File.dirname(temp_path))
|
53
|
+
IO.write(temp_path, YAML.dump(info.deep_stringify_keys))
|
54
|
+
end
|
55
|
+
|
56
|
+
def temp_path
|
57
|
+
"#{ENV['HOME']}/.lono/temp.yml"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class Lono::Registration
|
2
|
+
class User < Base
|
3
|
+
include Lono::Template::Context::Helpers # for ssm helper
|
4
|
+
|
5
|
+
def check
|
6
|
+
info = read_registration
|
7
|
+
unless info
|
8
|
+
say "Lono is not registered."
|
9
|
+
say "The .lono/registration.yml file does not exist."
|
10
|
+
return false
|
11
|
+
end
|
12
|
+
|
13
|
+
@resp = request_verification(info)
|
14
|
+
# A non-200 response means there was a non-200 http response. Failsafe behavior is to continue.
|
15
|
+
# Unless called from the cli: lono registration check
|
16
|
+
if @resp.nil?
|
17
|
+
if @options[:cli]
|
18
|
+
puts "There was an error with the API. Unable to confirm lono registration."
|
19
|
+
return false
|
20
|
+
else
|
21
|
+
return true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if @resp[:valid]
|
26
|
+
say "Lono registration looks good!"
|
27
|
+
return true
|
28
|
+
end
|
29
|
+
|
30
|
+
if @resp[:message]
|
31
|
+
say "Lono is not correctly registered. Unable to confirm info in #{@found}"
|
32
|
+
say @resp[:message]
|
33
|
+
end
|
34
|
+
false
|
35
|
+
end
|
36
|
+
|
37
|
+
def read_registration
|
38
|
+
folders = [Lono.root, ENV['HOME']]
|
39
|
+
files = folders.map { |f| "#{f}/.lono/registration.yml" }
|
40
|
+
@found = files.find do |path|
|
41
|
+
File.exist?(path)
|
42
|
+
end
|
43
|
+
return unless @found
|
44
|
+
|
45
|
+
content = RenderMePretty.result(@found, context: self)
|
46
|
+
if @options[:debug]
|
47
|
+
puts "Debug mode enabled. Here's the lono registration info being used:"
|
48
|
+
puts content
|
49
|
+
puts
|
50
|
+
end
|
51
|
+
YAML.load(content)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|