meroku 2.0.23 → 2.0.24

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
  SHA1:
3
- metadata.gz: 816206f9563347d62b87cfdc0efe4a2245655603
4
- data.tar.gz: f324cd878df16907747cf2f8026ed2fa74ac1893
3
+ metadata.gz: 6f904e491e3b5db4cac84dd8df856e3f261ed524
4
+ data.tar.gz: 50bc9918fee760e9023221be2ea2331fc4e3a515
5
5
  SHA512:
6
- metadata.gz: 81712892db6f34cce5e201865d6c1147ab69f5e0dbe7b9be63a2b7bda74b1d647c24195b4a6a30f7c6a9529f6112c8cf72e70cb407d7c65d3d02f036ea8c1c19
7
- data.tar.gz: 79120b685b9abba3109b8a4348d67fb342e9fd19d8c2c829b42a89e9c6bf9ad78fc613bb664ec0e8af38d891509773cbd522e05b4258c9355034fe4c8c0431ed
6
+ metadata.gz: bd05e025fb8078879f8950ce154d9d2b5d775f5f76cb1cb53aba11c1a6006cf750d5d8b9220eb2390ddc3f3e230b254ff84b831e9f4aa59e1da1e170f50e99a6
7
+ data.tar.gz: 38c5f3b0051a55eca784dc970ff02f1e250b7a3f6d7ae5124ac27955c3f5ad40d1d598c8c58a9616ad942a563934af417dd886ffd5c3ce0bfb028972de25c08b
data/.travis.yml CHANGED
@@ -3,3 +3,16 @@ language: ruby
3
3
  rvm:
4
4
  - 2.4.2
5
5
  before_install: gem install bundler -v 1.15.4
6
+
7
+ env:
8
+ global:
9
+ - CC_TEST_REPORTER_ID=61d42f990728bb450857fbd8b1f09d650f929f086d0d2d7d0c13ead9d33b77e2
10
+ - COVERAGE_PATH="coverage/"
11
+
12
+ before_script:
13
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
+ - chmod +x ./cc-test-reporter
15
+ - ./cc-test-reporter before-build
16
+
17
+ after_script:
18
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/README.md CHANGED
@@ -3,11 +3,10 @@ Meroku
3
3
 
4
4
  because hosting 100 apps costs $700 ($7x100) at you-know-where.com
5
5
 
