gleis 0.7.1 → 0.8.0

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: e3280f3d9b314f1cec830590c37979bf254307805c88f1f411bf2c65b483c39c
4
- data.tar.gz: 53c27f8be4e7b691bd3c1892cb806cdd3b3c65a9b92cda48826b60513bd6952f
3
+ metadata.gz: 5279f32d3b80eb5907b580db6a0377e308901890709e6a7db19e2118210decfd
4
+ data.tar.gz: f613f56d5dce97e59304b0e223cb94df1fab942e1e678ac24d5548bc7bee061e
5
5
  SHA512:
6
- metadata.gz: c8eb3cfbd61e91cb7488875ebe179cf09954fee641bbb510b1b33c1f0bd0495d53ed3a101b34b49deb8d408e707ec6002e8abc477e4259a108be021206ba6e7c
7
- data.tar.gz: 4f543eb031d9c696be13dfce9f9638e429776ca65974041a06419d5ab9e159eb679cbc75fe22fb59e45a0ae550fc9a3294b761bdd29a306568af9e5b388b56be
6
+ metadata.gz: 36336262ed60d02bac812b5617415b2d1dca4ba40b1c2d1ee1563e38a6c3e37ac7ac5f5229a718dc39203b82e736880a206eed3a71cb6b85c6c35501d907c464
7
+ data.tar.gz: 6264718149ab07be6825e20141921a38d9880ad5f2545d0dfb79684ef240997208e0c3352e58748d5055c3c103ab2696ed79703218f74befbf10b18c7597f206
data/CHANGELOG.md CHANGED
@@ -5,6 +5,20 @@ 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.8.0 - 2020-04-19
9
+
10
+ ### Changed
11
+
12
+ - Calls to system commands to check first if external system command exists
13
+ - External system call to which command with own which method
14
+ - Path separator to be dynamic for cross-platform compatibility
15
+ - Password prompt to use IO.noecho instead of depending on stty system command
16
+ - Save path of database dump file to be stored into user home directory instead of tmp
17
+
18
+ ### Fixed
19
+
20
+ - Adding SSH Host configuration in non-existing SSH config file
21
+
8
22
  ## 0.7.1 - 2020-03-20
9
23
 
10
24
  ### Changed
@@ -74,6 +74,7 @@ module Gleis
74
74
 
75
75
  def self.exec(app_name, command)
76
76
  token = Token.check
77
+ abort('The SSH client command ssh is not installed on this system.') unless Utils.which('ssh')
77
78
  config_body = Config.get_env_vars(app_name, token)
78
79
  # Get storage and generate mount parameter
79
80
  mount_param = Utils.generate_exec_mount_param(API.request('get', "storage/#{app_name}", token), app_name)
@@ -86,8 +87,8 @@ module Gleis
86
87
  -p #{p['run_port']} \
87
88
  #{p['run_username']}@#{p['run_server']} \
88
89
  '#{Utils.generate_exec_env_param(config_body['env_vars'])} #{mount_param} \
89
- #{p['registry_server']}/#{dp_body['namespace']}/#{app_name}:#{dp_body['deployments'].last['commit'][0..6]} \
90
- #{command}'")
90
+ #{p['registry_server']}/#{dp_body['namespace']}/#{app_name}:#{dp_body['deployments'].last['commit'][0..6]} \
91
+ #{command}'")
91
92
  else
92
93
  puts 'No deployments found, please deploy your app first.'
93
94
  end
data/lib/gleis/config.rb CHANGED
@@ -4,8 +4,8 @@ module Gleis
4
4
  # Override default API URL if GLEIS_API_URL env variable is set
5
5
  API_URL = ENV['GLEIS_API_URL'].nil? ? 'https://api.basel.gleis.app/' : ENV['GLEIS_API_URL']
6
6
  API_VERSION = 'v0'.freeze
7
- SSH_KEY_FILE_BASE = Dir.home + '/.ssh/gleis'
8
- TOKEN_FILE = Dir.home + '/.gleis-token'
7
+ SSH_KEY_FILE_BASE = File.join(Dir.home, '.ssh', 'gleis')
8
+ TOKEN_FILE = File.join(Dir.home, '.gleis-token')
9
9
 
10
10
  def self.get_env_vars(app_name, token)
11
11
  body = API.request('get', "config/#{app_name}", token)
@@ -8,7 +8,7 @@ module Gleis
8
8
  abort('There is no database configured under the DATABASE_URL variable.') unless url
9
9
  db_name = url.split('/').last
10
10
  timestamp = Time.now.strftime('%Y%m%d%H%M%S')
11
- backup_file = "/tmp/#{app_name}_#{db_name}_#{timestamp}.pgdump"
11
+ backup_file = File.join(Dir.home, "#{app_name}_#{db_name}_#{timestamp}.pgdump")
12
12
  if system("pg_dump -f #{backup_file} #{url}")
13
13
  puts "Database configured at DATABASE_URL succesfully backed up locally in #{backup_file}"
14
14
  else
@@ -102,7 +102,7 @@ module Gleis
102
102
 
103
103
  def self.psql(app_name)
104
104
  token = Token.check
105
- abort('The PostgreSQL client psql is not installed on this system.') unless system('which psql >/dev/null')
105
+ abort('The PostgreSQL client psql is not installed on this system.') unless Utils.which('psql')
106
106
  url = Config.get_env_var(app_name, token, 'DATABASE_URL')
107
107
  abort('There is no database configured under the DATABASE_URL variable.') unless url
108
108
  ENV['PGCONNECT_TIMEOUT'] = '5'
data/lib/gleis/ssh.rb CHANGED
@@ -11,9 +11,13 @@ module Gleis
11
11
 
12
12
  hostname = Socket.gethostname
13
13
  datetime = Time.now.strftime('%Y-%m-%d %H:%M')
14
- # returns true on success
15
- system('ssh-keygen', '-f', key_file, '-b 4096',
16
- "-C generated by Gleis CLI for #{username} by #{ENV['USER']}@#{hostname} on #{datetime}")
14
+ # returns true on success and nil if command is not found or failed
15
+ if Utils.which('ssh-keygen')
16
+ system('ssh-keygen', '-f', key_file, '-b 4096',
17
+ "-C generated by Gleis CLI for #{username} by #{ENV['USER']}@#{hostname} on #{datetime}")
18
+ else
19
+ puts 'The SSH key genator command ssh-keygen is not installed on this system.'
20
+ end
17
21
  end
18
22
 
19
23
  def self.load_public_key(public_key_file)
@@ -21,10 +25,10 @@ module Gleis
21
25
  end
22
26
 
23
27
  def self.add_host_to_config(host_name, private_key_file)
24
- config_file = Dir.home + '/.ssh/config'
28
+ config_file = File.join(Dir.home, '.ssh', 'config')
25
29
  ssh_host_line = "Host #{host_name}"
26
- # Check if SSH config for hosts already exists
27
- return if Utils.line_exists_in_file(config_file, ssh_host_line)
30
+ # Do not continue if host already exists in current SSH config file
31
+ return if File.exist?(config_file) && Utils.line_exists_in_file(config_file, ssh_host_line)
28
32
 
29
33
  f = File.open(config_file, 'a')
30
34
  f.puts "\n# Added by Gleis CLI on #{Time.now.strftime('%Y-%m-%d %H:%M')}"
data/lib/gleis/storage.rb CHANGED
@@ -51,7 +51,7 @@ module Gleis
51
51
  abort("Directory #{dir} does not exist or is not a directory.") unless Dir.exist?(dir)
52
52
  # Get CLI parameters from API server
53
53
  params = Params.get_cli_parameters(token)
54
- abort('The rsync tool is not installed on this system.') unless system('which rsync >/dev/null')
54
+ abort('The rsync tool is not installed on this system.') unless Utils.which('rsync')
55
55
  body = API.request('get', "storage/#{app_name}", token)
56
56
  if body['success'] == 1
57
57
  if (storage = body['data']['storage'].first)
data/lib/gleis/utils.rb CHANGED
@@ -1,3 +1,5 @@
1
+ require 'io/console'
2
+
1
3
  module Gleis
2
4
  # This class gathers various utilities as small methods
3
5
  class Utils
@@ -7,9 +9,7 @@ module Gleis
7
9
 
8
10
  def self.prompt_password
9
11
  print 'Password: '
10
- system 'stty -echo'
11
- password = $stdin.gets.chomp
12
- system 'stty echo'
12
+ password = STDIN.noecho(&:gets).chomp
13
13
  puts
14
14
  password
15
15
  end
@@ -32,7 +32,7 @@ module Gleis
32
32
 
33
33
  def self.check_for_local_pg_command(command)
34
34
  abort("The PostgreSQL client required to run the command #{command}) is not installed on this system.") unless
35
- system("which #{command} >/dev/null")
35
+ which(command)
36
36
  end
37
37
 
38
38
  def self.validate_scale_count(count)
@@ -48,7 +48,7 @@ module Gleis
48
48
  end
49
49
 
50
50
  def self.add_remote_to_git_config(remote_url)
51
- config_file = Dir.pwd + '/.git/config'
51
+ config_file = File.join(Dir.pwd, '.git', 'config')
52
52
  return false unless File.exist?(config_file)
53
53
 
54
54
  # Check if gleis remote already exists
@@ -119,5 +119,16 @@ module Gleis
119
119
  def self.update_available?(actual_version)
120
120
  Gem::Version.new(Gleis::VERSION) < Gem::Version.new(actual_version)
121
121
  end
122
+
123
+ def self.which(command)
124
+ file_extensions = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
125
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
126
+ file_extensions.each do |extension|
127
+ executable = File.join(path, "#{command}#{extension}")
128
+ return executable if File.executable?(executable) && !File.directory?(executable)
129
+ end
130
+ end
131
+ nil
132
+ end
122
133
  end
123
134
  end
data/lib/gleis/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gleis
2
- VERSION = '0.7.1'
2
+ VERSION = '0.8.0'
3
3
  end
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.7.1
4
+ version: 0.8.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: 2020-03-20 00:00:00.000000000 Z
11
+ date: 2020-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,8 +122,8 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.20.0
125
- description: Command-line interface to deploy and manage your Rails apps on the Swiss
126
- PaaS https://gleis.cloud
125
+ description: " Command-line interface to deploy and manage your Rails apps on the
126
+ https://gleis.cloud Swiss Platform as a Service.\n"
127
127
  email:
128
128
  - gleis@towards.ch
129
129
  executables: