boto-rb-cli 0.7.0
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 +7 -0
- data/LICENSE +21 -0
- data/exe/boto +6 -0
- data/lib/boto/cli/command.rb +33 -0
- data/lib/boto/cli/commands/add.rb +64 -0
- data/lib/boto/cli/commands/check.rb +46 -0
- data/lib/boto/cli/commands/graph.rb +35 -0
- data/lib/boto/cli/commands/new.rb +39 -0
- data/lib/boto/cli/commands/openapi.rb +77 -0
- data/lib/boto/cli/commands/ref.rb +39 -0
- data/lib/boto/cli/commands/run.rb +108 -0
- data/lib/boto/cli/commands/test.rb +122 -0
- data/lib/boto/cli/error.rb +8 -0
- data/lib/boto/cli/runner.rb +67 -0
- data/lib/boto/cli/support/affected_projects.rb +29 -0
- data/lib/boto/cli/support/botofile_editor.rb +91 -0
- data/lib/boto/cli/support/generator.rb +47 -0
- data/lib/boto/cli/support/server.rb +36 -0
- data/lib/boto/cli/version.rb +7 -0
- data/lib/boto/cli.rb +15 -0
- data/templates/library/models/.keep +0 -0
- data/templates/library/operations/.keep +0 -0
- data/templates/library/schemas/.keep +0 -0
- data/templates/library/test/test_helper.rb.erb +8 -0
- data/templates/solution/.gitignore +6 -0
- data/templates/solution/.ruby-version.erb +1 -0
- data/templates/solution/Botofile.erb +4 -0
- data/templates/solution/Gemfile.erb +5 -0
- data/templates/solution/apps/.keep +0 -0
- data/templates/solution/libs/.keep +0 -0
- data/templates/solution/services/.keep +0 -0
- data/templates/solution/workers/.keep +0 -0
- data/templates/webapi/config/app.rb.erb +10 -0
- data/templates/webapi/endpoints/health.rb.erb +10 -0
- data/templates/webapi/models/.keep +0 -0
- data/templates/webapi/operations/.keep +0 -0
- data/templates/webapi/schemas/health_schema.rb.erb +5 -0
- data/templates/webapi/test/config/security_test.rb.erb +15 -0
- data/templates/webapi/test/endpoints/health_test.rb.erb +14 -0
- data/templates/webapi/test/schemas/health_schema_test.rb.erb +9 -0
- data/templates/webapi/test/test_helper.rb.erb +12 -0
- metadata +109 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e873a6cc4f1a048784bd633428af4da1ce132ec3270c81cd6cac97b048ca285b
|
|
4
|
+
data.tar.gz: ee77b402d94250ab24ab2bb9660ef5f7cedcc6ba89a2b2f5f859bad29877b533
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 365d1f819db4f47c59bdae0e4305e23186b21e514e67fde0d41ec37c54f97f33d32094fcfd1b0056386ea34b59f578f04050e6b4440ba0c641018849ab4ba5c9
|
|
7
|
+
data.tar.gz: d5f5a02adf32d2e57711c22165712a1936f6a30aa2efa494dec30eb2c46c18f0061014dff87fd8416ecaaa6ca8b9407cbd7b8f125cbaafef217140a6f5d36e24
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Evo Tech Builder
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/exe/boto
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
class Command
|
|
6
|
+
SUCCESS = 0
|
|
7
|
+
FAILURE = 1
|
|
8
|
+
BOTOFILE_NAME = "Botofile"
|
|
9
|
+
|
|
10
|
+
attr_reader :argv, :out, :err, :cwd
|
|
11
|
+
|
|
12
|
+
def initialize(argv, out:, err:, cwd:)
|
|
13
|
+
@argv = argv
|
|
14
|
+
@out = out
|
|
15
|
+
@err = err
|
|
16
|
+
@cwd = cwd
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def call
|
|
20
|
+
raise NotImplementedError, "#{self.class} must implement #call"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def solution
|
|
26
|
+
path = File.join(cwd, BOTOFILE_NAME)
|
|
27
|
+
raise Error, "Botofile not found in #{cwd}" unless File.file?(path)
|
|
28
|
+
|
|
29
|
+
Botofile.load(path)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class Add < Command
|
|
7
|
+
SUMMARY = "Add a project to the solution"
|
|
8
|
+
USAGE = "usage: boto add <webapi|library> <name>"
|
|
9
|
+
TEMPLATES = %w[webapi library].freeze
|
|
10
|
+
|
|
11
|
+
def call
|
|
12
|
+
template, name = arguments
|
|
13
|
+
project = Boto::Project.new(name: name, template: template.to_sym, refs: [], line: 0)
|
|
14
|
+
ensure_available!(project)
|
|
15
|
+
files = generate(template, project)
|
|
16
|
+
declare!(project)
|
|
17
|
+
files.each { |file| out.puts "create #{project.path}/#{file}" }
|
|
18
|
+
out.puts "update #{BOTOFILE_NAME}"
|
|
19
|
+
SUCCESS
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def arguments
|
|
25
|
+
template, name = argv
|
|
26
|
+
raise Error, USAGE if template.nil? || name.nil?
|
|
27
|
+
raise Error, unknown_template_message(template) unless TEMPLATES.include?(template)
|
|
28
|
+
raise Error, %(invalid project name "#{name}") unless Boto::Botofile::NAME_FORMAT.match?(name)
|
|
29
|
+
|
|
30
|
+
[template, name]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def unknown_template_message(template)
|
|
34
|
+
%(unknown template "#{template}" (available: #{TEMPLATES.join(", ")}))
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def ensure_available!(project)
|
|
38
|
+
if solution.projects.any? { |declared| declared.name == project.name }
|
|
39
|
+
raise Error, %(project "#{project.name}" already exists)
|
|
40
|
+
end
|
|
41
|
+
return unless File.exist?(File.join(cwd, project.path))
|
|
42
|
+
|
|
43
|
+
raise Error, %(directory "#{project.path}" already exists)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def generate(template, project)
|
|
47
|
+
Generator.new(template).generate(
|
|
48
|
+
File.join(cwd, project.path), name: project.name, namespace: project.namespace_name
|
|
49
|
+
)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Validates the new Botofile before writing it, so a bad line never reaches disk.
|
|
53
|
+
def declare!(project)
|
|
54
|
+
path = File.join(cwd, BOTOFILE_NAME)
|
|
55
|
+
source = File.read(path)
|
|
56
|
+
source += "\n" unless source.end_with?("\n")
|
|
57
|
+
source += %(project "#{project.name}", template: :#{project.template}\n)
|
|
58
|
+
Boto::Botofile.parse(source, path: path)
|
|
59
|
+
File.write(path, source)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class Check < Command
|
|
7
|
+
SUMMARY = "Check that projects only use the projects they reference"
|
|
8
|
+
USAGE = "usage: boto check [project]"
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
plan = solution
|
|
12
|
+
names = requested_names(plan)
|
|
13
|
+
violations = Boto::Isolation.check(plan, root: cwd, projects: names)
|
|
14
|
+
return report_violations(violations) if violations.any?
|
|
15
|
+
|
|
16
|
+
count = (names || plan.projects).size
|
|
17
|
+
out.puts "No isolation violations in #{count} #{count == 1 ? "project" : "projects"}"
|
|
18
|
+
SUCCESS
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def requested_names(plan)
|
|
24
|
+
raise Error, USAGE if argv.size > 1
|
|
25
|
+
|
|
26
|
+
name = argv.first
|
|
27
|
+
return unless name
|
|
28
|
+
|
|
29
|
+
verify_project(plan, name)
|
|
30
|
+
[name]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def verify_project(plan, name)
|
|
34
|
+
plan.project(name)
|
|
35
|
+
rescue KeyError
|
|
36
|
+
raise Error, %(unknown project "#{name}")
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def report_violations(violations)
|
|
40
|
+
err.puts Boto::IsolationError.new(violations).message
|
|
41
|
+
FAILURE
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class Graph < Command
|
|
7
|
+
SUMMARY = "Show the dependency graph of the solution"
|
|
8
|
+
PROJECT_INDENT = " "
|
|
9
|
+
REF_INDENT = " "
|
|
10
|
+
REF_PREFIX = "-> "
|
|
11
|
+
NO_PROJECTS = "(no projects)"
|
|
12
|
+
|
|
13
|
+
def call
|
|
14
|
+
graph = solution
|
|
15
|
+
out.puts "solution #{graph.name}"
|
|
16
|
+
print_projects(graph.topological_order)
|
|
17
|
+
SUCCESS
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def print_projects(projects)
|
|
23
|
+
return out.puts("#{PROJECT_INDENT}#{NO_PROJECTS}") if projects.empty?
|
|
24
|
+
|
|
25
|
+
projects.each { |project| print_project(project) }
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def print_project(project)
|
|
29
|
+
out.puts "#{PROJECT_INDENT}#{project.name} [#{project.template}]"
|
|
30
|
+
project.refs.each { |ref| out.puts "#{REF_INDENT}#{REF_PREFIX}#{ref}" }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class New < Command
|
|
7
|
+
SUMMARY = "Create a new solution"
|
|
8
|
+
TEMPLATE = "solution"
|
|
9
|
+
USAGE = "usage: boto new <name>"
|
|
10
|
+
|
|
11
|
+
def call
|
|
12
|
+
name = name_argument
|
|
13
|
+
ensure_available!(name)
|
|
14
|
+
files = Generator.new(TEMPLATE).generate(
|
|
15
|
+
File.join(cwd, name),
|
|
16
|
+
name: name, ruby_version: RUBY_VERSION, boto_version: Boto::CLI::VERSION
|
|
17
|
+
)
|
|
18
|
+
files.each { |file| out.puts "create #{name}/#{file}" }
|
|
19
|
+
out.puts "Next: cd #{name} && boto add webapi api"
|
|
20
|
+
SUCCESS
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def name_argument
|
|
26
|
+
name = argv.first
|
|
27
|
+
raise Error, USAGE if name.nil?
|
|
28
|
+
raise Error, %(invalid solution name "#{name}") unless Boto::Botofile::NAME_FORMAT.match?(name)
|
|
29
|
+
|
|
30
|
+
name
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def ensure_available!(name)
|
|
34
|
+
raise Error, %(directory "#{name}" already exists) if File.exist?(File.join(cwd, name))
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "optparse"
|
|
5
|
+
|
|
6
|
+
module Boto
|
|
7
|
+
module CLI
|
|
8
|
+
module Commands
|
|
9
|
+
class Openapi < Command
|
|
10
|
+
SUMMARY = "Print or write the OpenAPI document of a project"
|
|
11
|
+
USAGE = "usage: boto openapi <project> [-o FILE] [--api-version V]"
|
|
12
|
+
DEFAULT_API_VERSION = "0.1.0"
|
|
13
|
+
SERVABLE_TEMPLATES = %i[webapi microservice].freeze
|
|
14
|
+
# Documentation needs the routes, not production secrets, so the app boots as in development.
|
|
15
|
+
ENV_NAME = "development"
|
|
16
|
+
|
|
17
|
+
def call
|
|
18
|
+
options = parse_options
|
|
19
|
+
plan = solution
|
|
20
|
+
project = named_project(plan, options[:project])
|
|
21
|
+
boot = Boto::Boot.new(plan, root: cwd)
|
|
22
|
+
emit(JSON.pretty_generate(document(boot, project, options[:api_version])), options[:output])
|
|
23
|
+
SUCCESS
|
|
24
|
+
ensure
|
|
25
|
+
# Releases the Zeitwerk loaders so the same solution can be booted again in this process.
|
|
26
|
+
boot&.shutdown
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def parse_options
|
|
32
|
+
options = { api_version: DEFAULT_API_VERSION }
|
|
33
|
+
positional = option_parser(options).parse(argv)
|
|
34
|
+
raise Error, USAGE unless positional.size == 1
|
|
35
|
+
|
|
36
|
+
options.merge(project: positional.first)
|
|
37
|
+
rescue OptionParser::ParseError => error
|
|
38
|
+
raise Error, error.message
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def option_parser(options)
|
|
42
|
+
OptionParser.new do |parser|
|
|
43
|
+
parser.banner = USAGE
|
|
44
|
+
parser.on("-o", "--output FILE") { |file| options[:output] = file }
|
|
45
|
+
parser.on("--api-version VERSION") { |version| options[:api_version] = version }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def named_project(plan, name)
|
|
50
|
+
project = plan.projects.find { |declared| declared.name == name }
|
|
51
|
+
raise Error, %(unknown project "#{name}") unless project
|
|
52
|
+
raise Error, %(project "#{name}" (#{project.template}) has no endpoints) unless endpoints?(project)
|
|
53
|
+
|
|
54
|
+
project
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def endpoints?(project)
|
|
58
|
+
SERVABLE_TEMPLATES.include?(project.template)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def document(boot, project, api_version)
|
|
62
|
+
app = boot.app(project.name, env_name: ENV_NAME, error_output: err)
|
|
63
|
+
Boto::OpenAPI.generate(app, title: project.name, version: api_version)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def emit(json, output)
|
|
67
|
+
return out.puts(json) unless output
|
|
68
|
+
|
|
69
|
+
File.write(File.expand_path(output, cwd), "#{json}\n")
|
|
70
|
+
out.puts "write #{output}"
|
|
71
|
+
rescue SystemCallError => e
|
|
72
|
+
raise Error, "cannot write #{output}: #{e.message}"
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
module Commands
|
|
6
|
+
class Ref < Command
|
|
7
|
+
SUMMARY = "Add a reference between projects"
|
|
8
|
+
USAGE = "usage: boto ref <project> <reference>"
|
|
9
|
+
|
|
10
|
+
def call
|
|
11
|
+
project, ref = argv
|
|
12
|
+
raise Error, USAGE if project.nil? || ref.nil?
|
|
13
|
+
# Guards the %w[] insertion: a name with spaces would become several refs.
|
|
14
|
+
raise Error, %(invalid reference "#{ref}") unless Boto::Botofile::NAME_FORMAT.match?(ref)
|
|
15
|
+
|
|
16
|
+
add_reference(botofile_path, project, ref)
|
|
17
|
+
out.puts "#{project} -> #{ref}"
|
|
18
|
+
SUCCESS
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
private
|
|
22
|
+
|
|
23
|
+
def botofile_path
|
|
24
|
+
path = File.join(cwd, BOTOFILE_NAME)
|
|
25
|
+
raise Error, "Botofile not found in #{cwd}" unless File.file?(path)
|
|
26
|
+
|
|
27
|
+
path
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Validates the edited source before writing, so an invalid reference never reaches the file.
|
|
31
|
+
def add_reference(path, project, ref)
|
|
32
|
+
source = BotofileEditor.add_ref(File.read(path), project: project, ref: ref)
|
|
33
|
+
Boto::Botofile.parse(source, path: path)
|
|
34
|
+
File.write(path, source)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
|
|
5
|
+
module Boto
|
|
6
|
+
module CLI
|
|
7
|
+
module Commands
|
|
8
|
+
class Run < Command
|
|
9
|
+
SUMMARY = "Run the solution's services in one process"
|
|
10
|
+
USAGE = "usage: boto run [project] [--port N] [--host H]"
|
|
11
|
+
SERVABLE_TEMPLATES = %i[webapi microservice].freeze
|
|
12
|
+
DEFAULT_PORT = 3000
|
|
13
|
+
DEFAULT_ENV = "development"
|
|
14
|
+
ENV_VARIABLE = "BOTO_ENV"
|
|
15
|
+
VALID_PORTS = (1..65_535)
|
|
16
|
+
STOP_MESSAGE = "Stopping"
|
|
17
|
+
|
|
18
|
+
DEFAULT_SERVER_FACTORY = ->(apps_by_port, host:) { Boto::CLI::Server.new(apps_by_port, host:) }
|
|
19
|
+
|
|
20
|
+
def initialize(argv, out:, err:, cwd:, server_factory: DEFAULT_SERVER_FACTORY, env: ENV)
|
|
21
|
+
super(argv, out: out, err: err, cwd: cwd)
|
|
22
|
+
@server_factory = server_factory
|
|
23
|
+
@env = env
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def call
|
|
27
|
+
options = parse_options
|
|
28
|
+
plan = solution
|
|
29
|
+
ports = port_assignments(select_projects(plan, options[:project]), options[:port])
|
|
30
|
+
boot = Boto::Boot.new(plan, root: cwd)
|
|
31
|
+
serve(boot, ports, options[:host])
|
|
32
|
+
ensure
|
|
33
|
+
# Releases the Zeitwerk loaders so the same solution can be booted again in this process.
|
|
34
|
+
boot&.shutdown
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
attr_reader :server_factory, :env
|
|
40
|
+
|
|
41
|
+
def parse_options
|
|
42
|
+
options = { port: DEFAULT_PORT, host: Boto::CLI::Server::DEFAULT_HOST }
|
|
43
|
+
positional = option_parser(options).parse(argv)
|
|
44
|
+
raise Error, USAGE if positional.size > 1
|
|
45
|
+
raise Error, %(invalid port "#{options[:port]}") unless VALID_PORTS.cover?(options[:port])
|
|
46
|
+
|
|
47
|
+
options.merge(project: positional.first)
|
|
48
|
+
rescue OptionParser::ParseError => error
|
|
49
|
+
raise Error, error.message
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def option_parser(options)
|
|
53
|
+
OptionParser.new do |parser|
|
|
54
|
+
parser.banner = USAGE
|
|
55
|
+
parser.on("--port PORT", Integer) { |port| options[:port] = port }
|
|
56
|
+
parser.on("--host HOST") { |host| options[:host] = host }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def select_projects(plan, name)
|
|
61
|
+
return [named_project(plan, name)] if name
|
|
62
|
+
|
|
63
|
+
servable = plan.topological_order.select { |project| servable?(project) }
|
|
64
|
+
raise Error, "no servable projects (#{SERVABLE_TEMPLATES.join(", ")})" if servable.empty?
|
|
65
|
+
|
|
66
|
+
servable
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def named_project(plan, name)
|
|
70
|
+
project = plan.projects.find { |declared| declared.name == name }
|
|
71
|
+
raise Error, %(unknown project "#{name}") unless project
|
|
72
|
+
raise Error, %(project "#{name}" (#{project.template}) cannot be served) unless servable?(project)
|
|
73
|
+
|
|
74
|
+
project
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def servable?(project)
|
|
78
|
+
SERVABLE_TEMPLATES.include?(project.template)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Ports follow the topological order, so a dependency always gets the lower port.
|
|
82
|
+
def port_assignments(projects, base_port)
|
|
83
|
+
projects.each_with_index.to_h { |project, index| [project.name, base_port + index] }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
def serve(boot, ports, host)
|
|
87
|
+
apps_by_port = build_apps(boot, ports)
|
|
88
|
+
announce(ports, host)
|
|
89
|
+
server_factory.call(apps_by_port, host: host).run
|
|
90
|
+
SUCCESS
|
|
91
|
+
rescue Interrupt
|
|
92
|
+
out.puts STOP_MESSAGE
|
|
93
|
+
SUCCESS
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def build_apps(boot, ports)
|
|
97
|
+
env_name = env.fetch(ENV_VARIABLE, DEFAULT_ENV)
|
|
98
|
+
ports.to_h { |name, port| [port, boot.app(name, env_name: env_name)] }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def announce(ports, host)
|
|
102
|
+
out.puts "Boto running (Ctrl-C to stop)"
|
|
103
|
+
ports.each { |name, port| out.puts " #{name} http://#{host}:#{port}" }
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "open3"
|
|
4
|
+
require "optparse"
|
|
5
|
+
require "rbconfig"
|
|
6
|
+
|
|
7
|
+
module Boto
|
|
8
|
+
module CLI
|
|
9
|
+
module Commands
|
|
10
|
+
class Test < Command
|
|
11
|
+
SUMMARY = "Run the tests of the solution projects"
|
|
12
|
+
USAGE = "usage: boto test [project] [--affected] [--base REF]"
|
|
13
|
+
CONFLICT_MESSAGE = "a project cannot be combined with --affected"
|
|
14
|
+
DEFAULT_BASE = "main"
|
|
15
|
+
TEST_DIR = "test"
|
|
16
|
+
TEST_LOADER = 'Dir["test/**/*_test.rb"].sort.each { |file| require File.expand_path(file) }'
|
|
17
|
+
# --relative keeps paths relative to the solution root even when it is a subfolder of the repo.
|
|
18
|
+
GIT_DIFF = %w[git diff --name-only --relative].freeze
|
|
19
|
+
GIT_UNTRACKED = %w[git ls-files --others --exclude-standard].freeze
|
|
20
|
+
|
|
21
|
+
DEFAULT_PROCESS_RUNNER = ->(command, chdir:) { system(*command, chdir: chdir) }
|
|
22
|
+
DEFAULT_CHANGED_FILES = lambda do |base, cwd|
|
|
23
|
+
commands = [GIT_DIFF + [base], GIT_UNTRACKED]
|
|
24
|
+
lines = commands.flat_map do |command|
|
|
25
|
+
stdout, stderr, status = Open3.capture3(*command, chdir: cwd)
|
|
26
|
+
raise Error, "git failed: #{stderr.strip}" unless status.success?
|
|
27
|
+
|
|
28
|
+
stdout.lines(chomp: true)
|
|
29
|
+
end
|
|
30
|
+
lines.reject(&:empty?).uniq
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def initialize(argv, out:, err:, cwd:, process_runner: DEFAULT_PROCESS_RUNNER,
|
|
34
|
+
changed_files: DEFAULT_CHANGED_FILES)
|
|
35
|
+
super(argv, out: out, err: err, cwd: cwd)
|
|
36
|
+
@process_runner = process_runner
|
|
37
|
+
@changed_files = changed_files
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def call
|
|
41
|
+
options = parse_options
|
|
42
|
+
plan = solution
|
|
43
|
+
projects = select_projects(options, plan)
|
|
44
|
+
return report_empty if projects.empty?
|
|
45
|
+
|
|
46
|
+
failed = projects.filter_map { |project| project.name unless run_project(project) }
|
|
47
|
+
report(projects.count { |project| test_dir?(project) }, failed)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
def parse_options
|
|
53
|
+
options = { affected: false, base: DEFAULT_BASE }
|
|
54
|
+
positional = option_parser(options).parse(argv)
|
|
55
|
+
raise Error, USAGE if positional.size > 1
|
|
56
|
+
|
|
57
|
+
options.merge(project: positional.first)
|
|
58
|
+
rescue OptionParser::ParseError => error
|
|
59
|
+
raise Error, error.message
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def option_parser(options)
|
|
63
|
+
OptionParser.new do |parser|
|
|
64
|
+
parser.banner = USAGE
|
|
65
|
+
parser.on("--affected") { options[:affected] = true }
|
|
66
|
+
parser.on("--base REF") { |ref| options[:base] = ref }
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def select_projects(options, plan)
|
|
71
|
+
raise Error, CONFLICT_MESSAGE if options[:project] && options[:affected]
|
|
72
|
+
return [named_project(plan, options[:project])] if options[:project]
|
|
73
|
+
return affected_projects(plan, options[:base]) if options[:affected]
|
|
74
|
+
|
|
75
|
+
plan.topological_order
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def named_project(plan, name)
|
|
79
|
+
plan.project(name)
|
|
80
|
+
rescue KeyError
|
|
81
|
+
raise Error, %(unknown project "#{name}")
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
def affected_projects(plan, base)
|
|
85
|
+
names = AffectedProjects.call(@changed_files.call(base, cwd), plan)
|
|
86
|
+
names.map { |name| plan.project(name) }
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def run_project(project)
|
|
90
|
+
return skip(project) unless test_dir?(project)
|
|
91
|
+
|
|
92
|
+
out.puts "== #{project.name}"
|
|
93
|
+
@process_runner.call([RbConfig.ruby, "-Itest", "-e", TEST_LOADER], chdir: project_dir(project))
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
def skip(project)
|
|
97
|
+
out.puts "-- skip #{project.name} (no test/)"
|
|
98
|
+
true
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def test_dir?(project)
|
|
102
|
+
File.directory?(File.join(project_dir(project), TEST_DIR))
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def project_dir(project)
|
|
106
|
+
File.join(cwd, project.path)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def report_empty
|
|
110
|
+
out.puts "no projects to test"
|
|
111
|
+
SUCCESS
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def report(tested_count, failed)
|
|
115
|
+
out.puts "#{tested_count} projects tested, #{failed.size} failed"
|
|
116
|
+
out.puts "failed: #{failed.join(", ")}" if failed.any?
|
|
117
|
+
failed.empty? ? SUCCESS : FAILURE
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
class Runner
|
|
6
|
+
COMMAND_FORMAT = /\A[a-z]+\z/
|
|
7
|
+
HELP_FLAGS = %w[help -h --help].freeze
|
|
8
|
+
USAGE = "usage: boto <command> [args]"
|
|
9
|
+
|
|
10
|
+
def initialize(out:, err:, cwd:)
|
|
11
|
+
@out = out
|
|
12
|
+
@err = err
|
|
13
|
+
@cwd = cwd
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def run(argv)
|
|
17
|
+
name, *rest = argv
|
|
18
|
+
return print_help if name.nil? || HELP_FLAGS.include?(name)
|
|
19
|
+
|
|
20
|
+
command_class = find_command(name)
|
|
21
|
+
return report_unknown(name) unless command_class
|
|
22
|
+
|
|
23
|
+
command_class.new(rest, out: @out, err: @err, cwd: @cwd).call
|
|
24
|
+
rescue Error, Botofile::InvalidError, IsolationError => error
|
|
25
|
+
@err.puts "boto: #{error.message}"
|
|
26
|
+
Command::FAILURE
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def print_help
|
|
32
|
+
@out.puts USAGE
|
|
33
|
+
@out.puts
|
|
34
|
+
@out.puts "Commands:"
|
|
35
|
+
command_entries.each { |name, command_class| @out.puts " #{name} #{command_class::SUMMARY}" }
|
|
36
|
+
Command::SUCCESS
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def command_entries
|
|
40
|
+
Commands.constants.sort.filter_map do |const|
|
|
41
|
+
command_class = Commands.const_get(const, false)
|
|
42
|
+
[const.to_s.downcase, command_class] if command?(command_class)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def find_command(name)
|
|
47
|
+
return unless COMMAND_FORMAT.match?(name)
|
|
48
|
+
|
|
49
|
+
const = name.capitalize
|
|
50
|
+
return unless Commands.const_defined?(const, false)
|
|
51
|
+
|
|
52
|
+
command_class = Commands.const_get(const, false)
|
|
53
|
+
command_class if command?(command_class)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Only Command subclasses are runnable, so stray constants never become commands.
|
|
57
|
+
def command?(value)
|
|
58
|
+
value.is_a?(Class) && value < Command
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def report_unknown(name)
|
|
62
|
+
@err.puts %(boto: unknown command "#{name}")
|
|
63
|
+
Command::FAILURE
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Boto
|
|
4
|
+
module CLI
|
|
5
|
+
# Pure selection: which projects a set of changed files touches, dependents included.
|
|
6
|
+
module AffectedProjects
|
|
7
|
+
BOTOFILE = "Botofile"
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def call(changed_files, solution)
|
|
12
|
+
return solution.topological_order.map(&:name) if changed_files.include?(BOTOFILE)
|
|
13
|
+
|
|
14
|
+
selected = directly_changed(changed_files, solution).flat_map do |name|
|
|
15
|
+
[name, *solution.dependents_of(name)]
|
|
16
|
+
end
|
|
17
|
+
solution.topological_order.map(&:name).select { |name| selected.include?(name) }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def directly_changed(changed_files, solution)
|
|
21
|
+
solution.projects.filter_map do |project|
|
|
22
|
+
prefix = "#{project.path}/"
|
|
23
|
+
project.name if changed_files.any? { |file| file.start_with?(prefix) }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
private_class_method :directly_changed
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "prism"
|
|
4
|
+
|
|
5
|
+
module Boto
|
|
6
|
+
module CLI
|
|
7
|
+
# Adds references to a Botofile's source text, touching only the inserted fragment.
|
|
8
|
+
module BotofileEditor
|
|
9
|
+
PROJECT_METHOD = :project
|
|
10
|
+
REFS_KEY = "refs"
|
|
11
|
+
WORD_ARRAY_OPENINGS = %w[%w %i].freeze
|
|
12
|
+
SYNTAX_ERROR_MESSAGE = "Botofile has syntax errors"
|
|
13
|
+
|
|
14
|
+
def self.add_ref(source, project:, ref:)
|
|
15
|
+
call = find_project_call(parse(source), project)
|
|
16
|
+
option = refs_option(call)
|
|
17
|
+
return splice(source, call.arguments.location.end_offset, ", #{REFS_KEY}: %w[#{ref}]") unless option
|
|
18
|
+
|
|
19
|
+
array = refs_array(option, project, ref)
|
|
20
|
+
splice(source, array.closing_loc.start_offset, array_insertion(array, ref))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def self.parse(source)
|
|
24
|
+
result = Prism.parse(source)
|
|
25
|
+
raise Error, SYNTAX_ERROR_MESSAGE if result.failure?
|
|
26
|
+
|
|
27
|
+
result.value
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.find_project_call(program, project)
|
|
31
|
+
call = program.statements.body.find { |node| project_call?(node, project) }
|
|
32
|
+
raise Error, %(project "#{project}" not found in Botofile) unless call
|
|
33
|
+
|
|
34
|
+
call
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.project_call?(node, project)
|
|
38
|
+
node.is_a?(Prism::CallNode) && node.receiver.nil? && node.name == PROJECT_METHOD &&
|
|
39
|
+
string_named?(first_argument(node), project)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def self.first_argument(call)
|
|
43
|
+
call.arguments&.arguments&.first
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def self.string_named?(node, name)
|
|
47
|
+
node.is_a?(Prism::StringNode) && node.unescaped == name
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def self.refs_option(call)
|
|
51
|
+
last = call.arguments.arguments.last
|
|
52
|
+
return unless last.is_a?(Prism::KeywordHashNode)
|
|
53
|
+
|
|
54
|
+
last.elements.find { |element| refs_assoc?(element) }
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.refs_assoc?(element)
|
|
58
|
+
element.is_a?(Prism::AssocNode) && element.key.is_a?(Prism::SymbolNode) && element.key.unescaped == REFS_KEY
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def self.refs_array(option, project, ref)
|
|
62
|
+
array = option.value
|
|
63
|
+
raise Error, "refs must be a literal array" unless array.is_a?(Prism::ArrayNode)
|
|
64
|
+
raise Error, %("#{project}" already references "#{ref}") if duplicate?(array, ref)
|
|
65
|
+
|
|
66
|
+
array
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def self.array_insertion(array, ref)
|
|
70
|
+
word = word_array?(array)
|
|
71
|
+
element = word ? ref : %("#{ref}")
|
|
72
|
+
return element if array.elements.empty?
|
|
73
|
+
|
|
74
|
+
"#{word ? " " : ", "}#{element}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def self.word_array?(array)
|
|
78
|
+
array.opening_loc.slice.start_with?(*WORD_ARRAY_OPENINGS)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def self.duplicate?(array, ref)
|
|
82
|
+
array.elements.any? { |element| element.respond_to?(:unescaped) && element.unescaped == ref }
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Prism offsets are byte offsets, so splice on bytes and restore the source encoding.
|
|
86
|
+
def self.splice(source, offset, text)
|
|
87
|
+
(source.byteslice(0, offset).b + text.b + source.byteslice(offset..).b).force_encoding(source.encoding)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "erb"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module Boto
|
|
7
|
+
module CLI
|
|
8
|
+
class Generator
|
|
9
|
+
TEMPLATES_ROOT = File.expand_path("../../../../templates", __dir__)
|
|
10
|
+
ERB_EXTENSION = ".erb"
|
|
11
|
+
ERB_TRIM_MODE = "-"
|
|
12
|
+
|
|
13
|
+
def initialize(template_name)
|
|
14
|
+
@dir = File.join(TEMPLATES_ROOT, template_name)
|
|
15
|
+
raise Error, %(unknown template "#{template_name}") unless File.directory?(@dir)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def generate(target_dir, locals)
|
|
19
|
+
template_files.map { |relative| materialize(relative, target_dir, locals) }.sort
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
private
|
|
23
|
+
|
|
24
|
+
def template_files
|
|
25
|
+
Dir.glob("**/*", File::FNM_DOTMATCH, base: @dir)
|
|
26
|
+
.reject { |relative| File.directory?(File.join(@dir, relative)) }
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def materialize(relative, target_dir, locals)
|
|
30
|
+
output = relative.delete_suffix(ERB_EXTENSION)
|
|
31
|
+
target = File.join(target_dir, output)
|
|
32
|
+
FileUtils.mkdir_p(File.dirname(target))
|
|
33
|
+
source = File.join(@dir, relative)
|
|
34
|
+
if relative.end_with?(ERB_EXTENSION)
|
|
35
|
+
File.write(target, render(File.read(source), locals))
|
|
36
|
+
else
|
|
37
|
+
FileUtils.cp(source, target)
|
|
38
|
+
end
|
|
39
|
+
output
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def render(content, locals)
|
|
43
|
+
ERB.new(content, trim_mode: ERB_TRIM_MODE).result_with_hash(locals)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "async"
|
|
4
|
+
require "async/http/endpoint"
|
|
5
|
+
require "falcon/server"
|
|
6
|
+
|
|
7
|
+
module Boto
|
|
8
|
+
module CLI
|
|
9
|
+
# Serves one Rack app per port, all of them inside a single Async reactor.
|
|
10
|
+
class Server
|
|
11
|
+
DEFAULT_HOST = "127.0.0.1"
|
|
12
|
+
|
|
13
|
+
attr_reader :apps_by_port, :host
|
|
14
|
+
|
|
15
|
+
def initialize(apps_by_port, host: DEFAULT_HOST)
|
|
16
|
+
@apps_by_port = apps_by_port
|
|
17
|
+
@host = host
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def run
|
|
21
|
+
Async do |task|
|
|
22
|
+
apps_by_port.each { |port, app| task.async { falcon_server(app, port).run } }
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
private
|
|
27
|
+
|
|
28
|
+
# Falcon's HTTP cache is on by default and would replay GET responses without reaching the app,
|
|
29
|
+
# skipping auth, rate limits and per-user data; an API server must not cache, so it is disabled.
|
|
30
|
+
def falcon_server(app, port)
|
|
31
|
+
endpoint = Async::HTTP::Endpoint.parse("http://#{host}:#{port}")
|
|
32
|
+
Falcon::Server.new(Falcon::Server.rack_middleware(app, cache: false), endpoint)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
data/lib/boto/cli.rb
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "boto"
|
|
4
|
+
require "zeitwerk"
|
|
5
|
+
|
|
6
|
+
loader = Zeitwerk::Loader.for_gem_extension(Boto)
|
|
7
|
+
loader.inflector.inflect("cli" => "CLI")
|
|
8
|
+
# support/ groups helpers on disk without adding a namespace (Boto::CLI::Generator stays the same).
|
|
9
|
+
loader.collapse("#{__dir__}/cli/support")
|
|
10
|
+
loader.setup
|
|
11
|
+
|
|
12
|
+
module Boto
|
|
13
|
+
module CLI
|
|
14
|
+
end
|
|
15
|
+
end
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "minitest/autorun"
|
|
4
|
+
require "boto"
|
|
5
|
+
|
|
6
|
+
SOLUTION_ROOT = File.expand_path("../../..", __dir__)
|
|
7
|
+
BOOT = Boto::Boot.new(Boto::Botofile.load(File.join(SOLUTION_ROOT, "Botofile")), root: SOLUTION_ROOT)
|
|
8
|
+
BOOT.load("<%= name %>")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<%= ruby_version %>
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Security plugins for <%= name %>. Secrets come from the environment and are read once at boot.
|
|
4
|
+
# In development a fixed token keeps `boto run` working out of the box; elsewhere API_TOKENS is required.
|
|
5
|
+
Boto.configure do |app|
|
|
6
|
+
default_tokens = app.env_name == "development" ? "dev-token" : ""
|
|
7
|
+
app.use :cors, origins: ENV.fetch("CORS_ORIGINS", "").split(",")
|
|
8
|
+
app.use :auth, strategy: :bearer, tokens: -> { ENV.fetch("API_TOKENS", default_tokens).split(",") }
|
|
9
|
+
app.use :rate_limit, limit: 300, period: 60
|
|
10
|
+
end
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class <%= namespace %>SecurityTest < Minitest::Test
|
|
6
|
+
def test_health_is_public
|
|
7
|
+
response = Rack::MockRequest.new(APP).get("/health")
|
|
8
|
+
assert_equal 200, response.status
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_health_ignores_wrong_token
|
|
12
|
+
response = Rack::MockRequest.new(APP).get("/health", "HTTP_AUTHORIZATION" => "Bearer wrong")
|
|
13
|
+
assert_equal 200, response.status
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class <%= namespace %>HealthTest < Minitest::Test
|
|
6
|
+
def test_returns_ok
|
|
7
|
+
assert_equal({ status: "ok" }, <%= namespace %>::Health.new.call)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def test_responds_over_http
|
|
11
|
+
response = Rack::MockRequest.new(APP).get("/health")
|
|
12
|
+
assert_equal 200, response.status
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "test_helper"
|
|
4
|
+
|
|
5
|
+
class <%= namespace %>HealthSchemaTest < Minitest::Test
|
|
6
|
+
def test_serialize_keeps_only_declared_fields
|
|
7
|
+
assert_equal({ status: "ok" }, <%= namespace %>::HealthSchema.serialize({ status: "ok", secret: "x" }))
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "minitest/autorun"
|
|
4
|
+
require "rack/mock"
|
|
5
|
+
require "boto"
|
|
6
|
+
|
|
7
|
+
# config/app.rb requires API_TOKENS (bearer rejects an empty list), so boot needs a value.
|
|
8
|
+
ENV["API_TOKENS"] ||= "test-token"
|
|
9
|
+
|
|
10
|
+
SOLUTION_ROOT = File.expand_path("../../..", __dir__)
|
|
11
|
+
BOOT = Boto::Boot.new(Boto::Botofile.load(File.join(SOLUTION_ROOT, "Botofile")), root: SOLUTION_ROOT)
|
|
12
|
+
APP = BOOT.app("<%= name %>")
|
metadata
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: boto-rb-cli
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.7.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Evo Tech Builder
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: boto-rb
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - '='
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.7.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - '='
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.7.0
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: falcon
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.57'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.57'
|
|
40
|
+
executables:
|
|
41
|
+
- boto
|
|
42
|
+
extensions: []
|
|
43
|
+
extra_rdoc_files: []
|
|
44
|
+
files:
|
|
45
|
+
- LICENSE
|
|
46
|
+
- exe/boto
|
|
47
|
+
- lib/boto/cli.rb
|
|
48
|
+
- lib/boto/cli/command.rb
|
|
49
|
+
- lib/boto/cli/commands/add.rb
|
|
50
|
+
- lib/boto/cli/commands/check.rb
|
|
51
|
+
- lib/boto/cli/commands/graph.rb
|
|
52
|
+
- lib/boto/cli/commands/new.rb
|
|
53
|
+
- lib/boto/cli/commands/openapi.rb
|
|
54
|
+
- lib/boto/cli/commands/ref.rb
|
|
55
|
+
- lib/boto/cli/commands/run.rb
|
|
56
|
+
- lib/boto/cli/commands/test.rb
|
|
57
|
+
- lib/boto/cli/error.rb
|
|
58
|
+
- lib/boto/cli/runner.rb
|
|
59
|
+
- lib/boto/cli/support/affected_projects.rb
|
|
60
|
+
- lib/boto/cli/support/botofile_editor.rb
|
|
61
|
+
- lib/boto/cli/support/generator.rb
|
|
62
|
+
- lib/boto/cli/support/server.rb
|
|
63
|
+
- lib/boto/cli/version.rb
|
|
64
|
+
- templates/library/models/.keep
|
|
65
|
+
- templates/library/operations/.keep
|
|
66
|
+
- templates/library/schemas/.keep
|
|
67
|
+
- templates/library/test/test_helper.rb.erb
|
|
68
|
+
- templates/solution/.gitignore
|
|
69
|
+
- templates/solution/.ruby-version.erb
|
|
70
|
+
- templates/solution/Botofile.erb
|
|
71
|
+
- templates/solution/Gemfile.erb
|
|
72
|
+
- templates/solution/apps/.keep
|
|
73
|
+
- templates/solution/libs/.keep
|
|
74
|
+
- templates/solution/services/.keep
|
|
75
|
+
- templates/solution/workers/.keep
|
|
76
|
+
- templates/webapi/config/app.rb.erb
|
|
77
|
+
- templates/webapi/endpoints/health.rb.erb
|
|
78
|
+
- templates/webapi/models/.keep
|
|
79
|
+
- templates/webapi/operations/.keep
|
|
80
|
+
- templates/webapi/schemas/health_schema.rb.erb
|
|
81
|
+
- templates/webapi/test/config/security_test.rb.erb
|
|
82
|
+
- templates/webapi/test/endpoints/health_test.rb.erb
|
|
83
|
+
- templates/webapi/test/schemas/health_schema_test.rb.erb
|
|
84
|
+
- templates/webapi/test/test_helper.rb.erb
|
|
85
|
+
homepage: https://github.com/EvoTechBuilder/boto-rb
|
|
86
|
+
licenses:
|
|
87
|
+
- MIT
|
|
88
|
+
metadata:
|
|
89
|
+
rubygems_mfa_required: 'true'
|
|
90
|
+
source_code_uri: https://github.com/EvoTechBuilder/boto-rb
|
|
91
|
+
changelog_uri: https://github.com/EvoTechBuilder/boto-rb/blob/main/CHANGELOG.md
|
|
92
|
+
rdoc_options: []
|
|
93
|
+
require_paths:
|
|
94
|
+
- lib
|
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ">="
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '3.4'
|
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
|
+
requirements:
|
|
102
|
+
- - ">="
|
|
103
|
+
- !ruby/object:Gem::Version
|
|
104
|
+
version: '0'
|
|
105
|
+
requirements: []
|
|
106
|
+
rubygems_version: 4.0.20
|
|
107
|
+
specification_version: 4
|
|
108
|
+
summary: Command line interface for the Boto framework.
|
|
109
|
+
test_files: []
|