gleis 0.4.0 → 0.5.0

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: e259aa0549f7f0a6e982128032b6229870ec360d1f8ff5df5cde09d0b56ac46b
4
- data.tar.gz: 79c8e30feb451306648f510cc03fabdfc7d1d38f5c80c722c18e70b0baa5781d
3
+ metadata.gz: 130f0b723f904109cb4cb38df148a8dc5a7748e40e3e4106ea646a004ccf1aa8
4
+ data.tar.gz: 2a9754ec31b238984825eb7d6a22f54e90528de1b3feb6c178f765bb18375057
5
5
  SHA512:
6
- metadata.gz: c9c407ddec056aa78d8b05675bdc7563444aa5978eb0cdf073fda9bffa62ad7ed348d1cfde96a51e4fe1ff6ff1405e31985e305d6bba6b8cf01c2b7f0eece7a5
7
- data.tar.gz: ad2c83adeab38fe45a52024f2e9df85ca2f6fc2f370b4aa9220079ed00ab0b20048e26793b9c4e3c06f2eb0345cb36c313a5d60b90b70795598be63b1cc731af
6
+ metadata.gz: b122513b42305f9764f184e65772db36fb7bcec1743e9404b3836c8c78d2efe0ed01f7a1c9445ddf83a4a2032b816c0b54fa245fa3af87b840d99234ed76c297
7
+ data.tar.gz: 5cb296c2bfcf9529328a7efaf73efa34963deffbf1bb7097d5fd831820089707f79cd077ab91e4fe3a2235bdbfa1ecc526da95051509d4f55b4ac36545d5fe04
data/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ All notable changes to the Gleis CLI will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.5.0 - 2019-02-25
9
+
10
+ ### Added
11
+
12
+ - New command called scheduler in order to manage scheduled job for an app
13
+ - Parameter --process/-p to app logs command to specify the process type (default: web)
14
+ - Check for new version of CLI after successfull login
15
+
16
+ ### Changed
17
+
18
+ - Status of app to inform under the Deployment field in case the app has not yet been deployed
19
+ - Forbidden rescue in API request to handle the case where the message is provided by the API
20
+
21
+ ### Fixed
22
+
23
+ - Wrong command description for removing an add-on
24
+ - Alias command parameters to include a leading dash
25
+
26
+ ### Removed
27
+
28
+ - Support for legacy rest-client (version <2.0) in API request
29
+
8
30
  ## 0.4.0 - 2019-02-10
9
31
 
10
32
  ### Added
data/lib/gleis/api.rb CHANGED
@@ -5,8 +5,6 @@ module Gleis
5
5
  class API
6
6
  def self.request(method, action, token = nil, body = {})
7
7
  url = Config::API_URL + Config::API_VERSION + '/cli/' + action
8
- # Support legacy rest-client (<2.0) which does not have RestClient::NotFound
9
- notfound_exception = defined?(RestClient::ResourceNotFound) ? RestClient::ResourceNotFound : RestClient::NotFound
10
8
  begin
11
9
  case method
12
10
  when 'get', 'delete'
@@ -23,9 +21,14 @@ module Gleis
23
21
  abort('Authentication failed.')
24
22
  rescue RestClient::Unauthorized
25
23
  abort('Not authenticated, please login first.')
26
- rescue RestClient::Forbidden
27
- abort('You do not have the required permissions, please contact the app owner.')
28
- rescue notfound_exception
24
+ rescue RestClient::Forbidden => e
25
+ message = if e.response.body.empty?
26
+ 'You do not have the required permissions, please contact the app owner.'
27
+ else
28
+ JSON.parse(e.response.body)['message']
29
+ end
30
+ abort(message)
31
+ rescue RestClient::NotFound
29
32
  abort('Application not found.')
30
33
  rescue RestClient::InternalServerError
31
34
  abort('An error occured on the platform. Please contact support if this problem persists.')
@@ -108,14 +108,16 @@ module Gleis
108
108
  end
109
109
  end
110
110
 
111
- def self.logs(app_name)
111
+ def self.logs(app_name, process)
112
112
  token = Token.check
