faastruby 0.3.2 → 0.3.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2d752da5ce5767b5c7b97f6e53e884ab2ba0123f36f713f6a70ba82fc8055acf
4
- data.tar.gz: d9c3038e42ca26f6b3de8953c06c7724a046549ae49942040ab8d9c3344536d2
3
+ metadata.gz: 335fa3ccc2c149a7f7c8f1551bf9e19d20d6195a81020557d252d580e157785c
4
+ data.tar.gz: ec71694b2713127f156d6424c71594559da5a44f80b434a5a2dc9b87cfbaa8b1
5
5
  SHA512:
6
- metadata.gz: 60085ed613203a88e39cbcc17aba0de3ed3884d6794255385e887c042097a871af5cb00069f422bcf96d855a969ec0e9253c98baf37c2819cefaf32737b8c6a0
7
- data.tar.gz: 2e50627ab43fd3fa0a6eabd702211d9df7759d810fa1691ef57177d390f4fa74730412b2c0c2c40a4429f05b83977520213a9fcac579766bf4c44bb459c61562
6
+ metadata.gz: 1d28851b29694062dcb7a4a04b35e290629a6f759dda9c244cdc44bef0eea177a37bc2f946042855f9fdd3bd1faa072e3c51d0b6bf9f391ad409fa6392b6dbc6
7
+ data.tar.gz: 758524d34c9a46aaf105ff92dd0618de98574e44fd0fad5543764b1e4a74b773659aafe8f601d45dd1400c51472556aa67a642f13bb353ade244746e68496e6e
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.3 - Dec 21 2018
4
+ - `deploy-to` will try to create the workspace if it doesn't exist.
5
+ - Changed template to add a carriage return.
6
+
3
7
  ## 0.3.2 - Dec 15 2018
4
8
  - Better output for tests
5
9
  - `bundle check && bundle install` runs before building a package to make sure Gemfile.lock is updated.
@@ -21,5 +21,5 @@ def handler event
21
21
  # The 'Content-Type' header is automatically set when you use 'render'.
22
22
  # You can set custom headers using a hash with string keys. Example:
23
23
  # render text: 'It Works!', headers: {'TransactionId' => 23928}
24
- render text: "Hello, #{data['name'] || 'World'}!"
24
+ render text: "Hello, #{data['name'] || 'World'}!\n"
25
25
  end
@@ -10,11 +10,11 @@ describe 'handler(event)' do
10
10
  end
11
11
  it 'should add the name to the response string' do
12
12
  body = handler(event).call.body
13
- expect(body).to be == 'Hello, Ruby!'
13
+ expect(body).to be == "Hello, Ruby!\n"
14
14
  end
15
15
  it 'should say Hello, World! when name is not present' do
16
16
  event = SpecHelper::Event.new(body: nil)
17
17
  body = handler(event).call.body
18
- expect(body).to be == 'Hello, World!'
18
+ expect(body).to be == "Hello, World!\n"
19
19
  end
20
20
  end
@@ -10,10 +10,11 @@ module FaaStRuby
10
10
  load_yaml
11
11
  @function_name = @yaml_config['name']
12
12
  @abort_when_tests_fail = @yaml_config['abort_deploy_when_tests_fail']
13
- FaaStRuby::Credentials.load_for(@workspace_name)
13
+ load_credentials(exit_on_error: false)
14
14
  end
15
15
 
16
16
  def run
17
+ create_or_use_workspace
17
18
  FaaStRuby::CLI.error('Please fix the problems above and try again') unless bundle_install
18
19
  tests_passed = run_tests
19
20
  FaaStRuby::CLI.error("Deploy aborted because tests failed and you have 'abort_deploy_when_tests_fail: true' in 'faastruby.yml'") unless tests_passed || !@abort_when_tests_fail
@@ -26,6 +27,7 @@ module FaaStRuby
26
27
  FaaStRuby::CLI.error(workspace.errors)