6
- [![Quality](https://img.shields.io/codeclimate/github/meroku/meroku.svg?style=flat-square)](https://codeclimate.com/github/meroku/meroku)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/cfec7757799809e85194/maintainability)](https://codeclimate.com/github/meroku/meroku/maintainability)
7
7
  [![Coverage](https://img.shields.io/codeclimate/coverage/github/meroku/meroku.svg?style=flat-square)](https://codeclimate.com/github/meroku/meroku)
8
8
  [![Build](https://img.shields.io/travis-ci/meroku/meroku.svg?style=flat-square)](https://travis-ci.org/meroku/meroku)
9
9
  [![Dependencies](https://img.shields.io/gemnasium/meroku/meroku.svg?style=flat-square)](https://gemnasium.com/meroku/meroku)
10
- [![Downloads](https://img.shields.io/gem/meroku/meroku.svg?style=flat-square)](https://rubygems.org/gems/meroku)
11
10
  [![Issues](https://img.shields.io/github/issues/meroku/meroku.svg?style=flat-square)](https://github.com/meroku/meroku/issues)
12
11
  [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](http://opensource.org/licenses/MIT)
13
12
  [![Gem Version](https://badge.fury.io/rb/meroku.svg)](https://badge.fury.io/rb/meroku)
data/lib/meroku/aws.rb CHANGED
@@ -5,28 +5,34 @@ module Meroku
5
5
  module Aws
6
6
  include Meroku::Shared
7
7
 
8
- def make_instance
9
- @instance_id = Meroku::Shared.ec2_client.run_instances(
8
+ def default_instance_params
9
+ {
10
10
  image_id: 'ami-841f46ff',
11
11
  min_count: 1,
12
12
  max_count: 1,
13
13
  key_name: 'meroku.id_rsa',
14
14
  instance_type: 't2.micro',
15
15
  tag_specifications: [tag]
16
- ).instances.first.instance_id
16
+ }
17
+ end
18
+
19
+ def make_instance
20
+ @instance_id =
21
+ Meroku::Shared \
22
+ .ec2_client \
23
+ .run_instances(default_instance_params) \
24
+ .instances.fetch(0).instance_id
25
+ puts 'waiting'
26
+ Meroku::Shared.ec2_client.wait_until(
27
+ :instance_running,
28
+ instance_ids: [@instance_id]
29
+ )
17
30
  end
18
31
 
19
32
  def associate_address
20
- retries ||= 0
21
- sleep 10
22
- begin
23
- puts Meroku::Shared.ec2_client.associate_address(
24
- allocation_id: allocation_id, instance_id: instance_id
25
- ).class
26
- sleep 20
27
- rescue ::Aws::EC2::Errors::InvalidInstanceID
28
- (retries += 1) < 10 ? retry : raise
29
- end
33
+ Meroku::Shared.ec2_client.associate_address(
34
+ allocation_id: allocation_id, instance_id: instance_id
35
+ )
30
36
  end
31
37
 
32
38
  # Private S3 Bucket
data/lib/meroku/cli.rb CHANGED
@@ -14,9 +14,14 @@ module Meroku
14
14
 
15
15
  def run(args = ARGV)
16
16
  @options = Options.new.parse(args)
17
+ act_on_user_options
17
18
  act_on_options
18
- rescue Meroku::Error => e
19
- puts "Error: #{e.message}"
19
+ rescue Meroku::Success
20
+ return 0
21
+ rescue StandardError => e
22
+ print 'Error:'
23
+ print " #{e.message}" if e.message
24
+ print " <#{e.class}>\n"
20
25
  return 2
21
26
  end
22
27
 
@@ -27,10 +32,15 @@ module Meroku
27
32
  Meroku::Shared.secrets.meroku_secret = @options[:meroku_secret]
28
33
  end
29
34
  Node.new if @options[:spawn]
30
- User.login(@options[:email], @options[:password]) if @options[:login]
31
- User.logout if @options[:logout]
32
35
  Meroku::Aws.terminate_all(tag: 'node') if @options[:despawn]
33
36
  true
34
37
  end
38
+
39
+ def act_on_user_options
40
+ User.login(@options[:email], @options[:password]) if @options[:login]
41
+ User.logout if @options[:logout]
42
+ User.signup(@options[:email], @options[:password]) if @options[:signup]
43
+ User.unregister(@options) if @options[:unregister]
44
+ end
35
45
  end
36
46
  end
data/lib/meroku/error.rb CHANGED
@@ -6,6 +6,5 @@ module Meroku
6
6
  # immediately, rather than carrying on
7
7
  class Error < StandardError; end
8
8
 
9
- class WipError < Error; end
10
- class LoginFailed < Error; end
9
+ class Success < RuntimeError; end
11
10
  end
data/lib/meroku/node.rb CHANGED
@@ -105,7 +105,7 @@ module Meroku
105
105
  execute_script <<~HEREDOC
106
106
  cd ~/backend_api; sudo gem install bundler; bundle;
107
107
  cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec rake db:migrate db:seed
108
- cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} SECRET_KEY_BASE=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec puma -d -b unix:///home/ubuntu/backend_api/tmp/backend_api.sock
108
+ cd ~/backend_api; SECRET=#{Meroku::Shared.secrets.meroku_secret} SECRET_KEY_BASE=#{Meroku::Shared.secrets.meroku_secret} RAILS_ENV=production bundle exec unicorn -D -l unix:///home/ubuntu/backend_api/tmp/backend_api.sock -c config/unicorn.rb
109
109
  sudo /usr/sbin/nginx -s reload
110
110
  HEREDOC
111
111
  end
@@ -22,13 +22,27 @@ module Meroku
22
22
  puts opts
23
23
  end
24
24
 
25
- add_users_options(opts)
25
+ add_users_registration_options(opts)
26
+ add_users_login_options(opts)
26
27
  opts.separator ''
27
28
  add_maintainers_options(opts)
28
29
  end
29
30
  end
30
31
 
31
- def add_users_options(opts)
32
+ def add_users_registration_options(opts)
33
+ option(opts, '--signup EMAIL,PASSWORD', Array) do |list|
34
+ @options[:signup] = true
35
+ @options[:email] = list[0]
36
+ @options[:password] = list[1]
37
+ end
38
+ option(opts, '--unregister EMAIL,PASSWORD', Array) do |list|
39
+ @options[:unregister] = true
40
+ @options[:email] = list[0]
41
+ @options[:password] = list[1]
42
+ end
43
+ end
44
+
45
+ def add_users_login_options(opts)
32
46
  option(opts, '--login EMAIL,PASSWORD', Array) do |list|
33
47
  @options[:login] = true
34
48
  @options[:email] = list[0]
data/lib/meroku/user.rb CHANGED
@@ -4,22 +4,63 @@ module Meroku
4
4
  # Logic related to Users login, logout etc
5
5
  module User
6
6
  def self.login(email, password)
7
- url = 'https://www.meroku.com/login.json'
8
7
  data = { 'email' => email, 'password' => password }.to_json
9
- result = RestClient.post url,
8
+ result = RestClient.post 'https://www.meroku.com/login.json',
10
9
  data,
11
10
  content_type: :json
12
- token = JSON.parse(result.body)['token']
13
- IO.write("#{Dir.home}/.meroku_token", token)
14
- puts 'Logged in'
15
- rescue RestClient::Unauthorized
16
- raise Meroku::LoginFailed, 'Login Failed'
11
+ process_error(result)
12
+ process_success(result) { |x| save_token(x) }
13
+ end
14
+
15
+ def self.process_error(result)
16
+ raise Meroku::Error, JSON.parse(result).dig('errors') \
17
+ if JSON.parse(result).dig('errors')
18
+ end
19
+
20
+ def self.process_success(result)
21
+ id = JSON.parse(result).dig('data', 'id')
22
+ if id
23
+ yield(result) if block_given?
24
+ puts "OK [#{id}]"
25
+ end
26
+ raise Meroku::Success
27
+ end
28
+
29
+ def self.save_token(x)
30
+ token = JSON.parse(x).dig('data', 'id')
31
+ IO.write("#{Dir.home}/.meroku_token", token) if token
17
32
  end
18
33
 
19
34
  def self.logout
20
35
  file = "#{Dir.home}/.meroku_token"
21
- File.delete(file) if File.exist?(file)
36
+ File.delete(file)
22
37
  puts 'Logged out'
38
+ raise Meroku::Success
39
+ end
40
+
41
+ def self.signup(email, password)
42
+ data = { 'email' => email, 'password' => password }.to_json
43
+ result = RestClient.post 'https://www.meroku.com/registrations.json',
44
+ data,
45
+ content_type: :json
46
+ process_error(result)
47
+ process_success(result) { |x| save_token(x) }
48
+ end
49
+
50
+ def self.unregister(options)
51
+ data = { 'email' => options[:email], 'password' => options[:password] }
52
+ result = RestClient::Request.execute(
53
+ method: :delete,
54
+ url: 'https://www.meroku.com/registrations.json',
55
+ headers: { params: data }
56
+ )
57
+ process_error(result)
58
+ process_success(result) { delete_token }
59
+ end
60
+
61
+ def self.delete_token
62
+ file = "#{Dir.home}/.meroku_token"
63
+ File.delete(file) if File.exist?(file)
23
64
  end
24
65
  end
25
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Meroku
4
- VERSION = '2.0.23'
4
+ VERSION = '2.0.24'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meroku
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.23
4
+ version: 2.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - Meroku System
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-11-05 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug