faastruby 0.4.18 → 0.5.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 +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
@@ -1,15 +1,17 @@
|
|
1
1
|
module FaaStRuby
|
2
2
|
module Command
|
3
3
|
module Workspace
|
4
|
-
|
4
|
+
# require 'faastruby/cli/commands/workspace/base_command'
|
5
|
+
require 'faastruby/cli/new_credentials'
|
6
|
+
class Destroy < BaseCommand
|
5
7
|
def initialize(args)
|
6
8
|
@args = args
|
9
|
+
help
|
7
10
|
@missing_args = []
|
8
11
|
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
9
12
|
@workspace_name = @args.shift
|
10
13
|
parse_options
|
11
|
-
|
12
|
-
@options['credentials_file'] ||= FaaStRuby.credentials_file
|
14
|
+
load_credentials
|
13
15
|
end
|
14
16
|
|
15
17
|
def run
|
@@ -18,9 +20,11 @@ module FaaStRuby
|
|
18
20
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
19
21
|
spinner = spin("Destroying...")
|
20
22
|
workspace.destroy
|
21
|
-
|
23
|
+
if workspace.errors.any?
|
24
|
+
spinner.stop(" Failed :(")
|
25
|
+
FaaStRuby::CLI.error(workspace.errors)
|
26
|
+
end
|
22
27
|
spinner.stop("Done!")
|
23
|
-
FaaStRuby::Credentials.remove(@workspace_name, @options['credentials_file'])
|
24
28
|
puts "Workspace '#{@workspace_name}' was deleted from the server"
|
25
29
|
end
|
26
30
|
|
@@ -43,11 +47,14 @@ module FaaStRuby
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def self.help
|
46
|
-
"destroy-workspace
|
50
|
+
"destroy-workspace WORKSPACE_NAME [ARGS]"
|
47
51
|
end
|
48
52
|
|
49
53
|
def usage
|
50
|
-
"
|
54
|
+
puts "\nUsage: faastruby #{self.class.help}"
|
55
|
+
puts %(
|
56
|
+
-y,--yes # Don't prompt for confirmation
|
57
|
+
)
|
51
58
|
end
|
52
59
|
|
53
60
|
def parse_options
|
@@ -1,36 +1,45 @@
|
|
1
|
+
require 'tty-table'
|
1
2
|
module FaaStRuby
|
2
3
|
module Command
|
3
4
|
module Workspace
|
4
|
-
|
5
|
+
# require 'faastruby/cli/commands/workspace/base_command'
|
6
|
+
require 'faastruby/cli/new_credentials'
|
7
|
+
class List < BaseCommand
|
5
8
|
def initialize(args)
|
6
9
|
@args = args
|
10
|
+
help
|
7
11
|
@missing_args = []
|
8
12
|
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
9
13
|
@workspace_name = @args.shift
|
10
|
-
|
14
|
+
load_credentials
|
11
15
|
end
|
12
16
|
|
13
17
|
def run
|
14
18
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name).fetch
|
15
19
|
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
20
|
+
if workspace.runners_max
|
21
|
+
puts "Allocated Runners: #{workspace.runners_max} (disabled)" if workspace&.runners_max == 0
|
22
|
+
puts "Allocated Runners: #{workspace.runners_max}" if workspace&.runners_max > 0
|
23
|
+
end
|
16
24
|
print_functions_table(workspace.functions)
|
17
25
|
end
|
18
26
|
|
19
27
|
def print_functions_table(functions)
|
20
28
|
no_functions unless functions.any?
|
21
|
-
rows = functions.map do |
|
22
|
-
[
|
29
|
+
rows = functions.map do |hash|
|
30
|
+
[hash['name'], hash['endpoint']]
|
23
31
|
end
|
24
32
|
table = TTY::Table.new(['FUNCTION','ENDPOINT'], rows)
|
25
33
|
puts table.render(:basic)
|
26
34
|
end
|
27
35
|
|
28
36
|
def self.help
|
29
|
-
"list-workspace
|
37
|
+
"list-workspace WORKSPACE_NAME"
|
30
38
|
end
|
31
39
|
|
32
40
|
def usage
|
33
|
-
"
|
41
|
+
puts "\n# List the contents of a cloud workspace."
|
42
|
+
puts "\nUsage: faastruby #{self.class.help}\n\n"
|
34
43
|
end
|
35
44
|
|
36
45
|
private
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'tty-table'
|
2
|
+
module FaaStRuby
|
3
|
+
module Command
|
4
|
+
module Workspace
|
5
|
+
# require 'faastruby/cli/commands/workspace/base_command'
|
6
|
+
require 'faastruby/cli/new_credentials'
|
7
|
+
require 'oj'
|
8
|
+
require 'fileutils'
|
9
|
+
class Migrate < BaseCommand
|
10
|
+
def initialize(args)
|
11
|
+
@args = args
|
12
|
+
@failed = []
|
13
|
+
@migrated = []
|
14
|
+
help
|
15
|
+
load_credentials
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
file1 = File.expand_path('~/.faastruby')
|
20
|
+
file2 = File.expand_path('~/.faastruby.tor1')
|
21
|
+
if !File.file?(file1) && !File.file?(file2)
|
22
|
+
puts "Nothing to migrate."
|
23
|
+
exit 0
|
24
|
+
end
|
25
|
+
old_credential_files = [file1, file2]
|
26
|
+
|
27
|
+
puts "@@@ WARNING @@@ WARNING @@@ WARNING @@@ WARNING @@@ ".red
|
28
|
+
puts "This is going to migrate all your legacy credentials into your new account. This process is REQUIRED, but irreversible."
|
29
|
+
email = NewCredentials::CredentialsFile.new.get['email']
|
30
|
+
puts "You are currently logged in as '#{email}'."
|
31
|
+
print "Continue? [y/N] "
|
32
|
+
response = STDIN.gets.chomp
|
33
|
+
FaaStRuby::CLI.error("Exiting", color: nil) unless response == 'y'
|
34
|
+
old_credential_files.each do |file|
|
35
|
+
next unless File.file?(file)
|
36
|
+
FileUtils.cp(file, "#{file}.backup_before_migration") unless File.file?("#{file}.backup_before_migration")
|
37
|
+
workspaces = Oj.load(File.read(file))
|
38
|
+
workspaces.each do |workspace_name, credentials|
|
39
|
+
migrate(workspace_name, credentials)
|
40
|
+
end
|
41
|
+
remove_migrated(file)
|
42
|
+
backup_file(file)
|
43
|
+
end
|
44
|
+
notify_failed
|
45
|
+
end
|
46
|
+
|
47
|
+
def remove_migrated(file)
|
48
|
+
credentials = Oj.load(File.read(file))
|
49
|
+
@migrated.each do |workspace_name|
|
50
|
+
credentials.delete(workspace_name)
|
51
|
+
end
|
52
|
+
File.write(file, JSON.pretty_generate(credentials))
|
53
|
+
end
|
54
|
+
|
55
|
+
def backup_file(file)
|
56
|
+
FileUtils.mv(file, "#{file}.bkp")
|
57
|
+
end
|
58
|
+
|
59
|
+
def notify_failed
|
60
|
+
return unless @failed.any?
|
61
|
+
puts "\nThe following workspaces failed to be migrated: #{@failed.join(', ').red}"
|
62
|
+
puts "Please come over to our Slack and we will assist you with this migration."
|
63
|
+
puts "Click the following link to join our Slack: https://faastruby.io/slack\n\n"
|
64
|
+
end
|
65
|
+
|
66
|
+
def migrate(workspace_name, credentials)
|
67
|
+
spinner = spin("Migrating workspace '#{workspace_name}'...")
|
68
|
+
api = API.new
|
69
|
+
response = api.migrate_to_account(workspace_name: workspace_name, api_key: credentials['api_key'], api_secret: credentials['api_secret'])
|
70
|
+
if response.code > 299
|
71
|
+
@failed << workspace_name
|
72
|
+
spinner.stop(" Failed :(".red)
|
73
|
+
return false
|
74
|
+
end
|
75
|
+
@migrated << workspace_name
|
76
|
+
spinner.stop(" Done!".green)
|
77
|
+
return true
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.help
|
81
|
+
"migrate-workspaces"
|
82
|
+
end
|
83
|
+
|
84
|
+
def usage
|
85
|
+
puts "\n# Migrate legacy workspace credentials to your new FaaStRuby account."
|
86
|
+
puts "# You must have an account and be logged in to perform the migration."
|
87
|
+
puts "\nUsage: faastruby #{self.class.help}\n\n"
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module FaaStRuby
|
2
|
+
module Command
|
3
|
+
module Workspace
|
4
|
+
# require 'faastruby/cli/commands/workspace/base_command'
|
5
|
+
require 'faastruby/cli/new_credentials'
|
6
|
+
class RM < BaseCommand
|
7
|
+
def initialize(args)
|
8
|
+
@args = args
|
9
|
+
help
|
10
|
+
@workspace_name, @relative_path = @args.shift.split(':')
|
11
|
+
validate_command
|
12
|
+
# FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
13
|
+
load_credentials
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
# destination_url = "#{FaaStRuby.workspace_host_for(@workspace_name)}/#{@relative_path}"
|
18
|
+
spinner = say("[#{@relative_path}] Removing file from cloud workspace '#{@workspace_name}'...")
|
19
|
+
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
20
|
+
workspace.delete_file(relative_path: @relative_path)
|
21
|
+
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
22
|
+
spinner.stop("Done!")
|
23
|
+
puts "* [#{@relative_path}] File removed from cloud workspace '#{@workspace_name}'.".green
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
def self.help
|
28
|
+
"rm WORKSPACE_NAME:/DESTINATION/PATH"
|
29
|
+
end
|
30
|
+
|
31
|
+
def usage
|
32
|
+
puts "\n# Remove static file from cloud workspace path '/DESTINATION/PATH'."
|
33
|
+
puts "\nUsage: faastruby #{self.class.help}\n\n"
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def validate_command
|
39
|
+
validate_workspace_name
|
40
|
+
validate_relative_path
|
41
|
+
end
|
42
|
+
|
43
|
+
def validate_relative_path
|
44
|
+
@relative_path.sub!(/^\//, '')
|
45
|
+
FaaStRuby::CLI.error(["Invalid path: #{@relative_path}".red, "The path must have at least one character and can only contain letters, numbers, -, _, . and /."], color: nil) unless @relative_path&.match(/#{FUNCTION_NAME_REGEX}/)
|
46
|
+
true
|
47
|
+
end
|
48
|
+
|
49
|
+
def validate_workspace_name
|
50
|
+
FaaStRuby::CLI.error(["Invalid workspace name: #{@workspace_name}".red, "The workspace name must have between 3 and 15 characters, and can only have letters, numbers and dashes."], color: nil) unless @workspace_name&.match(/#{WORKSPACE_NAME_REGEX}/)
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
# def missing_args
|
56
|
+
# FaaStRuby::CLI.error(["'#{@workspace_name}' is not a valid workspace name.".red, usage], color: nil) if @workspace_name =~ /^-.*/
|
57
|
+
# @missing_args << "Missing argument: WORKSPACE_NAME".red unless @workspace_name
|
58
|
+
# @missing_args << "Missing argument: -s SOURCE_FILE" unless @options['source']
|
59
|
+
# @missing_args << "Missing argument: -d DESTINATION_PATH" unless @options['destination']
|
60
|
+
# @missing_args << usage if @missing_args.any?
|
61
|
+
# @missing_args
|
62
|
+
# end
|
63
|
+
|
64
|
+
# def parse_options(require_options: {})
|
65
|
+
# @options = {}
|
66
|
+
# while @args.any?
|
67
|
+
# option = @args.shift
|
68
|
+
# case option
|
69
|
+
# when '-s', '--source'
|
70
|
+
# @options['source'] = @args.shift
|
71
|
+
# when '-d', '--destination'
|
72
|
+
# @options['destination'] = @args.shift.gsub(/(^\/|\/$|\.\.|;|'|"|&|\\)/, '')
|
73
|
+
# else
|
74
|
+
# FaaStRuby::CLI.error("Unknown argument: #{option}")
|
75
|
+
# end
|
76
|
+
# end
|
77
|
+
# end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
module FaaStRuby
|
2
|
+
module Command
|
3
|
+
module Workspace
|
4
|
+
# require 'faastruby/cli/commands/workspace/base_command'
|
5
|
+
require 'faastruby/cli/new_credentials'
|
6
|
+
class Update < BaseCommand
|
7
|
+
def initialize(args)
|
8
|
+
@args = args
|
9
|
+
help
|
10
|
+
@missing_args = []
|
11
|
+
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
12
|
+
@workspace_name = @args.shift
|
13
|
+
parse_options
|
14
|
+
load_credentials
|
15
|
+
end
|
16
|
+
|
17
|
+
def run(create_directory: true, exit_on_error: true)
|
18
|
+
spinner = spin("Updating the number of runners to #{@options['runners_max']}...")
|
19
|
+
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
20
|
+
workspace.update_runners(@options['runners_max'])
|
21
|
+
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
22
|
+
spinner.stop("Done!")
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.help
|
26
|
+
"update-workspace WORKSPACE_NAME ARGS"
|
27
|
+
end
|
28
|
+
|
29
|
+
def usage
|
30
|
+
puts "\nUsage: faastruby #{self.class.help}"
|
31
|
+
puts %(
|
32
|
+
--runners N # Assign N runners to the workspace.
|
33
|
+
)
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def missing_args
|
39
|
+
if @args.empty?
|
40
|
+
@missing_args << "Missing argument: WORKSPACE_NAME".red
|
41
|
+
@missing_args << usage
|
42
|
+
end
|
43
|
+
FaaStRuby::CLI.error(["'#{@args.first}' is not a valid workspace name.".red, usage], color: nil) if @args.first =~ /^-.*/
|
44
|
+
@missing_args
|
45
|
+
end
|
46
|
+
|
47
|
+
def parse_options
|
48
|
+
@options = {}
|
49
|
+
while @args.any?
|
50
|
+
option = @args.shift
|
51
|
+
case option
|
52
|
+
when '--runners'
|
53
|
+
@options['runners_max'] = @args.shift
|
54
|
+
else
|
55
|
+
FaaStRuby::CLI.error("Unknown argument: #{option}")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -1,62 +1,63 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
# require 'json'
|
2
|
+
# require 'colorize'
|
3
|
+
# module FaaStRuby
|
4
|
+
# class Credentials # TODO: change it to YAML?
|
5
|
+
# def self.load_credentials_file(credentials_file = FaaStRuby.credentials_file)
|
6
|
+
# return {} unless File.file?(credentials_file)
|
7
|
+
# creds = Oj.load(File.read(credentials_file))
|
8
|
+
# if creds.is_a?(Hash)
|
9
|
+
# creds.delete_if{|workspace, credentials| credentials.nil?}
|
10
|
+
# return creds
|
11
|
+
# end
|
12
|
+
# return {}
|
13
|
+
# end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
# def self.add(workspace_name, new_credentials, credentials_file)
|
16
|
+
# FaaStRuby::CLI.error("Error trying to save null credentials. You probably found a bug in the gem. Please report it at https://github.com/FaaStRuby/faastruby-cli/issues/new") unless new_credentials
|
17
|
+
# credentials = load_credentials_file(credentials_file)
|
18
|
+
# credentials.merge!({workspace_name => new_credentials})
|
19
|
+
# save_file(credentials, credentials_file)
|
20
|
+
# end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
# def self.remove(workspace_name, credentials_file)
|
23
|
+
# credentials = load_credentials_file
|
24
|
+
# credentials.delete_if{|k,v| k == workspace_name}
|
25
|
+
# save_file(credentials, credentials_file)
|
26
|
+
# end
|
26
27
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
# def self.save_file(credentials, credentials_file)
|
29
|
+
# if File.file?(credentials_file)
|
30
|
+
# color = :yellow
|
31
|
+
# symbol = '~'
|
32
|
+
# else
|
33
|
+
# color = :green
|
34
|
+
# symbol = '+'
|
35
|
+
# end
|
36
|
+
# credentials.delete_if{|workspace, creds| creds.nil?}
|
37
|
+
# File.open(credentials_file, 'w') {|f| f.write JSON.pretty_generate(credentials)}
|
38
|
+
# puts "#{symbol} f #{credentials_file}".colorize(color)
|
39
|
+
# end
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
41
|
+
# def self.load_for(workspace_name, cred_file = FaaStRuby.credentials_file, exit_on_error: true)
|
42
|
+
# credentials = load_from_env(workspace_name) || load_credentials_file(cred_file)
|
43
|
+
# error_msg = "Could not find credentials for '#{workspace_name}' in '#{cred_file}'"
|
44
|
+
# if exit_on_error && !credentials[workspace_name]
|
45
|
+
# FaaStRuby::CLI.error(error_msg)
|
46
|
+
# elsif !credentials[workspace_name]
|
47
|
+
# puts error_msg
|
48
|
+
# return false
|
49
|
+
# end
|
50
|
+
# FaaStRuby.configure do |config|
|
51
|
+
# config.api_key = credentials[workspace_name]['api_key']
|
52
|
+
# config.api_secret = credentials[workspace_name]['api_secret']
|
53
|
+
# end
|
54
|
+
# return true
|
55
|
+
# end
|
55
56
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
57
|
+
# def self.load_from_env(workspace_name)
|
58
|
+
# return nil unless ENV['FAASTRUBY_API_KEY'] && ENV['FAASTRUBY_API_SECRET']
|
59
|
+
# puts "#{"WARNING:".red} Using credentials from env vars FAASTRUBY_API_KEY and FAASTRUBY_API_SECRET"
|
60
|
+
# {workspace_name => {'api_key' => ENV['FAASTRUBY_API_KEY'], 'api_secret' => ENV['FAASTRUBY_API_SECRET']}}
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
# end
|