faastruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a2b492f1a720606438bf41373fc04ef892932224b8272cc1ef9ee48a793d31e
4
- data.tar.gz: c9489fbc690bd3ab685067852c7dda8115c0a7c6f075b145ebeb92558f83c8ab
3
+ metadata.gz: 8f94b2b6822fa6d477e75642336d2d67c1f7c3f7596e87fa03e9119e43637836
4
+ data.tar.gz: 49986876b8202867c2e5e388656e517232e2bf2132c3acab624f1021541f4d10
5
5
  SHA512:
6
- metadata.gz: 2ddf53f3d75310e788d2671a6939d2706f7658bb946b49dfc5828c52816d8a091c06cf815e2a93e31294c09ae93d475ea82525c825f6bd44f3466d36e7387b5a
7
- data.tar.gz: 325b6fc49cb1168ac0522abdfaebad1bd06466d511e5271bcb9c0bdb03e5dda0dcac93a8abb990035b768997db52e1a864495234d61e98afa4fac84e050bec13
6
+ metadata.gz: 8bb18dedc52a1dedb1c379ed4cf318367e44f8e175a0ebe02b74f3ac7ca3e6d3829ff65cf49113beaa8a122e78cb2c3ce12f6c9de64e0afa8782e2d7a943cb94
7
+ data.tar.gz: 567d11e675800ae13e529aacb05011f207158673b7cc25874bfa93bdbae3cd1363c45ab3279280b3855eae417517da3392a7b7bff6776fba757bb1b8fdb96b63
@@ -1,11 +1,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1 - Oct 16 2018
4
+ - New command: `add-credentials` - add credentials to a credentials file
5
+ - New command: `list-credentials` - list current credentials in a credentials file
6
+ Run `faastruby help` for usage details.
7
+
3
8
  ## 0.2.0 - Oct 12 2018
4
- - Full rewrite of the gem. All command line parameters have changed. Please see the documentation.
5
- - No more git dependence.
6
- - Functions are packaged and deployed individually, and also removed individually.
9
+ - Full rewrite of the gem. All command line parameters have changed. Please see the [documentation](https://faastruby.io/tutorial.html).
10
+ - No more git repositories.
11
+ - Functions are packaged, deployed and managed individually.
7
12
  - Functions have a YAML configuration file.
8
- - Functions can have tests and they can be configured to run before each deploy, aborting it if a failure happens.
13
+ - Functions can have tests and they can be configured to run before each deploy, aborting if a failure happens.
9
14
  - Added option to print or save the workspace credentials into a different file upon creation, instead of saving it to ~/.faastruby
10
15
  - Read a different credentials file via FAASTRUBY_CREDENTIALS environment variable.
11
16
  - Read credentials via environment variables: FAASTRUBY_API_KEY and FAASTRUBY_API_SECRET.
@@ -2,12 +2,12 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  faastruby (0.2.0)
5
- colorize
6
- oj
7
- rest-client
8
- rubyzip
9
- tty-spinner
10
- tty-table
5
+ colorize (~> 0.8)
6
+ oj (~> 3.6)
7
+ rest-client (~> 2.0)
8
+ rubyzip (~> 1.2)
9
+ tty-spinner (~> 0.8)
10
+ tty-table (~> 0.10)
11
11
 
12
12
  GEM
13
13
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,39 +1,60 @@
1
- # FaaSt Ruby
1
+ [![Gem Version](https://badge.fury.io/rb/faastruby.svg)](https://badge.fury.io/rb/faastruby)
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/rubyfaas`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ # faastruby-cli
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ CLI tool for managing workspaces and functions hosted at [FaaStRuby](https://faastruby.io).
6
6
 
7
- ## Installation
7
+ ## What is FaaStRuby?
8
+ Fast, lightweight and scalable serverless platform built for Ruby developers.
8
9
 
9
- Add this line to your application's Gemfile:
10
+ * [Tutorial](https://faastruby.io/tutorial.html)
10
11
 
11
- ```ruby
12
- gem 'faastruby'
12
+ ## Try it
13
+
14
+ 1. Install the gem:
15
+
16
+ ```
17
+ $ gem install faastruby
13
18
  ```
14
19
 
15
- And then execute:
20
+ 2. Create a workspace to deploy your functions. The workspace name must be unique (like a username).
16
21
 
17
- $ bundle
22
+ ```
23
+ $ faastruby create-workspace awesome-prod
24
+ ```
18
25
 
19
- Or install it yourself as:
26
+ 3. Create a function and deploy it to your workspace:
20
27
 
21
- $ gem install faastruby
28
+ ```
29
+ $ faastruby new my-first-function
30
+ $ cd my-first-function
31
+ $ faastruby deploy-to awesome-prod
32
+ ◐ Running tests... Passed!
33
+ ...
22
34
 
23
- ## Usage
35
+ Finished in 0.00563 seconds (files took 0.15076 seconds to load)
36
+ 3 examples, 0 failures
24
37
 
25
- TODO: Write usage instructions here
38
+ Building package... Done!
39
+ ◐ Deploying to workspace 'awesome-prod'... Done!
40
+ ```
26
41
 
27
- ## Development
42
+ 4. Run it:
28
43
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+ ```
45
+ $ faastruby run awesome-prod --json '{"name":"Ruby"}'
46
+ Hello, Ruby!
47
+ ```
30
48
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
49
+ You can also generate a CURL command:
32
50
 
33
- ## Contributing
51
+ ```
52
+ $ faastruby run awesome-prod --json '{"name":"Ruby"}' --header 'My-Header: value' --query 'foo=bar' --query 'baz=fox' --curl
53
+ curl -X POST -H 'Content-Type: application/json' -H 'My-Header: value' -d '{"name":"Ruby"}' 'https://api.faastruby.io/awesome-prod/my-first-function?foo=bar&baz=fox'
54
+ ```
34
55
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/faastruby.
56
+ Build lots of functions and share them with fellow Ruby devs!
36
57
 
37
- ## License
58
+ ## FaaStRuby + Hyperstack = fullstack Ruby apps!
38
59
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
60
+ 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.
@@ -1,5 +1,5 @@
1
- require 'yaml'
2
1
  require 'tty-spinner'
2
+ require 'yaml'
3
3
  require 'tty-table'
4
4
  require 'zip'
5
5
  require 'colorize'
@@ -35,6 +35,7 @@ end
35
35
  require 'faastruby/cli/credentials'
36
36
  require 'faastruby/cli/commands/function'
37
37
  require 'faastruby/cli/commands/workspace'
38
+ require 'faastruby/cli/commands/credentials'
38
39
  require 'faastruby/cli/commands/help'
39
40
  require 'faastruby/cli/commands/version'
40
41
 
@@ -52,6 +53,8 @@ module FaaStRuby
52
53
  'list-workspace' => FaaStRuby::Command::Workspace::List,
53
54
  'test' => FaaStRuby::Command::Function::Test,
54
55
  'run' => FaaStRuby::Command::Function::Run,
56
+ 'add-credentials' => FaaStRuby::Command::Credentials::Add,
57
+ 'list-credentials' => FaaStRuby::Command::Credentials::List,
55
58
  'help' => FaaStRuby::Command::Help,
56
59
  '-h' => FaaStRuby::Command::Help,
57
60
  '--help' => FaaStRuby::Command::Help,
@@ -0,0 +1,11 @@
1
+ module FaaStRuby
2
+ module Command
3
+ module Credentials
4
+ class CredentialsBaseCommand < BaseCommand
5
+ end
6
+ end
7
+ end
8
+ end
9
+
10
+ require 'faastruby/cli/commands/credentials/add'
11
+ require 'faastruby/cli/commands/credentials/list'
@@ -0,0 +1,58 @@
1
+ module FaaStRuby
2
+ module Command
3
+ module Credentials
4
+ class Add < CredentialsBaseCommand
5
+ def initialize(args)
6
+ @args = args
7
+ @workspace_name = @args.shift
8
+ FaaStRuby::CLI.error(['Missing argument: WORKSPACE_NAME'.red, usage], color: nil) if @workspace_name.nil? || @workspace_name =~ /^-.*/
9
+ parse_options
10
+ @options['credentials_file'] ||= FAASTRUBY_CREDENTIALS
11
+ @missing_args = []
12
+ FaaStRuby::CLI.error(@missing_args, color: nil) if missing_args.any?
13
+ end
14
+
15
+ def run
16
+ new_credentials = {'api_key' => @options['api_key'], 'api_secret' => @options['api_secret']}
17
+ FaaStRuby::Credentials.add(@workspace_name, new_credentials, @options['credentials_file'])
18
+ puts "Credentials file updated."
19
+ end
20
+
21
+ def self.help
22
+ "add-credentials".blue + " WORKSPACE_NAME -k API_KEY -s API_SECRET [-c CREDENTIALS_FILE]"
23
+ end
24
+
25
+ def usage
26
+ "Usage: faastruby #{self.class.help}"
27
+ end
28
+
29
+ private
30
+
31
+ def missing_args
32
+ @missing_args << "Missing argument: API_KEY".red unless @options['api_key']
33
+ @missing_args << "Missing argument: API_SECRET".red unless @options['api_secret']
34
+ @missing_args << "Missing argument: CREDENTIALS_FILE".red unless @options['credentials_file']
35
+ @missing_args << usage if @missing_args.any?
36
+ @missing_args
37
+ end
38
+
39
+ def parse_options
40
+ @options = {}
41
+ while @args.any?
42
+ option = @args.shift
43
+ case option
44
+ when '-k', '--api-key'
45
+ @options['api_key'] = @args.shift
46
+ when '-c', '--credentials-file'
47
+ @options['credentials_file'] = @args.shift
48
+ when '-s', '--api-secret'
49
+ @options['api_secret'] = @args.shift
50
+ else
51
+ FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,54 @@
1
+ module FaaStRuby
2
+ module Command
3
+ module Credentials
4
+ class List < CredentialsBaseCommand
5
+ def initialize(args)
6
+ @args = args
7
+ parse_options
8
+ @options['credentials_file'] ||= FAASTRUBY_CREDENTIALS
9
+ end
10
+
11
+ def run
12
+ FaaStRuby::CLI.error("The file '#{@options['credentials_file']}' does not exist.") unless File.file?(@options['credentials_file'])
13
+ rows = []
14
+ credentials = FaaStRuby::Credentials.load_credentials_file(@options['credentials_file'])
15
+ FaaStRuby::CLI.error("The credentials file '#{@options['credentials_file']}' is empty.") unless credentials.any?
16
+ credentials.each do |workspace, credentials|
17
+ rows << [workspace, credentials['api_key'], credentials['api_secret']]
18
+ end
19
+ table = TTY::Table.new(['Workspace','API_KEY', 'API_SECRET'], rows)
20
+ puts table.render(:basic)
21
+ end
22
+
23
+ def self.help
24
+ "list-credentials".blue + " [-c CREDENTIALS_FILE]"
25
+ end
26
+
27
+ def usage
28
+ "Usage: faastruby #{self.class.help}"
29
+ end
30
+
31
+ private
32
+
33
+ def missing_args
34
+ @missing_args << "Missing argument: CREDENTIALS_FILE".red unless @options['credentials_file']
35
+ @missing_args << usage if @missing_args.any?
36
+ @missing_args
37
+ end
38
+
39
+ def parse_options
40
+ @options = {}
41
+ while @args.any?
42
+ option = @args.shift
43
+ case option
44
+ when '-c', '--credentials-file'
45
+ @options['credentials_file'] = @args.shift
46
+ else
47
+ FaaStRuby::CLI.error(["Unknown argument: #{option}".red, usage], color: nil)
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -28,7 +28,7 @@ module FaaStRuby
28
28
  end
29
29
 
30
30
  def self.help
31
- "create-workspace".blue + " WORKSPACE_NAME [--stdout|-o, --output-file] [-e, --email YOUR_EMAIL_ADDRESS]"
31
+ "create-workspace".blue + " WORKSPACE_NAME [--stdout|-c, --credentials-file CREDENTIALS_FILE] [-e, --email YOUR_EMAIL_ADDRESS]"
32
32
  end
33
33
 
34
34
  def usage
@@ -40,7 +40,7 @@ module FaaStRuby
40
40
  def missing_args
41
41
  if @args.empty?
42
42
  @missing_args << "Missing argument: WORKSPACE_NAME".red
43
- @missing_args << "Usage: faastruby create-workspace WORKSPACE_NAME"
43
+ @missing_args << usage
44
44
  end
45
45
  FaaStRuby::CLI.error(["'#{@args.first}' is not a valid workspace name.".red, usage], color: nil) if @args.first =~ /^-.*/
46
46
  @missing_args
@@ -55,7 +55,7 @@ module FaaStRuby
55
55
  # @options['credentials_file'] = @args.shift
56
56
  when '--stdout'
57
57
  @options['stdout'] = true
58
- when '-o', '--output-file'
58
+ when '-c', '--credentials-file'
59
59
  @options['credentials_file'] = @args.shift
60
60
  when '-e', '--email'
61
61
  @options['email'] = @args.shift
@@ -1,15 +1,17 @@
1
1
  module FaaStRuby
2
2
  class Credentials # TODO: change it to YAML?
3
- def self.load_credentials_file
4
- if File.file?(FAASTRUBY_CREDENTIALS)
5
- Oj.load(File.read(FAASTRUBY_CREDENTIALS))
3
+ def self.load_credentials_file(credentials_file = FAASTRUBY_CREDENTIALS)
4
+ if File.file?(credentials_file)
5
+ creds = Oj.load(File.read(credentials_file))
6
+ return creds if creds.is_a?(Hash)
7
+ return {}
6
8
  else
7
9
  {}
8
10
  end
9
11
  end
10
12
 
11
13
  def self.add(workspace_name, new_credentials, credentials_file)
12
- credentials = load_credentials_file
14
+ credentials = load_credentials_file(credentials_file)
13
15
  credentials.merge!({workspace_name => new_credentials})
14
16
  save_file(credentials, credentials_file)
15
17
  end
@@ -32,9 +34,9 @@ module FaaStRuby
32
34
  puts "#{symbol} f #{credentials_file}".colorize(color)
33
35
  end
34
36
 
35
- def self.load_for(workspace_name)
36
- credentials = load_from_env(workspace_name) || load_credentials_file
37
- FaaStRuby::CLI.error("Could not find credentials for '#{workspace_name}' in '#{FAASTRUBY_CREDENTIALS}'") unless credentials.has_key?(workspace_name)
37
+ def self.load_for(workspace_name, cred_file = FAASTRUBY_CREDENTIALS)
38
+ credentials = load_from_env(workspace_name) || load_credentials_file(cred_file)
39
+ FaaStRuby::CLI.error("Could not find credentials for '#{workspace_name}' in '#{cred_file}'") unless credentials.has_key?(workspace_name)
38
40
  FaaStRuby.configure do |config|
39
41
  config.api_key = credentials[workspace_name]['api_key']
40
42
  config.api_secret = credentials[workspace_name]['api_secret']
@@ -1,3 +1,3 @@
1
1
  module FaaStRuby
2
- VERSION = '0.2.0'
2
+ VERSION = '0.2.1'
3
3
  end
@@ -13,7 +13,7 @@ module FaaStRuby
13
13
  case response.code
14
14
  when 422
15
15
  workspace.errors += ['(422) Unprocessable Entity', response.body]
16
- when 200
16
+ when 200, 201
17
17
  workspace.credentials = response.body['credentials']
18
18
  else
19
19
  workspace.errors << "(#{response.code}) Error"
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.2.0
4
+ version: 0.2.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-10-12 00:00:00.000000000 Z
11
+ date: 2018-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -156,6 +156,9 @@ files:
156
156
  - lib/faastruby/base.rb
157
157
  - lib/faastruby/cli.rb
158
158
  - lib/faastruby/cli/commands.rb
159
+ - lib/faastruby/cli/commands/credentials.rb
160
+ - lib/faastruby/cli/commands/credentials/add.rb
161
+ - lib/faastruby/cli/commands/credentials/list.rb
159
162
  - lib/faastruby/cli/commands/function.rb
160
163
  - lib/faastruby/cli/commands/function/build.rb
161
164
  - lib/faastruby/cli/commands/function/deploy.rb