27
28
  end
28
29
  spinner.stop('Done!')
30
+ puts "Endpoint: #{FaaStRuby.api_host}/#{@workspace_name}/#{@function_name}"
29
31
  exit 0
30
32
  end
31
33
 
@@ -39,6 +41,24 @@ module FaaStRuby
39
41
 
40
42
  private
41
43
 
44
+ def load_credentials(exit_on_error:)
45
+ @has_credentials = FaaStRuby::Credentials.load_for(@workspace_name, exit_on_error: exit_on_error)
46
+ end
47
+
48
+ def create_or_use_workspace
49
+ unless @has_credentials
50
+ puts "Attemping to create workspace '#{@workspace_name}'"
51
+ cmd = FaaStRuby::Command::Workspace::Create.new([@workspace_name])
52
+ cmd.run(create_directory: false, exit_on_error: false)
53
+ load_credentials(exit_on_error: true)
54
+ # Give a little bit of time after creating the workspace
55
+ # for consistency. This is temporary until the API gets patched.
56
+ spinner = spin("Waiting for the new workspace to be ready...")
57
+ sleep 2
58
+ spinner.stop("Done!")
59
+ end
60
+ end
61
+
42
62
  def bundle_install
43
63
  puts '[build] Verifying dependencies'
44
64
  return true unless File.file?('Gemfile')
@@ -12,11 +12,11 @@ module FaaStRuby
12
12
  @options['credentials_file'] ||= FaaStRuby.credentials_file
13
13
  end
14
14
 
15
- def run
15
+ def run(create_directory: true, exit_on_error: true)
16
16
  spinner = spin("Requesting credentials...")
17
17
  workspace = FaaStRuby::Workspace.create(name: @workspace_name, email: @options['email'])
18
18
  spinner.stop("Done!")
19
- FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any?
19
+ FaaStRuby::CLI.error(workspace.errors) if workspace.errors.any? && exit_on_error
20
20
  if @options['stdout']
21
21
  puts "IMPORTANT: Please store the credentials below in a safe place. If you lose them you will not be able to manage your workspace.".yellow
22
22
  puts "API_KEY: #{workspace.credentials['api_key']}"
@@ -26,7 +26,7 @@ module FaaStRuby
26
26
  FaaStRuby::Credentials.add(@workspace_name, workspace.credentials, @options['credentials_file'])
27
27
  end
28
28
  puts "Workspace '#{@workspace_name}' created"
29
- create_dir unless dir_exists?
29
+ create_dir if create_directory && !dir_exists?
30
30
  end
31
31
 
32
32
  def self.help
@@ -34,13 +34,20 @@ module FaaStRuby
34
34
  puts "#{symbol} f #{credentials_file}".colorize(color)
35
35
  end
36
36
 
37
- def self.load_for(workspace_name, cred_file = FaaStRuby.credentials_file)
37
+ def self.load_for(workspace_name, cred_file = FaaStRuby.credentials_file, exit_on_error: true)
38
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)
39
+ error_msg = "Could not find credentials for '#{workspace_name}' in '#{cred_file}'"
40
+ if exit_on_error && !credentials[workspace_name]
41
+ FaaStRuby::CLI.error(error_msg)
42
+ elsif !credentials[workspace_name]
43
+ puts error_msg
44
+ return false
45
+ end
40
46
  FaaStRuby.configure do |config|
41
47
  config.api_key = credentials[workspace_name]['api_key']
42
48
  config.api_secret = credentials[workspace_name]['api_secret']
43
49
  end
50
+ return true
44
51
  end
45
52
 
46
53
  def self.load_from_env(workspace_name)
@@ -1,3 +1,3 @@
1
1
  module FaaStRuby
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.3'
3
3
  end
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.3.2
4
+ version: 0.3.3
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-12-16 00:00:00.000000000 Z
11
+ date: 2018-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client