faastruby 0.4.18 → 0.5.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 +4 -4
- data/CHANGELOG.md +6 -3
- data/Gemfile.lock +28 -4
- data/README.md +63 -5
- data/faastruby.gemspec +5 -1
- data/lib/faastruby.rb +1 -0
- data/lib/faastruby/api.rb +154 -6
- data/lib/faastruby/base.rb +3 -9
- data/lib/faastruby/cli.rb +39 -12
- data/lib/faastruby/cli/base_command.rb +66 -0
- data/lib/faastruby/cli/commands.rb +122 -59
- data/lib/faastruby/cli/commands/account/base_command.rb +10 -0
- data/lib/faastruby/cli/commands/account/confirm.rb +94 -0
- data/lib/faastruby/cli/commands/account/login.rb +86 -0
- data/lib/faastruby/cli/commands/account/logout.rb +59 -0
- data/lib/faastruby/cli/commands/account/signup.rb +76 -0
- data/lib/faastruby/cli/commands/{function.rb → function/base_command.rb} +2 -11
- data/lib/faastruby/cli/commands/function/build.rb +18 -11
- data/lib/faastruby/cli/commands/function/deploy_to.rb +100 -37
- data/lib/faastruby/cli/commands/function/new.rb +89 -36
- data/lib/faastruby/cli/commands/function/remove_from.rb +21 -6
- data/lib/faastruby/cli/commands/function/run.rb +15 -15
- data/lib/faastruby/cli/commands/function/test.rb +5 -4
- data/lib/faastruby/cli/commands/function/update_context.rb +10 -3
- data/lib/faastruby/cli/commands/function/upgrade.rb +62 -61
- data/lib/faastruby/cli/commands/help.rb +33 -20
- data/lib/faastruby/cli/commands/project/base_command.rb +14 -0
- data/lib/faastruby/cli/commands/project/deploy.rb +114 -0
- data/lib/faastruby/cli/commands/project/down.rb +58 -0
- data/lib/faastruby/cli/commands/project/new.rb +237 -0
- data/lib/faastruby/cli/commands/workspace/cp.rb +107 -0
- data/lib/faastruby/cli/commands/workspace/create.rb +35 -27
- data/lib/faastruby/cli/commands/workspace/destroy.rb +14 -7
- data/lib/faastruby/cli/commands/workspace/list.rb +15 -6
- data/lib/faastruby/cli/commands/workspace/migrate.rb +93 -0
- data/lib/faastruby/cli/commands/workspace/rm.rb +81 -0
- data/lib/faastruby/cli/commands/workspace/update.rb +62 -0
- data/lib/faastruby/cli/credentials.rb +58 -57
- data/lib/faastruby/cli/new_credentials.rb +63 -0
- data/lib/faastruby/cli/package.rb +1 -0
- data/lib/faastruby/cli/template.rb +7 -7
- data/lib/faastruby/local.rb +188 -0
- data/lib/faastruby/local/crystal_runtime.cr +170 -0
- data/lib/faastruby/local/functions.rb +7 -0
- data/lib/faastruby/local/functions/crystal.rb +64 -0
- data/lib/faastruby/local/functions/function.rb +173 -0
- data/lib/faastruby/local/functions/ruby.rb +28 -0
- data/lib/faastruby/local/listeners.rb +5 -0
- data/lib/faastruby/local/listeners/listener.rb +104 -0
- data/lib/faastruby/local/logger.rb +37 -0
- data/lib/faastruby/local/monkey_patch.rb +38 -0
- data/lib/faastruby/local/processors.rb +7 -0
- data/lib/faastruby/local/processors/function.rb +151 -0
- data/lib/faastruby/local/processors/processor.rb +116 -0
- data/lib/faastruby/local/processors/static_file.rb +48 -0
- data/lib/faastruby/local/static_files.rb +5 -0
- data/lib/faastruby/local/static_files/static_file.rb +59 -0
- data/lib/faastruby/server.rb +44 -3
- data/lib/faastruby/server/app.rb +107 -0
- data/lib/faastruby/server/concurrency_controller.rb +50 -50
- data/lib/faastruby/server/config.ru +2 -0
- data/lib/faastruby/server/event.rb +3 -0
- data/lib/faastruby/server/event_hub.rb +7 -6
- data/lib/faastruby/server/local.rb +22 -0
- data/lib/faastruby/server/logger.rb +50 -0
- data/lib/faastruby/server/project_config.rb +44 -0
- data/lib/faastruby/server/puma.rb +4 -0
- data/lib/faastruby/server/response.rb +40 -0
- data/lib/faastruby/server/runner.rb +116 -21
- data/lib/faastruby/server/runner_methods.rb +17 -16
- data/lib/faastruby/server/sentinel.rb +496 -0
- data/lib/faastruby/supported_runtimes.rb +8 -0
- data/lib/faastruby/user.rb +77 -0
- data/lib/faastruby/version.rb +1 -1
- data/lib/faastruby/workspace.rb +36 -3
- data/templates/crystal/example-blank/handler.cr +3 -0
- data/templates/crystal/example/spec/handler_spec.cr +11 -6
- data/templates/public-web/assets/images/background.png +0 -0
- data/templates/public-web/assets/images/ruby.png +0 -0
- data/templates/public-web/assets/javascripts/main.js +1 -0
- data/templates/public-web/assets/stylesheets/main.css +70 -0
- data/templates/public-web/favicon.ico +0 -0
- data/templates/ruby/api-404/handler.rb +6 -0
- data/templates/ruby/api-root/handler.rb +6 -0
- data/templates/ruby/example-blank/handler.rb +0 -23
- data/templates/ruby/web-404/404.html +36 -0
- data/templates/ruby/web-404/handler.rb +3 -0
- data/templates/ruby/web-root/handler.rb +10 -0
- data/templates/ruby/web-root/index.html.erb +37 -0
- data/templates/ruby/web-root/template.rb +13 -0
- metadata +102 -21
- data/exe/faastruby-server +0 -76
- data/lib/faastruby/cli/commands/credentials.rb +0 -11
- data/lib/faastruby/cli/commands/credentials/add.rb +0 -58
- data/lib/faastruby/cli/commands/credentials/list.rb +0 -58
- data/lib/faastruby/cli/commands/workspace.rb +0 -13
- data/lib/faastruby/cli/commands/workspace/deploy.rb +0 -50
- data/templates/crystal/example-blank/README.md +0 -22
- data/templates/crystal/example-blank/spec/handler_spec.cr +0 -8
- data/templates/crystal/example-blank/spec/spec_helper.cr +0 -4
- data/templates/crystal/example-blank/src/handler.cr +0 -25
- data/templates/ruby/example-blank/Gemfile +0 -7
- data/templates/ruby/example-blank/README.md +0 -22
- data/templates/ruby/example-blank/spec/handler_spec.rb +0 -16
- data/templates/ruby/example-blank/spec/spec_helper.rb +0 -3
data/lib/faastruby/cli.rb
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
require 'tty-spinner'
|
|
2
|
-
require 'yaml'
|
|
3
|
-
require 'tty-table'
|
|
4
|
-
require 'zip'
|
|
5
1
|
require 'colorize'
|
|
6
|
-
require 'faastruby/cli/commands'
|
|
7
|
-
require 'faastruby/cli/package'
|
|
8
|
-
require 'faastruby/cli/template'
|
|
9
|
-
require 'erb'
|
|
10
2
|
|
|
11
3
|
module FaaStRuby
|
|
4
|
+
FUNCTION_NAME_REGEX = '[a-zA-Z\-_0-9\/\.]{1,}'
|
|
5
|
+
WORKSPACE_NAME_REGEX = '[a-zA-Z0-im9_]{1}[a-zA-Z0-9\-]{1,}[a-zA-Z0-9_]{1}'
|
|
12
6
|
FAASTRUBY_YAML = 'faastruby.yml'
|
|
13
7
|
SPINNER_FORMAT = :spin_2
|
|
14
|
-
|
|
8
|
+
|
|
15
9
|
class CLI
|
|
16
10
|
def self.error(message, color: :red)
|
|
17
11
|
message.each {|m| STDERR.puts m.colorize(color)} if message.is_a?(Array)
|
|
@@ -21,14 +15,22 @@ module FaaStRuby
|
|
|
21
15
|
|
|
22
16
|
def self.run(command, args)
|
|
23
17
|
if command.nil?
|
|
18
|
+
require 'faastruby/cli/commands/help'
|
|
24
19
|
FaaStRuby::Command::Help.new(args).run
|
|
25
20
|
return
|
|
26
21
|
end
|
|
27
|
-
|
|
22
|
+
check_ruby_version
|
|
23
|
+
start_server(args) if command == 'local'
|
|
24
|
+
start_tmuxinator if command == 'mux'
|
|
28
25
|
# check_version
|
|
29
26
|
check_region
|
|
27
|
+
require 'faastruby/cli/commands'
|
|
28
|
+
# require 'faastruby/cli/package'
|
|
29
|
+
# require 'faastruby/cli/template'
|
|
30
30
|
error("Unknown command: #{command}") unless FaaStRuby::Command::COMMANDS.has_key?(command)
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
const = FaaStRuby::Command::COMMANDS[command].call
|
|
33
|
+
const.new(args).run
|
|
32
34
|
end
|
|
33
35
|
|
|
34
36
|
# def self.check_version
|
|
@@ -42,13 +44,38 @@ module FaaStRuby
|
|
|
42
44
|
# end
|
|
43
45
|
# end
|
|
44
46
|
|
|
47
|
+
def self.check_ruby_version
|
|
48
|
+
require 'faastruby/supported_runtimes'
|
|
49
|
+
error("Unsupported Ruby version: #{RUBY_VERSION}\nSupported Ruby versions are: #{SUPPORTED_RUBY.join(", ")}") unless SUPPORTED_RUBY.include?(RUBY_VERSION)
|
|
50
|
+
end
|
|
51
|
+
|
|
45
52
|
def self.check_region
|
|
46
53
|
ENV['FAASTRUBY_REGION'] ||= DEFAULT_REGION
|
|
47
54
|
error(["No such region: #{ENV['FAASTRUBY_REGION']}".red, "Valid regions are: #{FaaStRuby::REGIONS.join(' | ')}"], color: nil) unless FaaStRuby::REGIONS.include?(ENV['FAASTRUBY_REGION'])
|
|
48
55
|
end
|
|
49
56
|
|
|
50
57
|
def self.start_server(args)
|
|
51
|
-
|
|
58
|
+
parsed = []
|
|
59
|
+
parsed << 'FAASTRUBY_PROJECT_SYNC_ENABLED=true' if args.delete('--sync')
|
|
60
|
+
parsed << 'DEBUG=true' if args.delete('--debug')
|
|
61
|
+
args.each_with_index do |arg, i|
|
|
62
|
+
if ['--env', '-e'].include?(arg)
|
|
63
|
+
args.delete_at(i)
|
|
64
|
+
parsed << "FAASTRUBY_PROJECT_DEPLOY_ENVIRONMENT=#{args.delete_at(i)}"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
server_dir = "#{Gem::Specification.find_by_name("faastruby").gem_dir}/lib/faastruby/server"
|
|
68
|
+
config_ru = "#{server_dir}/config.ru"
|
|
69
|
+
puma_config = "#{server_dir}/puma.rb"
|
|
70
|
+
exec "#{parsed.join(' ')} puma -C #{puma_config} #{args.join(' ')} #{config_ru}"
|
|
71
|
+
end
|
|
72
|
+
def self.start_tmuxinator
|
|
73
|
+
if system("tmux -V > /dev/null")
|
|
74
|
+
project_name = YAML.load(File.read("project.yml"))['name']
|
|
75
|
+
exec("tmuxinator start #{project_name} -p tmuxinator.yml")
|
|
76
|
+
else
|
|
77
|
+
error("To use 'faastruby mux' you need to have 'tmux' installed.", color: nil)
|
|
78
|
+
end
|
|
52
79
|
end
|
|
53
80
|
end
|
|
54
81
|
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'tty-spinner'
|
|
2
|
+
require 'yaml'
|
|
3
|
+
module FaaStRuby
|
|
4
|
+
module Command
|
|
5
|
+
class BaseCommand
|
|
6
|
+
def self.spin(message)
|
|
7
|
+
spinner = TTY::Spinner.new(":spinner #{message}", format: SPINNER_FORMAT)
|
|
8
|
+
spinner.auto_spin
|
|
9
|
+
spinner
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def write_file(path, content, mode = 'w', print_base_dir: false, extra_content: nil)
|
|
13
|
+
base_dir = print_base_dir ? "#{print_base_dir}/" : ""
|
|
14
|
+
File.open(path, mode) do |f|
|
|
15
|
+
f.write(content)
|
|
16
|
+
f.write(extra_content) if extra_content
|
|
17
|
+
end
|
|
18
|
+
message = "#{mode == 'w' ? '+' : '~'} f #{base_dir}#{path}"
|
|
19
|
+
puts message.green if mode == 'w'
|
|
20
|
+
puts message.yellow if mode == 'w+' || mode == 'a'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def say(message, quiet: false)
|
|
24
|
+
return puts "\n#{message}" if quiet
|
|
25
|
+
spin(message)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def load_credentials
|
|
29
|
+
@credentials_file = NewCredentials::CredentialsFile.new
|
|
30
|
+
@credentials = @credentials_file.get
|
|
31
|
+
FaaStRuby.configure do |config|
|
|
32
|
+
config.api_key = @credentials['api_key']
|
|
33
|
+
config.api_secret = @credentials['api_secret']
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def help
|
|
38
|
+
if ['-h', '--help'].include?(@args.first)
|
|
39
|
+
usage
|
|
40
|
+
exit 0
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def has_user_logged_in?
|
|
45
|
+
NewCredentials::CredentialsFile.new.has_user_logged_in?
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def spin(message)
|
|
49
|
+
spinner = TTY::Spinner.new(":spinner #{message}", format: SPINNER_FORMAT)
|
|
50
|
+
spinner.auto_spin
|
|
51
|
+
spinner
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def load_yaml
|
|
55
|
+
if File.file?(FAASTRUBY_YAML)
|
|
56
|
+
return YAML.load(File.read(FAASTRUBY_YAML))
|
|
57
|
+
end
|
|
58
|
+
FaaStRuby::CLI.error("Could not find file #{FAASTRUBY_YAML}")
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
def spin(message)
|
|
62
|
+
self.class.spin(message)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -1,65 +1,128 @@
|
|
|
1
1
|
module FaaStRuby
|
|
2
2
|
module Command
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
spinner = TTY::Spinner.new(":spinner #{message}", format: SPINNER_FORMAT)
|
|
6
|
-
spinner.auto_spin
|
|
7
|
-
spinner
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def write_file(path, content, mode = 'w')
|
|
11
|
-
File.open(path, mode){|f| f.write(content) }
|
|
12
|
-
message = "#{mode == 'w' ? '+' : '~'} f #{path}"
|
|
13
|
-
puts message.green if mode == 'w'
|
|
14
|
-
puts message.yellow if mode == 'w+' || mode == 'a'
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def spin(message)
|
|
18
|
-
spinner = TTY::Spinner.new(":spinner #{message}", format: SPINNER_FORMAT)
|
|
19
|
-
spinner.auto_spin
|
|
20
|
-
spinner
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def load_yaml
|
|
24
|
-
return YAML.load(File.read(FAASTRUBY_YAML)) if File.file?(FAASTRUBY_YAML)
|
|
25
|
-
FaaStRuby.error("Could not find file #{FAASTRUBY_YAML}")
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
def spin(message)
|
|
29
|
-
self.class.spin(message)
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
require 'faastruby/cli/credentials'
|
|
36
|
-
require 'faastruby/cli/commands/function'
|
|
37
|
-
require 'faastruby/cli/commands/workspace'
|
|
38
|
-
require 'faastruby/cli/commands/credentials'
|
|
39
|
-
require 'faastruby/cli/commands/help'
|
|
40
|
-
require 'faastruby/cli/commands/version'
|
|
41
|
-
|
|
42
|
-
module FaaStRuby
|
|
43
|
-
module Command
|
|
3
|
+
require 'faastruby/cli/base_command'
|
|
4
|
+
# require 'faastruby/cli/credentials'
|
|
44
5
|
COMMANDS = {
|
|
45
|
-
'new' =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
'
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
'
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
'
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
'
|
|
62
|
-
'
|
|
6
|
+
'new' => Proc.new do
|
|
7
|
+
require 'faastruby/cli/commands/function/new'
|
|
8
|
+
FaaStRuby::Command::Function::New
|
|
9
|
+
end,
|
|
10
|
+
'deploy-to' => Proc.new do
|
|
11
|
+
require 'faastruby/cli/commands/function/deploy_to'
|
|
12
|
+
FaaStRuby::Command::Function::DeployTo
|
|
13
|
+
end,
|
|
14
|
+
'remove-from' => Proc.new do
|
|
15
|
+
require 'faastruby/cli/commands/function/remove_from'
|
|
16
|
+
FaaStRuby::Command::Function::RemoveFrom
|
|
17
|
+
end,
|
|
18
|
+
'update-context' => Proc.new do
|
|
19
|
+
require 'faastruby/cli/commands/function/update_context'
|
|
20
|
+
FaaStRuby::Command::Function::UpdateContext
|
|
21
|
+
end,
|
|
22
|
+
# 'upgrade' => Proc.new do
|
|
23
|
+
# require 'faastruby/cli/commands/function/upgrade'
|
|
24
|
+
# FaaStRuby::Command::Function::Upgrade
|
|
25
|
+
# end,
|
|
26
|
+
'build' => Proc.new do
|
|
27
|
+
require 'faastruby/cli/commands/function/build'
|
|
28
|
+
FaaStRuby::Command::Function::Build
|
|
29
|
+
end,
|
|
30
|
+
'create-workspace' => Proc.new do
|
|
31
|
+
require 'faastruby/cli/commands/workspace/create'
|
|
32
|
+
FaaStRuby::Command::Workspace::Create
|
|
33
|
+
end,
|
|
34
|
+
'cp' => Proc.new do
|
|
35
|
+
require 'faastruby/cli/commands/workspace/cp'
|
|
36
|
+
FaaStRuby::Command::Workspace::CP
|
|
37
|
+
end,
|
|
38
|
+
'rm' => Proc.new do
|
|
39
|
+
require 'faastruby/cli/commands/workspace/rm'
|
|
40
|
+
FaaStRuby::Command::Workspace::RM
|
|
41
|
+
end,
|
|
42
|
+
'update-workspace' => Proc.new do
|
|
43
|
+
require 'faastruby/cli/commands/workspace/update'
|
|
44
|
+
FaaStRuby::Command::Workspace::Update
|
|
45
|
+
end,
|
|
46
|
+
'destroy-workspace' => Proc.new do
|
|
47
|
+
require 'faastruby/cli/commands/workspace/destroy'
|
|
48
|
+
FaaStRuby::Command::Workspace::Destroy
|
|
49
|
+
end,
|
|
50
|
+
'list-workspace' => Proc.new do
|
|
51
|
+
require 'faastruby/cli/commands/workspace/list'
|
|
52
|
+
FaaStRuby::Command::Workspace::List
|
|
53
|
+
end,
|
|
54
|
+
'new-project' => Proc.new do
|
|
55
|
+
require 'faastruby/cli/commands/project/new'
|
|
56
|
+
FaaStRuby::Command::Project::New
|
|
57
|
+
end,
|
|
58
|
+
'deploy' => Proc.new do
|
|
59
|
+
require 'faastruby/cli/commands/project/deploy'
|
|
60
|
+
FaaStRuby::Command::Project::Deploy
|
|
61
|
+
end,
|
|
62
|
+
'up' => Proc.new do
|
|
63
|
+
require 'faastruby/cli/commands/project/deploy'
|
|
64
|
+
FaaStRuby::Command::Project::Deploy
|
|
65
|
+
end,
|
|
66
|
+
'down' => Proc.new do
|
|
67
|
+
require 'faastruby/cli/commands/project/down'
|
|
68
|
+
FaaStRuby::Command::Project::Down
|
|
69
|
+
end,
|
|
70
|
+
'test' => Proc.new do
|
|
71
|
+
require 'faastruby/cli/commands/function/test'
|
|
72
|
+
FaaStRuby::Command::Function::Test
|
|
73
|
+
end,
|
|
74
|
+
'run' => Proc.new do
|
|
75
|
+
require 'faastruby/cli/commands/function/run'
|
|
76
|
+
FaaStRuby::Command::Function::Run
|
|
77
|
+
end,
|
|
78
|
+
# 'add-credentials' => Proc.new do
|
|
79
|
+
# require 'faastruby/cli/commands/credentials/add'
|
|
80
|
+
# FaaStRuby::Command::Credentials::Add
|
|
81
|
+
# end,
|
|
82
|
+
# 'list-credentials' => Proc.new do
|
|
83
|
+
# require 'faastruby/cli/commands/credentials/list'
|
|
84
|
+
# FaaStRuby::Command::Credentials::List
|
|
85
|
+
# end,
|
|
86
|
+
'help' => Proc.new do
|
|
87
|
+
require 'faastruby/cli/commands/help'
|
|
88
|
+
FaaStRuby::Command::Help
|
|
89
|
+
end,
|
|
90
|
+
'-h' => Proc.new do
|
|
91
|
+
require 'faastruby/cli/commands/help'
|
|
92
|
+
FaaStRuby::Command::Help
|
|
93
|
+
end,
|
|
94
|
+
'--help' => Proc.new do
|
|
95
|
+
require 'faastruby/cli/commands/help'
|
|
96
|
+
FaaStRuby::Command::Help
|
|
97
|
+
end,
|
|
98
|
+
'-v' => Proc.new do
|
|
99
|
+
require 'faastruby/cli/commands/version'
|
|
100
|
+
FaaStRuby::Command::Version
|
|
101
|
+
end,
|
|
102
|
+
'watch' => Proc.new do
|
|
103
|
+
require 'faastruby/local'
|
|
104
|
+
FaaStRuby::Local.start!
|
|
105
|
+
end,
|
|
106
|
+
'signup' => Proc.new do
|
|
107
|
+
require 'faastruby/cli/commands/account/signup'
|
|
108
|
+
FaaStRuby::Command::Account::Signup
|
|
109
|
+
end,
|
|
110
|
+
'confirm-account' => Proc.new do
|
|
111
|
+
require 'faastruby/cli/commands/account/confirm'
|
|
112
|
+
FaaStRuby::Command::Account::Confirm
|
|
113
|
+
end,
|
|
114
|
+
'login' => Proc.new do
|
|
115
|
+
require 'faastruby/cli/commands/account/login'
|
|
116
|
+
FaaStRuby::Command::Account::Login
|
|
117
|
+
end,
|
|
118
|
+
'logout' => Proc.new do
|
|
119
|
+
require 'faastruby/cli/commands/account/logout'
|
|
120
|
+
FaaStRuby::Command::Account::Logout
|
|
121
|
+
end,
|
|
122
|
+
'migrate-workspaces' => Proc.new do
|
|
123
|
+
require 'faastruby/cli/commands/workspace/migrate'
|
|
124
|
+
FaaStRuby::Command::Workspace::Migrate
|
|
125
|
+
end
|
|
63
126
|
}
|
|
64
127
|
end
|
|
65
128
|
end
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
module FaaStRuby
|
|
3
|
+
module Command
|
|
4
|
+
module Account
|
|
5
|
+
require 'faastruby/cli/commands/account/base_command'
|
|
6
|
+
class Confirm < AccountBaseCommand
|
|
7
|
+
def initialize(args)
|
|
8
|
+
@args = args
|
|
9
|
+
parse_options
|
|
10
|
+
@missing_args = []
|
|
11
|
+
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
user = User.new(email: @options['email'])
|
|
16
|
+
user.send_confirmation_code
|
|
17
|
+
puts "\nYou should have received an email with a confirmation token. If you didn't receive an email, make sure you sign up with the correct email address."
|
|
18
|
+
print "Confirmation Token: "
|
|
19
|
+
user.confirmation_token = STDIN.gets.chomp
|
|
20
|
+
spinner = spin("Confirming your account...")
|
|
21
|
+
user.confirm_account!
|
|
22
|
+
FaaStRuby::CLI.error(user.errors) if user.errors.any?
|
|
23
|
+
spinner.stop(" Done!")
|
|
24
|
+
user.save_credentials
|
|
25
|
+
puts "Login successful!"
|
|
26
|
+
migrate
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def migrate
|
|
30
|
+
old_credentials = File.expand_path("~/.faastruby.tor1")
|
|
31
|
+
return unless File.file?(old_credentials)
|
|
32
|
+
puts "ATTENTION: I've detected you have workspace credentials saved in '#{old_credentials}'.".red
|
|
33
|
+
puts "You need to migrate these credentials into your account."
|
|
34
|
+
print "Do you want to do it right now? [Y/n] "
|
|
35
|
+
answer = STDIN.gets.chomp
|
|
36
|
+
if answer == 'n'
|
|
37
|
+
puts "You won't be able to manage these workspaces until you perform this migration."
|
|
38
|
+
puts "When you are ready to perform this migration, run 'faastruby migrate-workspaces'."
|
|
39
|
+
exit 0
|
|
40
|
+
else
|
|
41
|
+
exec("faastruby migrate-workspaces")
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.help
|
|
46
|
+
"confirm-account [ARGS]"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def usage
|
|
50
|
+
puts "Usage: faastruby #{self.class.help}"
|
|
51
|
+
puts %(
|
|
52
|
+
-e,--email EMAIL # Your email
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
private
|
|
57
|
+
|
|
58
|
+
def missing_args
|
|
59
|
+
@missing_args << "Missing argument: --email EMAIL".red unless @options['email']
|
|
60
|
+
@missing_args << usage if @missing_args.any?
|
|
61
|
+
@missing_args
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def parse_options
|
|
65
|
+
@options = {}
|
|
66
|
+
while @args.any?
|
|
67
|
+
option = @args.shift
|
|
68
|
+
case option
|
|
69
|
+
when '-h', '--help', 'help'
|
|
70
|
+
puts usage
|
|
71
|
+
exit 0
|
|
72
|
+
when '-e', '--email'
|
|
73
|
+
@options['email'] = @args.shift
|
|
74
|
+
else
|
|
75
|
+
FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
module FaaStRuby
|
|
2
|
+
module Command
|
|
3
|
+
module Account
|
|
4
|
+
require 'faastruby/cli/commands/account/base_command'
|
|
5
|
+
require 'io/console'
|
|
6
|
+
class Login < AccountBaseCommand
|
|
7
|
+
def initialize(args)
|
|
8
|
+
@args = args
|
|
9
|
+
parse_options
|
|
10
|
+
@email = @options['email']
|
|
11
|
+
@password = @options['password']
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def run
|
|
15
|
+
ask_for_email unless @email
|
|
16
|
+
ask_for_password unless @password
|
|
17
|
+
user = User.new(email: @email, password: @password)
|
|
18
|
+
user.login
|
|
19
|
+
FaaStRuby::CLI.error(user.errors) if user&.errors.any?
|
|
20
|
+
user.save_credentials
|
|
21
|
+
puts "Login successful."
|
|
22
|
+
migrate
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def ask_for_email
|
|
26
|
+
print "Email: "
|
|
27
|
+
@email = STDIN.gets.chomp
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def ask_for_password
|
|
31
|
+
print "Password: "
|
|
32
|
+
@password = STDIN.noecho(&:gets).chomp
|
|
33
|
+
puts "\n"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def migrate
|
|
37
|
+
old_credentials = File.expand_path("~/.faastruby.tor1")
|
|
38
|
+
return unless File.file?(old_credentials)
|
|
39
|
+
puts "ATTENTION: I've detected you have workspace credentials saved in '#{old_credentials}'.".red
|
|
40
|
+
puts "You need to migrate these credentials into your account."
|
|
41
|
+
print "Do you want to do it right now? [Y/n] "
|
|
42
|
+
answer = STDIN.gets.chomp
|
|
43
|
+
if answer == 'n'
|
|
44
|
+
puts "You won't be able to manage these workspaces until you perform this migration."
|
|
45
|
+
puts "When you are ready to perform this migration, run 'faastruby migrate-workspaces'."
|
|
46
|
+
exit 0
|
|
47
|
+
else
|
|
48
|
+
exec("faastruby migrate-workspaces")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
def self.help
|
|
53
|
+
"login [ARGS]"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def usage
|
|
57
|
+
puts "Usage: faastruby #{self.class.help}"
|
|
58
|
+
puts %(
|
|
59
|
+
-e,--email EMAIL # Your email
|
|
60
|
+
-p,--password PASSWORD # Your password
|
|
61
|
+
)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def parse_options
|
|
67
|
+
@options = {}
|
|
68
|
+
while @args.any?
|
|
69
|
+
option = @args.shift
|
|
70
|
+
case option
|
|
71
|
+
when '-h', '--help', 'help'
|
|
72
|
+
puts usage
|
|
73
|
+
exit 0
|
|
74
|
+
when '-e', '--email'
|
|
75
|
+
@options['email'] = @args.shift
|
|
76
|
+
when '-p', '--password'
|
|
77
|
+
@options['password'] = @args.shift
|
|
78
|
+
else
|
|
79
|
+
FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|