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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e947223f9a44c7019dab288b430f625aa030004c574f77be0a1702e29d7582e
|
4
|
+
data.tar.gz: ab438317e8aca46fd893cf29160d1537dd9421085b6c457cb50b9cb2eb2a1c20
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6830c604ae0693f66f5583ced3695d5c7fc49cb117dab05dc9770dfaecc21fbfc97d0c5080cffb35bf700c84c7ea122be56e1480cd7d5362bcf15f663ccdb11d
|
7
|
+
data.tar.gz: 80183f91c9e2c2f07f50e86f853f1c01a8f917739591e4c8b0323a70d80f0ddbc5eeec056f91e7f22c529733a338cb4371a09c0c8093f354d8fb9394d68422aa
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
-
## 0.
|
3
|
+
## 0.5.0 - Mar 8 2019
|
4
|
+
- Introduces FaaStRuby Local
|
5
|
+
- Introduce user accounts and a migration tool to move the legacy workspace credentials into your account.
|
4
6
|
- New key on faastruby.yml - `before_build` allows you to specify commands to run locally before building and uploading the function package.
|
7
|
+
- New command: `update-workspace WORKSPACE_NAME --runners INT` - set the number of runners for a workspace.
|
5
8
|
|
6
9
|
## 0.4.18 - Feb 6 2019
|
7
10
|
- Bumps runtime crystal:0.27.1 to crystal:0.27.2
|
@@ -26,7 +29,7 @@
|
|
26
29
|
- Better message when updating the function context
|
27
30
|
- Fixed output when creating a function with `faastruby new`
|
28
31
|
|
29
|
-
A new version of the platform API was released in tandem to address the issue that would erase contexts when a function is redeployed. Thanks [Justin](https://github.com/presidentbeef) again for pointing that out.
|
32
|
+
A new version of the platform API was released in tandem to address the issue that would erase contexts when a function is redeployed. Thanks [Justin](https://github.com/presidentbeef) again for pointing that out.
|
30
33
|
|
31
34
|
## 0.4.12 - Jan 26 2019
|
32
35
|
Special thanks to [Sean Earle](https://github.com/HellRok) for fixing those bugs!
|
@@ -40,7 +43,7 @@ Special thanks to [Sean Earle](https://github.com/HellRok) for fixing those bugs
|
|
40
43
|
- Fix command `faastruby server`
|
41
44
|
|
42
45
|
## 0.4.9 - Jan 13 2019
|
43
|
-
- Changes in `faastruby server`
|
46
|
+
- Changes in `faastruby server`
|
44
47
|
- Cleaned up code
|
45
48
|
- Logs are easier to read
|
46
49
|
- Function responses show up in the log
|
data/Gemfile.lock
CHANGED
@@ -1,15 +1,19 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
faastruby (0.
|
4
|
+
faastruby (0.5.0)
|
5
5
|
colorize (~> 0.8)
|
6
|
-
faastruby-rpc (~> 0.2
|
6
|
+
faastruby-rpc (~> 0.2)
|
7
|
+
filewatcher (~> 1.1)
|
8
|
+
listen (~> 3.1)
|
7
9
|
oj (~> 3.6)
|
8
10
|
puma (~> 3.12)
|
9
11
|
rest-client (~> 2.0)
|
12
|
+
rouge (~> 3.3)
|
10
13
|
rubyzip (~> 1.2)
|
11
14
|
sinatra (~> 2.0)
|
12
15
|
sinatra-contrib (~> 2.0)
|
16
|
+
tmuxinator (~> 0.15)
|
13
17
|
tty-spinner (~> 0.8)
|
14
18
|
tty-table (~> 0.10)
|
15
19
|
|
@@ -18,7 +22,7 @@ GEM
|
|
18
22
|
specs:
|
19
23
|
addressable (2.5.2)
|
20
24
|
public_suffix (>= 2.0.2, < 4.0)
|
21
|
-
backports (3.
|
25
|
+
backports (3.12.0)
|
22
26
|
colorize (0.8.1)
|
23
27
|
crack (0.4.3)
|
24
28
|
safe_yaml (~> 1.0.0)
|
@@ -26,11 +30,19 @@ GEM
|
|
26
30
|
domain_name (0.5.20180417)
|
27
31
|
unf (>= 0.0.5, < 1.0.0)
|
28
32
|
equatable (0.5.0)
|
33
|
+
erubis (2.7.0)
|
29
34
|
faastruby-rpc (0.2.1)
|
30
35
|
oj (~> 3.6)
|
36
|
+
ffi (1.10.0)
|
37
|
+
filewatcher (1.1.1)
|
38
|
+
optimist (~> 3.0)
|
31
39
|
hashdiff (0.3.7)
|
32
40
|
http-cookie (1.0.3)
|
33
41
|
domain_name (~> 0.5)
|
42
|
+
listen (3.1.5)
|
43
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
44
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
45
|
+
ruby_dep (~> 1.2)
|
34
46
|
mime-types (3.2.2)
|
35
47
|
mime-types-data (~> 3.2015)
|
36
48
|
mime-types-data (3.2018.0812)
|
@@ -38,7 +50,8 @@ GEM
|
|
38
50
|
mustermann (1.0.3)
|
39
51
|
necromancer (0.4.0)
|
40
52
|
netrc (0.11.0)
|
41
|
-
oj (3.7.
|
53
|
+
oj (3.7.9)
|
54
|
+
optimist (3.0.0)
|
42
55
|
pastel (0.7.2)
|
43
56
|
equatable (~> 0.5.0)
|
44
57
|
tty-color (~> 0.4.0)
|
@@ -48,10 +61,14 @@ GEM
|
|
48
61
|
rack-protection (2.0.5)
|
49
62
|
rack
|
50
63
|
rake (10.5.0)
|
64
|
+
rb-fsevent (0.10.3)
|
65
|
+
rb-inotify (0.10.0)
|
66
|
+
ffi (~> 1.0)
|
51
67
|
rest-client (2.0.2)
|
52
68
|
http-cookie (>= 1.0.2, < 2.0)
|
53
69
|
mime-types (>= 1.16, < 4.0)
|
54
70
|
netrc (~> 0.8)
|
71
|
+
rouge (3.3.0)
|
55
72
|
rspec (3.8.0)
|
56
73
|
rspec-core (~> 3.8.0)
|
57
74
|
rspec-expectations (~> 3.8.0)
|
@@ -65,6 +82,7 @@ GEM
|
|
65
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
66
83
|
rspec-support (~> 3.8.0)
|
67
84
|
rspec-support (3.8.0)
|
85
|
+
ruby_dep (1.5.0)
|
68
86
|
rubyzip (1.2.2)
|
69
87
|
safe_yaml (1.0.4)
|
70
88
|
sinatra (2.0.5)
|
@@ -84,7 +102,12 @@ GEM
|
|
84
102
|
unicode-display_width (~> 1.4.0)
|
85
103
|
unicode_utils (~> 1.4.0)
|
86
104
|
strings-ansi (0.1.0)
|
105
|
+
thor (0.20.3)
|
87
106
|
tilt (2.0.9)
|
107
|
+
tmuxinator (0.15.0)
|
108
|
+
erubis (~> 2.6)
|
109
|
+
thor (~> 0.19, >= 0.15.0)
|
110
|
+
xdg (~> 2.2, >= 2.2.3)
|
88
111
|
tty-color (0.4.3)
|
89
112
|
tty-cursor (0.6.0)
|
90
113
|
tty-screen (0.6.5)
|
@@ -105,6 +128,7 @@ GEM
|
|
105
128
|
addressable (>= 2.3.6)
|
106
129
|
crack (>= 0.3.2)
|
107
130
|
hashdiff
|
131
|
+
xdg (2.2.3)
|
108
132
|
|
109
133
|
PLATFORMS
|
110
134
|
ruby
|
data/README.md
CHANGED
@@ -10,23 +10,81 @@
|
|
10
10
|
CLI tool for managing workspaces and functions hosted at [FaaStRuby](https://faastruby.io).
|
11
11
|
|
12
12
|
## What is FaaStRuby?
|
13
|
-
FaaStRuby is a
|
13
|
+
FaaStRuby is a Serverless Software Development Platform for Ruby and Crystal.
|
14
14
|
|
15
15
|
* [Tutorial](https://faastruby.io/getting-started)
|
16
16
|
|
17
17
|
## Try it
|
18
18
|
|
19
|
-
|
19
|
+
Getting up and running is quick and easy:
|
20
|
+
|
21
|
+
![Getting up and running](https://s3.amazonaws.com/faastruby/public/create-project.mp4)
|
22
|
+
|
23
|
+
1. Install the gem so `faastruby` is available in your terminal
|
20
24
|
|
21
25
|
```
|
22
26
|
~$ gem install faastruby
|
23
27
|
```
|
24
28
|
|
25
|
-
2. Create a
|
29
|
+
2. Create a new FaaStRuby project
|
30
|
+
|
31
|
+
```
|
32
|
+
~$ faastruby new-project hello-world
|
33
|
+
+ d ./hello-world
|
34
|
+
+ f ./hello-world/project.yml
|
35
|
+
+ f ./hello-world/secrets.yml
|
36
|
+
+ d ./hello-world/functions/root
|
37
|
+
+ f ./hello-world/functions/root/index.html.erb
|
38
|
+
+ f ./hello-world/functions/root/template.rb
|
39
|
+
+ f ./hello-world/functions/root/handler.rb
|
40
|
+
+ f ./hello-world/functions/root/faastruby.yml
|
41
|
+
+ d ./hello-world/functions/catch-all
|
42
|
+
+ f ./hello-world/functions/catch-all/404.html
|
43
|
+
+ f ./hello-world/functions/catch-all/handler.rb
|
44
|
+
+ f ./hello-world/functions/catch-all/faastruby.yml
|
45
|
+
+ f ./hello-world/public/faastruby.yml
|
46
|
+
+ f ./hello-world/.gitignore
|
47
|
+
Initialized empty Git repository in /Users/mf/OpenSource/faastruby/hello-world/.git/
|
48
|
+
Project 'hello-world' initialized.
|
49
|
+
Now run:
|
50
|
+
$ cd hello-world
|
51
|
+
$ faastruby local
|
52
|
+
```
|
53
|
+
|
54
|
+
3. Fire up the local development environment for your new project
|
26
55
|
|
27
56
|
```
|
28
|
-
~$ faastruby new hello-world
|
29
57
|
~$ cd hello-world
|
58
|
+
~/hello-world$ faastruby local
|
59
|
+
Puma starting in single mode...
|
60
|
+
* Version 3.12.0 (ruby 2.5.3-p105), codename: Llamas in Pajamas
|
61
|
+
* Min threads: 0, max threads: 32
|
62
|
+
* Environment: production
|
63
|
+
sh: crystal: command not found
|
64
|
+
2019-02-27 23:36:03 +0800 (EventHub) Channel subscriptions: {}
|
65
|
+
---
|
66
|
+
2019-02-27 23:36:03 +0800 (EventHub) Please restart the server if you modify channel subscriptions in 'faastruby.yml' for any function.
|
67
|
+
---
|
68
|
+
2019-02-27 23:36:03 +0800 (EventHub) Events thread started.
|
69
|
+
---
|
70
|
+
2019-02-27 23:36:03 +0800 (Sentinel) Ruby functions: ["root", "catch-all"]
|
71
|
+
---
|
72
|
+
2019-02-27 23:36:03 +0800 (Sentinel) Watching for new Ruby functions...
|
73
|
+
```
|
74
|
+
|
75
|
+
As you can see, this runs with Ruby only. If you want to run Crystal as well (similar to Ruby, but with types and compiled to run very fast), simply [install Crystal](https://crystal-lang.org/reference/installation/) and start `faastruby local` again.
|
76
|
+
|
77
|
+
|
78
|
+
`faastruby local` is very powerful. When you add a new folder with a `handler.rb` or `handler.cr`, it will automatically be detected. FaaStRuby will automatically add the configuration for the function so you can jump straight in:
|
79
|
+
|
80
|
+
![How to add a new folder and file](https://s3.amazonaws.com/faastruby/public/new-paths.mp4)
|
81
|
+
|
82
|
+
Changes to the code will automatically be detected and immediately refreshed for you, making local development easy and comfortable:
|
83
|
+
[!How to edit files and refresh them in the browser](https://s3.amazonaws.com/faastruby/public/local-file-refresh.mp4)
|
84
|
+
|
85
|
+
4. Deploy it to a workspace:
|
86
|
+
|
87
|
+
```
|
30
88
|
~/hello-world$ faastruby deploy-to awesome-prod
|
31
89
|
◐ Running tests... Passed!
|
32
90
|
...
|
@@ -50,4 +108,4 @@ Build lots of functions and share them with fellow Ruby devs!
|
|
50
108
|
|
51
109
|
## FaaStRuby + Hyperstack = fullstack Ruby apps!
|
52
110
|
|
53
|
-
Do you think JavaScript is your only option for the front-end? Think again. [Hyperstack](https://hyperstack.org) is a Ruby DSL, compiled by Opal, bundled by Webpack, powered by React.
|
111
|
+
Do you think JavaScript is your only option for the front-end? Think again. [Hyperstack](https://hyperstack.org) is a Ruby DSL, compiled by Opal, bundled by Webpack, powered by React.
|
data/faastruby.gemspec
CHANGED
@@ -20,7 +20,11 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_runtime_dependency 'sinatra', '~> 2.0'
|
21
21
|
spec.add_runtime_dependency 'sinatra-contrib', '~> 2.0'
|
22
22
|
spec.add_runtime_dependency 'puma', '~> 3.12'
|
23
|
-
spec.add_runtime_dependency 'faastruby-rpc', '~> 0.2
|
23
|
+
spec.add_runtime_dependency 'faastruby-rpc', '~> 0.2'
|
24
|
+
spec.add_runtime_dependency 'tmuxinator', '~> 0.15'
|
25
|
+
spec.add_runtime_dependency 'rouge', '~> 3.3'
|
26
|
+
spec.add_runtime_dependency 'listen', '~> 3.1'
|
27
|
+
|
24
28
|
|
25
29
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
26
30
|
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
data/lib/faastruby.rb
CHANGED
data/lib/faastruby/api.rb
CHANGED
@@ -7,7 +7,8 @@ module FaaStRuby
|
|
7
7
|
def initialize
|
8
8
|
@api_url = "#{FaaStRuby.api_host}/#{@@api_version}"
|
9
9
|
@credentials = {'API-KEY' => FaaStRuby.api_key, 'API-SECRET' => FaaStRuby.api_secret}
|
10
|
-
@
|
10
|
+
@base_headers = {client_version: FaaStRuby::VERSION, content_type: 'application/json', accept: 'application/json'}
|
11
|
+
@headers = @base_headers.merge(@credentials)
|
11
12
|
@struct = Struct.new(:response, :body, :errors, :code)
|
12
13
|
@timeout = nil # disable request timeouts
|
13
14
|
end
|
@@ -39,10 +40,154 @@ module FaaStRuby
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
def update_runners(workspace_name:, runners_max:)
|
44
|
+
url = "#{@api_url}/workspaces/#{workspace_name}/runners"
|
45
|
+
payload = {'runners_max' => runners_max}
|
46
|
+
parse RestClient::Request.execute(method: :patch, timeout: @timeout, url: url, headers: @headers, payload: Oj.dump(payload))
|
47
|
+
rescue RestClient::ExceptionWithResponse => err
|
48
|
+
case err.http_code
|
49
|
+
when 301, 302, 307
|
50
|
+
err.response.follow_redirection
|
51
|
+
else
|
52
|
+
parse err.response
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def signup(email:, password:)
|
57
|
+
url = "#{@api_url}/users/signup"
|
58
|
+
payload = {
|
59
|
+
'email' => email,
|
60
|
+
'password' => password
|
61
|
+
}
|
62
|
+
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, headers: @base_headers, payload: Oj.dump(payload))
|
63
|
+
rescue RestClient::ExceptionWithResponse => err
|
64
|
+
case err.http_code
|
65
|
+
when 301, 302, 307
|
66
|
+
err.response.follow_redirection
|
67
|
+
else
|
68
|
+
parse err.response
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def send_confirmation_code(email)
|
73
|
+
url = "#{@api_url}/users/confirm"
|
74
|
+
payload = {
|
75
|
+
'email' => email
|
76
|
+
}
|
77
|
+
parse RestClient::Request.execute(method: :patch, timeout: @timeout, url: url, headers: @base_headers, payload: Oj.dump(payload))
|
78
|
+
rescue RestClient::ExceptionWithResponse => err
|
79
|
+
case err.http_code
|
80
|
+
when 301, 302, 307
|
81
|
+
err.response.follow_redirection
|
82
|
+
else
|
83
|
+
parse err.response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def confirm_account(confirmation_token)
|
88
|
+
url = "#{@api_url}/users/confirm"
|
89
|
+
payload = {
|
90
|
+
'code' => confirmation_token
|
91
|
+
}
|
92
|
+
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, headers: @base_headers, payload: Oj.dump(payload))
|
93
|
+
rescue RestClient::ExceptionWithResponse => err
|
94
|
+
case err.http_code
|
95
|
+
when 301, 302, 307
|
96
|
+
err.response.follow_redirection
|
97
|
+
else
|
98
|
+
parse err.response
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def logout(api_key:, api_secret:, all: false)
|
103
|
+
url = "#{@api_url}/users/logout"
|
104
|
+
headers = @base_headers.merge({'API-KEY' => api_key, 'API-SECRET' => api_secret})
|
105
|
+
payload = {
|
106
|
+
'all' => all
|
107
|
+
}
|
108
|
+
parse RestClient::Request.execute(method: :delete, timeout: @timeout, url: url, headers: headers, payload: Oj.dump(payload))
|
109
|
+
rescue RestClient::ExceptionWithResponse => err
|
110
|
+
case err.http_code
|
111
|
+
when 301, 302, 307
|
112
|
+
err.response.follow_redirection
|
113
|
+
else
|
114
|
+
parse err.response
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def login(email:, password:)
|
119
|
+
url = "#{@api_url}/users/login"
|
120
|
+
payload = {
|
121
|
+
'email' => email,
|
122
|
+
'password' => password
|
123
|
+
}
|
124
|
+
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, headers: @base_headers, payload: Oj.dump(payload))
|
125
|
+
rescue RestClient::ExceptionWithResponse => err
|
126
|
+
case err.http_code
|
127
|
+
when 301, 302, 307
|
128
|
+
err.response.follow_redirection
|
129
|
+
else
|
130
|
+
parse err.response
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def migrate_to_account(workspace_name:, api_key:, api_secret:)
|
135
|
+
url = "#{@api_url}/workspaces/#{workspace_name}/migrate"
|
136
|
+
payload = {
|
137
|
+
'api_key' => api_key,
|
138
|
+
'api_secret' => api_secret
|
139
|
+
}
|
140
|
+
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, headers: @headers, payload: Oj.dump(payload))
|
141
|
+
rescue RestClient::ExceptionWithResponse => err
|
142
|
+
case err.http_code
|
143
|
+
when 301, 302, 307
|
144
|
+
err.response.follow_redirection
|
145
|
+
else
|
146
|
+
parse err.response
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
def get_static_metadata(workspace_name)
|
151
|
+
url = "#{@api_url}/workspaces/#{workspace_name}/static/metadata"
|
152
|
+
parse RestClient::Request.execute(method: :get, timeout: @timeout, url: url, headers: @headers)
|
153
|
+
rescue RestClient::ExceptionWithResponse => err
|
154
|
+
case err.http_code
|
155
|
+
when 301, 302, 307
|
156
|
+
err.response.follow_redirection
|
157
|
+
else
|
158
|
+
parse err.response
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def upload_file(workspace_name:, relative_path:, package:)
|
163
|
+
url = "#{@api_url}/workspaces/#{workspace_name}/static/sync"
|
164
|
+
payload = {package: File.new(package, 'rb')}
|
165
|
+
payload[:relative_path] = relative_path
|
166
|
+
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, payload: payload, headers: @credentials)
|
167
|
+
rescue RestClient::ExceptionWithResponse => err
|
168
|
+
case err.http_code
|
169
|
+
when 301, 302, 307
|
170
|
+
err.response.follow_redirection
|
171
|
+
else
|
172
|
+
parse err.response
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def delele_file(workspace_name:, relative_path:)
|
177
|
+
url = "#{@api_url}/workspaces/#{workspace_name}/static/sync"
|
178
|
+
payload = {
|
179
|
+
relative_path: relative_path
|
180
|
+
}
|
181
|
+
parse RestClient::Request.execute(method: :delete, timeout: @timeout, url: url, headers: @credentials, payload: payload)
|
182
|
+
rescue RestClient::ExceptionWithResponse => err
|
183
|
+
case err.http_code
|
184
|
+
when 301, 302, 307
|
185
|
+
err.response.follow_redirection
|
186
|
+
else
|
187
|
+
parse err.response
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
46
191
|
|
47
192
|
def get_workspace_info(workspace_name)
|
48
193
|
url = "#{@api_url}/workspaces/#{workspace_name}"
|
@@ -69,9 +214,12 @@ module FaaStRuby
|
|
69
214
|
end
|
70
215
|
end
|
71
216
|
|
72
|
-
def deploy(workspace_name:, package:)
|
217
|
+
def deploy(workspace_name:, package:, root_to: nil, catch_all: nil, context: nil)
|
73
218
|
url = "#{@api_url}/workspaces/#{workspace_name}/deploy"
|
74
219
|
payload = {package: File.new(package, 'rb')}
|
220
|
+
payload[:root_to] = root_to if root_to
|
221
|
+
payload[:catch_all] = catch_all if catch_all
|
222
|
+
payload[:context] = context if context
|
75
223
|
parse RestClient::Request.execute(method: :post, timeout: @timeout, url: url, payload: payload, headers: @credentials)
|
76
224
|
rescue RestClient::ExceptionWithResponse => err
|
77
225
|
case err.http_code
|
data/lib/faastruby/base.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module FaaStRuby
|
2
2
|
ROOT_DOMAIN = ENV['FAASTRUBY_ROOT_DOMAIN'] || 'faastruby.io'
|
3
|
+
WORKSPACE_BASE_HOST = ENV['FAASTRUBY_WORKSPACE_BASE_HOST'] || 'faast.cloud'
|
3
4
|
DEFAULT_REGION = 'tor1'
|
4
5
|
REGIONS = [
|
5
6
|
'tor1'
|
@@ -35,15 +36,8 @@ module FaaStRuby
|
|
35
36
|
ENV['FAASTRUBY_HOST'] || "https://api.#{region}.#{ROOT_DOMAIN}"
|
36
37
|
end
|
37
38
|
|
38
|
-
def self.
|
39
|
-
|
40
|
-
if region == DEFAULT_REGION && File.file?(File.expand_path('~/.faastruby'))
|
41
|
-
return File.expand_path('~/.faastruby')
|
42
|
-
elsif region == DEFAULT_REGION
|
43
|
-
return File.expand_path("~/.faastruby.#{region}")
|
44
|
-
else
|
45
|
-
return File.expand_path("~/.faastruby.#{region}")
|
46
|
-
end
|
39
|
+
def self.workspace_host_for(workspace_name)
|
40
|
+
"https://#{workspace_name}.#{region}.#{WORKSPACE_BASE_HOST}"
|
47
41
|
end
|
48
42
|
|
49
43
|
class Configuration
|