faastruby 0.2.6 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +43 -4
- data/example-blank/Gemfile +1 -0
- data/example-blank/spec/spec_helper.rb +1 -0
- data/example/Gemfile +1 -0
- data/example/spec/spec_helper.rb +1 -0
- data/exe/faastruby-server +123 -0
- data/faastruby.gemspec +4 -0
- data/lib/faastruby/api.rb +6 -1
- data/lib/faastruby/cli.rb +5 -0
- data/lib/faastruby/cli/commands/function/new.rb +2 -2
- data/lib/faastruby/cli/commands/workspace/create.rb +8 -0
- data/lib/faastruby/cli/commands/workspace/destroy.rb +2 -0
- data/lib/faastruby/version.rb +1 -1
- metadata +60 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca9d4cec0bdbdaefb83ad63a578a211a5fb186f118f2e9c7f4bb8f81f4b2ac08
|
4
|
+
data.tar.gz: 5857b9257bafe182fb38f89a6a1290d3a7fc148e75bc405e48a9cd51e6acbb80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6fdbc0c311dc686ef5f1aa2f8310d4cef9fdf7c77d304bb42edc8069da4603b30d033df29d2b4743e5891f1ef90a34460ffb49cebcf927bbbad02c6860b8eff
|
7
|
+
data.tar.gz: 8aeb14ace46c50277eff7a9a9f29d7dda88f302674a96a5d5ece6930072698a3eff8a3816984f91944d39f359594b643caf0c1605e8ec8e2f1c6c02e515d4062
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.3.1 - Dec 9 2018
|
4
|
+
- Add faastruby-rpc to Gemfile template and runtime dependencies
|
5
|
+
|
6
|
+
## 0.3.0 - Dec 9 2018
|
7
|
+
- Add spinner feedback when destroying workspace
|
8
|
+
- Better error handling when response is not JSON
|
9
|
+
- New command `faastruby server` will start a development environment.
|
10
|
+
|
3
11
|
## 0.2.6 - Nov 20 2018
|
4
12
|
- Change Ruby minimum version to 2.5.0
|
5
13
|
- Disable timeout on HTTP requests.
|
data/Gemfile.lock
CHANGED
@@ -1,39 +1,61 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
faastruby (0.
|
4
|
+
faastruby (0.3.0)
|
5
5
|
colorize (~> 0.8)
|
6
|
+
faastruby-rpc (~> 0.1)
|
6
7
|
oj (~> 3.6)
|
8
|
+
puma (~> 3.12)
|
7
9
|
rest-client (~> 2.0)
|
8
10
|
rubyzip (~> 1.2)
|
11
|
+
sinatra (~> 2.0)
|
12
|
+
sinatra-contrib (~> 2.0)
|
9
13
|
tty-spinner (~> 0.8)
|
10
14
|
tty-table (~> 0.10)
|
11
15
|
|
12
16
|
GEM
|
13
17
|
remote: https://rubygems.org/
|
14
18
|
specs:
|
19
|
+
activesupport (5.2.2)
|
20
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
21
|
+
i18n (>= 0.7, < 2)
|
22
|
+
minitest (~> 5.1)
|
23
|
+
tzinfo (~> 1.1)
|
15
24
|
addressable (2.5.2)
|
16
25
|
public_suffix (>= 2.0.2, < 4.0)
|
26
|
+
backports (3.11.4)
|
17
27
|
colorize (0.8.1)
|
28
|
+
concurrent-ruby (1.1.3)
|
18
29
|
crack (0.4.3)
|
19
30
|
safe_yaml (~> 1.0.0)
|
20
31
|
diff-lcs (1.3)
|
21
32
|
domain_name (0.5.20180417)
|
22
33
|
unf (>= 0.0.5, < 1.0.0)
|
23
34
|
equatable (0.5.0)
|
35
|
+
faastruby-rpc (0.1.1)
|
36
|
+
oj (~> 3.6)
|
24
37
|
hashdiff (0.3.7)
|
25
38
|
http-cookie (1.0.3)
|
26
39
|
domain_name (~> 0.5)
|
40
|
+
i18n (1.1.1)
|
41
|
+
concurrent-ruby (~> 1.0)
|
27
42
|
mime-types (3.2.2)
|
28
43
|
mime-types-data (~> 3.2015)
|
29
44
|
mime-types-data (3.2018.0812)
|
45
|
+
minitest (5.11.3)
|
46
|
+
multi_json (1.13.1)
|
47
|
+
mustermann (1.0.3)
|
30
48
|
necromancer (0.4.0)
|
31
49
|
netrc (0.11.0)
|
32
|
-
oj (3.7.
|
50
|
+
oj (3.7.4)
|
33
51
|
pastel (0.7.2)
|
34
52
|
equatable (~> 0.5.0)
|
35
53
|
tty-color (~> 0.4.0)
|
36
54
|
public_suffix (3.0.3)
|
55
|
+
puma (3.12.0)
|
56
|
+
rack (2.0.6)
|
57
|
+
rack-protection (2.0.4)
|
58
|
+
rack
|
37
59
|
rake (10.5.0)
|
38
60
|
rest-client (2.0.2)
|
39
61
|
http-cookie (>= 1.0.2, < 2.0)
|
@@ -54,22 +76,39 @@ GEM
|
|
54
76
|
rspec-support (3.8.0)
|
55
77
|
rubyzip (1.2.2)
|
56
78
|
safe_yaml (1.0.4)
|
79
|
+
sinatra (2.0.4)
|
80
|
+
mustermann (~> 1.0)
|
81
|
+
rack (~> 2.0)
|
82
|
+
rack-protection (= 2.0.4)
|
83
|
+
tilt (~> 2.0)
|
84
|
+
sinatra-contrib (2.0.4)
|
85
|
+
activesupport (>= 4.0.0)
|
86
|
+
backports (>= 2.8.2)
|
87
|
+
multi_json
|
88
|
+
mustermann (~> 1.0)
|
89
|
+
rack-protection (= 2.0.4)
|
90
|
+
sinatra (= 2.0.4)
|
91
|
+
tilt (>= 1.3, < 3)
|
57
92
|
strings (0.1.4)
|
58
93
|
strings-ansi (~> 0.1.0)
|
59
94
|
unicode-display_width (~> 1.4.0)
|
60
95
|
unicode_utils (~> 1.4.0)
|
61
96
|
strings-ansi (0.1.0)
|
97
|
+
thread_safe (0.3.6)
|
98
|
+
tilt (2.0.9)
|
62
99
|
tty-color (0.4.3)
|
63
100
|
tty-cursor (0.6.0)
|
64
101
|
tty-screen (0.6.5)
|
65
|
-
tty-spinner (0.
|
66
|
-
tty-cursor (
|
102
|
+
tty-spinner (0.9.0)
|
103
|
+
tty-cursor (~> 0.6.0)
|
67
104
|
tty-table (0.10.0)
|
68
105
|
equatable (~> 0.5.0)
|
69
106
|
necromancer (~> 0.4.0)
|
70
107
|
pastel (~> 0.7.2)
|
71
108
|
strings (~> 0.1.0)
|
72
109
|
tty-screen (~> 0.6.4)
|
110
|
+
tzinfo (1.2.5)
|
111
|
+
thread_safe (~> 0.1)
|
73
112
|
unf (0.1.4)
|
74
113
|
unf_ext
|
75
114
|
unf_ext (0.0.7.5)
|
data/example-blank/Gemfile
CHANGED
data/example/Gemfile
CHANGED
data/example/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'sinatra'
|
4
|
+
require 'sinatra/multi_route'
|
5
|
+
require 'yaml'
|
6
|
+
require 'oj'
|
7
|
+
require 'faastruby-rpc'
|
8
|
+
|
9
|
+
module FaaStRubyFunction
|
10
|
+
def self.call(workspace_name, function_name, event, args)
|
11
|
+
begin
|
12
|
+
load "./#{workspace_name}/#{function_name}/handler.rb"
|
13
|
+
response = handler(event, *args)
|
14
|
+
return response if response.is_a?(FaaStRubyFunction::Response)
|
15
|
+
body = {
|
16
|
+
'error' => "Please use the helpers 'render' or 'respond_with' as your function return value."
|
17
|
+
}
|
18
|
+
respond_with(Oj.dump(body), status: 500, headers: {'Content-Type' => 'application/json'})
|
19
|
+
rescue Exception => e
|
20
|
+
body = {
|
21
|
+
'error' => e.message,
|
22
|
+
'location' => e.backtrace&.first,
|
23
|
+
}
|
24
|
+
respond_with(Oj.dump(body), status: 500, headers: {'Content-Type' => 'application/json'})
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def self.respond_with(body, status: 200, headers: {})
|
28
|
+
r = FaaStRubyFunction::Response.new(:body, :status, :headers)
|
29
|
+
r.new(body, status, headers)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.render(js: nil, body: nil, inline: nil, html: nil, json: nil, yaml: nil, text: nil, status: 200, headers: {}, content_type: nil)
|
33
|
+
headers["Content-Type"] = content_type if content_type
|
34
|
+
case
|
35
|
+
when json
|
36
|
+
headers["Content-Type"] ||= "application/json"
|
37
|
+
resp_body = json.is_a?(String) ? json : Oj.dump(json)
|
38
|
+
when html, inline
|
39
|
+
headers["Content-Type"] ||= "text/html"
|
40
|
+
resp_body = html
|
41
|
+
when text
|
42
|
+
headers["Content-Type"] ||= "text/plain"
|
43
|
+
resp_body = text
|
44
|
+
when yaml
|
45
|
+
headers["Content-Type"] ||= "application/yaml"
|
46
|
+
resp_body = yaml.to_yaml
|
47
|
+
when body
|
48
|
+
headers["Content-Type"] ||= "application/octet-stream"
|
49
|
+
resp_body = raw
|
50
|
+
when js
|
51
|
+
headers["Content-Type"] ||= "text/javascript"
|
52
|
+
resp_body = js
|
53
|
+
end
|
54
|
+
respond_with(resp_body, status: status, headers: headers)
|
55
|
+
end
|
56
|
+
class Event < Struct
|
57
|
+
end
|
58
|
+
|
59
|
+
class Response < Struct
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class FaaStRubyServer < Sinatra::Application
|
64
|
+
set :port, 3000
|
65
|
+
set :bind, '0.0.0.0'
|
66
|
+
case ARGV.shift
|
67
|
+
when '-p'
|
68
|
+
set :port, ARGV.shift
|
69
|
+
when '-b'
|
70
|
+
set :bind, ARGV.shift
|
71
|
+
end
|
72
|
+
set :server, %w[puma]
|
73
|
+
set :run, false
|
74
|
+
set :show_exceptions, false
|
75
|
+
|
76
|
+
register Sinatra::MultiRoute
|
77
|
+
route :get, :post, :put, :patch, :delete, '/:workspace_name/:function_name' do
|
78
|
+
e = FaaStRubyFunction::Event.new(:body, :query_params, :headers, :context)
|
79
|
+
headers = env.select { |key, value| key.include?('HTTP_') || ['CONTENT_TYPE', 'CONTENT_LENGTH', 'REMOTE_ADDR', 'REQUEST_METHOD', 'QUERY_STRING'].include?(key) }
|
80
|
+
if headers.has_key?("HTTP_FAASTRUBY_RPC")
|
81
|
+
body = nil
|
82
|
+
rpc_args = parse_body(request.body.read, headers['CONTENT_TYPE'], request.request_method) || []
|
83
|
+
else
|
84
|
+
body = parse_body(request.body.read, headers['CONTENT_TYPE'], request.request_method)
|
85
|
+
rpc_args = []
|
86
|
+
end
|
87
|
+
query_params = parse_query(request.query_string)
|
88
|
+
context = set_context(params[:workspace_name], params[:function_name])
|
89
|
+
event = e.new(body, query_params, headers, context)
|
90
|
+
response = FaaStRubyFunction.call(params[:workspace_name], params[:function_name], event, rpc_args)
|
91
|
+
status response.status
|
92
|
+
headers response.headers
|
93
|
+
body response.body
|
94
|
+
end
|
95
|
+
|
96
|
+
def parse_body(body, content_type, method)
|
97
|
+
return nil if method == 'GET'
|
98
|
+
return {} if body.nil? && method != 'GET'
|
99
|
+
return Oj.load(body) if content_type == 'application/json'
|
100
|
+
return body
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_context(workspace_name, function_name)
|
104
|
+
return nil unless File.file?('context.yml')
|
105
|
+
yaml = YAML.load(File.read('context.yml'))
|
106
|
+
return nil unless yaml.has_key?(workspace_name)
|
107
|
+
yaml[workspace_name][function_name]
|
108
|
+
end
|
109
|
+
|
110
|
+
def parse_query(query_string)
|
111
|
+
hash = {}
|
112
|
+
query_string.split('&').each do |param|
|
113
|
+
key, value = params.split('=')
|
114
|
+
hash[key] = value
|
115
|
+
end
|
116
|
+
hash
|
117
|
+
end
|
118
|
+
def self.run?
|
119
|
+
true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
FaaStRubyServer.run! rescue nil # this will suppress some of the errors messages
|
data/faastruby.gemspec
CHANGED
@@ -17,6 +17,10 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.add_runtime_dependency 'tty-table', '~> 0.10'
|
18
18
|
spec.add_runtime_dependency 'rubyzip', '~> 1.2'
|
19
19
|
spec.add_runtime_dependency 'colorize', '~> 0.8'
|
20
|
+
spec.add_runtime_dependency 'sinatra', '~> 2.0'
|
21
|
+
spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0'
|
22
|
+
spec.add_runtime_dependency 'puma', '~> 3.12'
|
23
|
+
spec.add_runtime_dependency 'faastruby-rpc', '~> 0.1'
|
20
24
|
|
21
25
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
22
26
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
data/lib/faastruby/api.rb
CHANGED
@@ -131,7 +131,12 @@ module FaaStRuby
|
|
131
131
|
end
|
132
132
|
|
133
133
|
def parse(response)
|
134
|
-
|
134
|
+
begin
|
135
|
+
body = Oj.load(response.body) unless [500, 408].include?(response.code)
|
136
|
+
rescue Oj::ParseError => e
|
137
|
+
puts response.body
|
138
|
+
raise e
|
139
|
+
end
|
135
140
|
case response.code
|
136
141
|
when 401 then return error(["(401) Unauthorized - #{body['error']}"], 401)
|
137
142
|
when 404 then return error(["(404) Not Found - #{body['error']}"], 404)
|
data/lib/faastruby/cli.rb
CHANGED
@@ -21,6 +21,7 @@ module FaaStRuby
|
|
21
21
|
FaaStRuby::Command::Help.new(args).run
|
22
22
|
return
|
23
23
|
end
|
24
|
+
start_server(args) if command == 'server'
|
24
25
|
check_version
|
25
26
|
check_region
|
26
27
|
error("Unknown command: #{command}") unless FaaStRuby::Command::COMMANDS.has_key?(command)
|
@@ -42,5 +43,9 @@ module FaaStRuby
|
|
42
43
|
ENV['FAASTRUBY_REGION'] ||= DEFAULT_REGION
|
43
44
|
error(["No such region: #{ENV['FAASTRUBY_REGION']}".red, "Valid regions are: #{FaaStRuby::REGIONS.join(' | ')}"], color: nil) unless FaaStRuby::REGIONS.include?(ENV['FAASTRUBY_REGION'])
|
44
45
|
end
|
46
|
+
|
47
|
+
def self.start_server(args)
|
48
|
+
exec("faastruby-server #{args.join(' ')}")
|
49
|
+
end
|
45
50
|
end
|
46
51
|
end
|
@@ -57,7 +57,7 @@ EOS
|
|
57
57
|
|
58
58
|
def dir_exists?
|
59
59
|
return unless File.directory?(@base_dir)
|
60
|
-
print "The
|
60
|
+
print "The folder '#{@function_name}' already exists. Overwrite files? [y/N] "
|
61
61
|
response = STDIN.gets.chomp
|
62
62
|
FaaStRuby::CLI.error("Cancelled", color: nil) unless response == 'y'
|
63
63
|
end
|
@@ -96,4 +96,4 @@ EOS
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
end
|
99
|
-
end
|
99
|
+
end
|
@@ -7,11 +7,13 @@ module FaaStRuby
|
|
7
7
|
@missing_args = []
|
8
8
|
FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
|
9
9
|
@workspace_name = @args.shift
|
10
|
+
@base_dir = "./#{@workspace_name}"
|
10
11
|
parse_options
|
11
12
|
@options['credentials_file'] ||= FaaStRuby.credentials_file
|
12
13
|
end
|
13
14
|
|
14
15
|
def run
|
16
|
+
dir_exists? || FileUtils.mkdir_p(@base_dir)
|
15
17
|
spinner = spin("Requesting credentials...")
|
16
18
|
workspace = FaaStRuby::Workspace.create(name: @workspace_name, email: @options['email'])
|
17
19
|
spinner.stop("Done!")
|
@@ -37,6 +39,12 @@ module FaaStRuby
|
|
37
39
|
|
38
40
|
private
|
39
41
|
|
42
|
+
def dir_exists?
|
43
|
+
return false unless File.directory?(@base_dir)
|
44
|
+
puts "Local folder '#{@workspace_name}' already exists."
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
40
48
|
def missing_args
|
41
49
|
if @args.empty?
|
42
50
|
@missing_args << "Missing argument: WORKSPACE_NAME".red
|
@@ -16,8 +16,10 @@ module FaaStRuby
|
|
16
16
|
warning unless @options['force']
|
17
17
|
FaaStRuby::CLI.error("Cancelled") unless @options['force'] == 'y'
|
18
18
|
workspace = FaaStRuby::Workspace.new(name: @workspace_name)
|
19
|
+
spinner = spin("Destroying...")
|
19
20
|
workspace.destroy
|
20
21
|
FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
|
22
|
+
spinner.stop("Done!")
|
21
23
|
FaaStRuby::Credentials.remove(@workspace_name, @options['credentials_file'])
|
22
24
|
puts "Workspace '#{@workspace_name}' was deleted from the server"
|
23
25
|
end
|
data/lib/faastruby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: faastruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -94,6 +94,62 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.8'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: sinatra
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.0'
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: sinatra-contrib
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '2.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '2.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: puma
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.12'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.12'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: faastruby-rpc
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.1'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.1'
|
97
153
|
- !ruby/object:Gem::Dependency
|
98
154
|
name: bundler
|
99
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -155,6 +211,7 @@ email:
|
|
155
211
|
- parrudaj@gmail.com
|
156
212
|
executables:
|
157
213
|
- faastruby
|
214
|
+
- faastruby-server
|
158
215
|
extensions: []
|
159
216
|
extra_rdoc_files: []
|
160
217
|
files:
|
@@ -180,6 +237,7 @@ files:
|
|
180
237
|
- example/spec/helpers/faastruby.rb
|
181
238
|
- example/spec/spec_helper.rb
|
182
239
|
- exe/faastruby
|
240
|
+
- exe/faastruby-server
|
183
241
|
- faastruby.gemspec
|
184
242
|
- lib/faastruby.rb
|
185
243
|
- lib/faastruby/api.rb
|