113
- action = 'logs/' + app_name
113
+ action = "logs/#{app_name}/#{process}"
114
114
  body = API.request('get', action, token)
115
- if body['log'].nil? || body['log'].empty?
115
+ if body['log'].nil?
116
+ puts 'Failed to get logs: ' + body['message']
117
+ elsif body['log'].empty?
116
118
  puts 'No log entries found yet.'
117
119
  else
118
- puts "Last 100 lines of consolidated log output for #{app_name}:"
120
+ puts "Most recent entries of consolidated log for #{app_name} (#{process} process):"
119
121
  puts
120
122
  puts body['log']
121
123
  end
@@ -196,13 +198,15 @@ module Gleis
196
198
  puts "Status of app #{app_name}:\n\n"
197
199
  if body['success'] == 1
198
200
  status = body['data']
199
- if status['deployment_commit'] && status['deployment_version']
200
- deployment = "\tDeployment:\t#{status['deployment_commit']} (v#{status['deployment_version']})\n"
201
- end
201
+ deployment = if status['deployment_commit'] && status['deployment_version']
202
+ "#{status['deployment_commit']} (v#{status['deployment_version']})"
203
+ else
204
+ 'app not deployed yet'
205
+ end
202
206
  puts "\tStatus:\t\trunning\n" \
203
207
  "\tStarted at:\t#{Time.parse(status['createdat']).localtime.strftime('%c')}\n" \
204
208
  "\tUpdated at:\t#{Time.parse(status['updatedat']).localtime.strftime('%c')}\n" \
205
- "#{deployment}" \
209
+ "\tDeployment:\t#{deployment}\n" \
206
210
  "\tUpdate count:\t#{status['forceupdate']}\n" \
207
211
  "\tReplicas:\t#{status['replicas']}"
208
212
  else
@@ -16,6 +16,8 @@ module Gleis
16
16
  ssh_key_filename = Config::SSH_KEY_FILE_BASE + '_' + Utils.convert_username_to_filename(username)
17
17
  AuthKey.add("#{ssh_key_filename}.pub", nil, true) \
18
18
  if skip_keygen == false && SSH.generate_key(ssh_key_filename, username)
19
+ puts "\nINFO: New Gleis CLI version available, please update by running \"gem update gleis\"\n\n" \
20
+ if Utils.update_available?(Params.get_cli_parameters(token)['version'])
19
21
  end
20
22
 
21
23
  def self.register(email)
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Add-ons-related CLI commands
4
4
  class Addon < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add ADDON', 'Add add-on to app'
8
8
  def add(name)
@@ -14,7 +14,7 @@ module Gleis
14
14
  Gleis::Addon.list(options[:app])
15
15
  end
16
16
 
17
- desc 'remove ADDON', 'Add add-on to app'
17
+ desc 'remove ADDON', 'Remove add-on from app'
18
18
  def remove(name)
19
19
  Gleis::Addon.remove(options[:app], name)
20
20
  end
data/lib/gleis/cli/app.rb CHANGED
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Application-related CLI commands
4
4
  class App < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'config [VAR=value]', 'Show, set or delete environment variables'
8
8
  def config(env_var = '')
@@ -24,20 +24,22 @@ module Gleis
24
24
  Application.deployments(options[:app])
25
25
  end
26
26
 
27
- desc 'exec COMMAND', 'Execute a one-time-command (e.g. rails db:migrate)'
27
+ desc 'exec COMMAND', 'Execute a one-time-command (e.g. "rails db:migrate")'
28
28
  def exec(command)
29
29
  Application.exec(options[:app], command)
30
30
  end
31
31
 
32
32
  desc 'git', 'Show URL of git repository'
33
- option :quiet, aliases: :q, type: :boolean, default: false
33
+ option :quiet, aliases: :'-q', type: :boolean, default: false
34
34
  def git
35
35
  Application.git(options[:app], options[:quiet])
36
36
  end
37
37
 
38
- desc 'logs', 'View last log entries'
38
+ desc 'logs', 'View last log entries of a process'
39
+ option :process, aliases: :'-p', type: :string, default: 'web',
40
+ desc: 'Process type (valid types are: scheduler, worker and web)'
39
41
  def logs
40
- Application.logs(options[:app])
42
+ Application.logs(options[:app], options[:process])
41
43
  end
42
44
 
43
45
  desc 'maintenance', 'Enable or disable maintenance mode'
@@ -6,7 +6,7 @@ module Gleis
6
6
  subcommand 'key', CLI::AuthKey
7
7
 
8
8
  desc 'login USERNAME [PASSWORD]', 'Login into Gleis'
9
- option :skip_keygen, aliases: :s, type: :boolean, default: false
9
+ option :skip_keygen, aliases: :'-s', type: :boolean, default: false
10
10
  def login(username, password = nil)
11
11
  Authentication.login(username, password, options[:skip_keygen])
12
12
  end
data/lib/gleis/cli/db.rb CHANGED
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Database-related CLI subcommands
4
4
  class Db < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'backup', 'Backup locally database DATABASE_URL'
8
8
  def backup
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Domain-related CLI commands
4
4
  class Domain < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add DOMAIN', 'Add domain name to app'
8
8
  def add(name)
@@ -0,0 +1,27 @@
1
+ module Gleis
2
+ module CLI
3
+ # Add-ons-related CLI commands
4
+ class Scheduler < Thor
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
+
7
+ desc 'add COMMAND', 'Add command to be scheduled for this app'
8
+ option :frequency, aliases: :'-f', type: :string, required: true,
9
+ desc: 'Frequency to run job: 10minutes, hourly or daily'
10
+ option :time, aliases: :'-t', type: :string,
11
+ desc: 'Time in HH:MM format to run a job for the hourly (e.g. :15) or daily (e.g. 23:30) frequency'
12
+ def add(command)
13
+ Gleis::Scheduler.add(options[:app], options[:frequency], options[:time], command)
14
+ end
15
+
16
+ desc 'list', 'List scheduled job for this app'
17
+ def list
18
+ Gleis::Scheduler.list(options[:app])
19
+ end
20
+
21
+ desc 'remove', 'Remove scheduled job from app'
22
+ def remove
23
+ Gleis::Scheduler.remove(options[:app])
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Sharing-related CLI commands
4
4
  class Sharing < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add EMAIL ROLE', 'Allow user to access app (roles: collaborator, owner)'
8
8
  def add(email, role)
@@ -2,7 +2,7 @@ module Gleis
2
2
  module CLI
3
3
  # Storage-related CLI commands
4
4
  class Storage < Thor
5
- class_option :app, aliases: :a, type: :string, default: Utils.app_name, desc: 'Name of application'
5
+ class_option :app, aliases: :'-a', type: :string, default: Utils.app_name, desc: 'Name of application'
6
6
 
7
7
  desc 'add TYPE', 'Add storage to app'
8
8
  def add(type)
@@ -20,7 +20,7 @@ module Gleis
20
20
  end
21
21
 
22
22
  desc 'sync DIRECTORY', 'Synchronise local directory to Gleis storage (from local to remote)'
23
- option :reverse, aliases: :x, type: :boolean, default: false,
23
+ option :reverse, aliases: :'-x', type: :boolean, default: false,
24
24
  desc: 'Reverse synchronisation (from remote to local)'
25
25
  def sync(dir)
26
26
  Gleis::Storage.sync(options[:app], dir, options[:reverse])
data/lib/gleis/main.rb CHANGED
@@ -32,6 +32,9 @@ module Gleis
32
32
  desc 'mgmt COMMAND', 'Administration and management related commands'
33
33
  subcommand 'mgmt', CLI::Management
34
34
 
35
+ desc 'scheduler COMMAND', 'Manage scheduled job: add, list, remove'
36
+ subcommand 'scheduler', CLI::Scheduler
37
+
35
38
  desc 'sharing COMMAND', 'Manage collaboration: add, list, remove'
36
39
  subcommand 'sharing', CLI::Sharing
37
40
 
@@ -0,0 +1,44 @@
1
+ module Gleis
2
+ # The class implements the methods required to manage the scheduler service of a Gleis app
3
+ class Scheduler
4
+ def self.add(app_name, frequency, time, command)
5
+ token = Token.check
6
+ body = API.request('post', 'scheduler', token, 'name': app_name, 'frequency': frequency, 'time': time,
7
+ 'command': command)
8
+ if body['success'] == 1
9
+ puts "Successfully added scheduler job to #{app_name}."
10
+ else
11
+ puts "Failed to add scheduler job: #{body['message']}"
12
+ end
13
+ end
14
+
15
+ def self.list(app_name)
16
+ token = Token.check
17
+ body = API.request('get', "scheduler/#{app_name}", token)
18
+ jobs = body ['data']
19
+ if jobs.first.empty?
20
+ puts 'No scheduled jobs.'
21
+ else
22
+ puts "List of scheduled jobs:\n\n"
23
+ printf("\t%s\n", 'TIME')
24
+ printf("\t%-30s %-15s %s\n", 'COMMAND', 'FREQUENCY', 'LAST RUN')
25
+ printf("\t%-30s %-15s %s\n\n", '-------', '---------', '--------')
26
+ jobs.each do |job|
27
+ last_run = job['last_run'] ? Time.parse(job['last_run']).localtime.strftime('%c') : 'never'
28
+ printf("\t%-30s %-15s %s\n", job['cron_time'], job['frequency'], last_run)
29
+ puts "\t#{job['command']}\n\n"
30
+ end
31
+ end
32
+ end
33
+
34
+ def self.remove(app_name)
35
+ token = Token.check
36
+ body = API.request('delete', "scheduler/#{app_name}", token)
37
+ if body['success'] == 1
38
+ puts "Successfully removed scheduled job from #{app_name}."
39
+ else
40
+ puts "Failed to remove scheduled job: #{body['message']}"
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/gleis/utils.rb CHANGED
@@ -115,5 +115,9 @@ module Gleis
115
115
  end
116
116
  nil
117
117
  end
118
+
119
+ def self.update_available?(actual_version)
120
+ Gem::Version.new(Gleis::VERSION) < Gem::Version.new(actual_version)
121
+ end
118
122
  end
119
123
  end
data/lib/gleis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gleis
2
- VERSION = '0.4.0'
2
+ VERSION = '0.5.0'
3
3
  end
data/lib/gleis.rb CHANGED
@@ -11,6 +11,7 @@ require 'gleis/cli/auth'
11
11
  require 'gleis/cli/db'
12
12
  require 'gleis/cli/domain'
13
13
  require 'gleis/cli/management'
14
+ require 'gleis/cli/scheduler'
14
15
  require 'gleis/cli/sharing'
15
16
  require 'gleis/cli/storage'
16
17
  require 'gleis/config'
@@ -18,6 +19,7 @@ require 'gleis/database'
18
19
  require 'gleis/domain'
19
20
  require 'gleis/management'
20
21
  require 'gleis/params'
22
+ require 'gleis/scheduler'
21
23
  require 'gleis/sharing'
22
24
  require 'gleis/ssh'
23
25
  require 'gleis/storage'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gleis
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Bigler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-10 00:00:00.000000000 Z
11
+ date: 2019-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -149,6 +149,7 @@ files:
149
149
  - lib/gleis/cli/db.rb
150
150
  - lib/gleis/cli/domain.rb
151
151
  - lib/gleis/cli/management.rb
152
+ - lib/gleis/cli/scheduler.rb
152
153
  - lib/gleis/cli/sharing.rb
153
154
  - lib/gleis/cli/storage.rb
154
155
  - lib/gleis/config.rb
@@ -157,6 +158,7 @@ files:
157
158
  - lib/gleis/main.rb
158
159
  - lib/gleis/management.rb
159
160
  - lib/gleis/params.rb
161
+ - lib/gleis/scheduler.rb
160
162
  - lib/gleis/sharing.rb
161
163
  - lib/gleis/ssh.rb
162
164
  - lib/gleis/storage.rb