toolshed 1.0.6 → 1.0.7

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: 215029306670114b410a3c8e153734c8b6d9ce3d
4
- data.tar.gz: 27c11d5351604e6dcb24c3bd5f3c00a98f69c6fd
3
+ metadata.gz: 03f1f1b3fbd050039f62bf6a6c1a3cbfeedd8bce
4
+ data.tar.gz: b83471543158bd0015e7ed86e24fdda070946f5e
5
5
  SHA512:
6
- metadata.gz: f8fa73f9315ebae7f0d46d0cdb17a526a0593abf6b871f6a8c24857ca336e372efb8ce525f1e13f45013c50abbc814a1c739923e094a5507de940b401d13ffc7
7
- data.tar.gz: 9251f783275043a902ba2b889a0e11e1f982d9f72c18faf2976be8f65f470069651022efa9f478bd779ac479fcff1f0745e7b6bc0e4ea7c60f20eaf927a11dff
6
+ metadata.gz: 3e3592c41d1e744f1f903eaadd6d45faec1f71781a0936f9f35173efb1f45fe75cda1c3451e48486d291fa65dd61010cbaa5d71c6bf795c2b5e8bc0015e2c3f7
7
+ data.tar.gz: 1b619b9bb06b8c9322245261baa2924003ff0ce67ba148f0bac73cc825cbc36e428c6d1459ef8cf03f809e95b584d4a5ca8d71796be41c2e628140a49ee966d5
@@ -24,7 +24,7 @@ module Toolshed
24
24
  end
25
25
 
26
26
  all = a_stdout + a_stderr
27
- exit_status = wait_thr.value # Process::Status object returned.
27
+ exit_status = wait_thr.value.to_s # Process::Status object returned.
28
28
  result.merge!(stdout: a_stdout, stderr: a_stderr, all: all, process_status: exit_status) # rubocop:disable Metrics/LineLength
29
29
  end
30
30
  rescue ::Timeout::Error
@@ -10,7 +10,7 @@ module Toolshed
10
10
  {
11
11
  banner: 'Usage: mysql backup [options]',
12
12
  options: {
13
- local_host: {
13
+ host: {
14
14
  short_on: '-l'
15
15
  },
16
16
  path: {
@@ -44,7 +44,7 @@ module Toolshed
44
44
 
45
45
  def options_with_defaults(options = nil)
46
46
  options ||= {}
47
- options[:local_host] ||= 'localhost'
47
+ options[:host] ||= 'localhost'
48
48
  options[:path] ||= read_user_input("Storage Path (/tmp/test/#{Time.now.utc.getlocal.strftime('%Y%m%d')}.sql) ?", required: true)
49
49
  options[:username] ||= read_user_input('Username?', required: true)
50
50
  options[:name] ||= read_user_input('Database Name?', required: true)
@@ -1,17 +1,19 @@
1
1
  require 'toolshed/error'
2
2
  require 'toolshed/password'
3
3
 
4
+ require 'fileutils'
5
+
4
6
  module Toolshed
5
7
  module Databases
6
8
  module Mysql
7
9
  class Backup
8
10
  include Toolshed::Password
9
11
 
10
- attr_reader :local_host, :name, :path, :password, :username, :wait_time
12
+ attr_reader :host, :name, :path, :password, :username, :wait_time
11
13
 
12
14
  def initialize(options = nil)
13
15
  options ||= {}
14
- @local_host = options[:local_host]
16
+ @host = options[:host]
15
17
  @name = options[:name]
16
18
  @path = options[:path]
17
19
  @password = options[:password]
@@ -19,15 +21,26 @@ module Toolshed
19
21
  @wait_time = options[:wait_time] || 120
20
22
  end
21
23
 
24
+ def create_path
25
+ FileUtils.mkdir_p(File.dirname(path))
26
+ end
27
+
22
28
  def execute
23
29
  raise TypeError, "Wait time passed in is not a number #{wait_time}" unless wait_time.is_a?(Fixnum)
24
- Toolshed.logger.info "Starting execution of mysqldump -h #{local_host} -u #{username} #{hidden_password_param} #{name} > #{path}."
25
- Toolshed::Base.wait_for_command("mysqldump -h #{local_host} -u #{username} #{password_param} #{name} > #{path}", wait_time)
30
+ Toolshed.logger.info "Starting execution of mysqldump -h #{host} -u #{username} #{hidden_password_param} #{name} > #{path}."
31
+ create_path
32
+ results = Toolshed::Base.wait_for_command("mysqldump -h #{host} -u #{username} #{password_param} #{name} > #{path}", wait_time)
33
+ unless results[:stderr].is_a?(NilClass)
34
+ error_message = results[:stderr].join(' ')
35
+ Toolshed.logger.fatal error_message
36
+ raise Toolshed::PermissionsException, error_message
37
+ end
38
+ Toolshed.logger.info results[:stdout].join(' ') unless results[:stdout].is_a?(NilClass)
26
39
  Toolshed.logger.info 'mysqldump has completed.'
27
40
  end
28
41
 
29
42
  def password_param
30
- password.nil? || password.empty? ? '' : "-p #{password_from_config(password)}"
43
+ password.nil? || password.empty? ? '' : "-p#{password_from_config(password)}"
31
44
  end
32
45
 
33
46
  def hidden_password_param
@@ -10,14 +10,17 @@ module Toolshed
10
10
  translated_password = Toolshed.configuration
11
11
  password_parts = password.split(':')
12
12
  password_parts.each do |password_part|
13
- return password if translated_password[password_part].nil?
13
+ if translated_password[password_part].nil?
14
+ translated_password = password
15
+ break
16
+ end
14
17
  translated_password = translated_password[password_part]
15
18
  end
16
- return translated_password
19
+ translated_password
17
20
  rescue => e
18
21
  Toolshed::Logger.instance.fatal e.message
19
22
  Toolshed::Logger.instance.fatal e.inspect
20
- return password
23
+ password
21
24
  end
22
25
  end
23
26
  end
@@ -10,28 +10,30 @@ module Toolshed
10
10
  class SCP
11
11
  include Toolshed::Password
12
12
 
13
- attr_reader :local_path, :password, :remote_host, :remote_path, :username, :verbose_output # rubocop:disable LineLength
13
+ attr_reader :local_path, :password, :remote_host, :remote_path, :ssh_options, :username, :verbose_output # rubocop:disable LineLength
14
14
 
15
15
  def initialize(options = nil)
16
16
  options ||= {}
17
-
18
17
  @password = options[:password]
19
18
  @remote_host = options[:remote_host]
20
19
  @remote_path = options[:remote_path]
21
20
  @local_path = options[:local_path]
22
21
  @username = options[:username]
23
22
  @verbose_output = options[:verbose_output]
23
+ @ssh_options = options[:ssh_options]
24
+ @ssh_options ||= {}
25
+ @ssh_options.merge(password: password_from_config(password))
24
26
  end
25
27
 
26
28
  def download
27
29
  Toolshed.logger.info "Attempting to SCP from #{username}@#{remote_host}:#{remote_path} to #{local_path}." # rubocop:disable LineLength
28
- Net::SCP.download!(remote_host, username, remote_path, local_path, ssh: { password: password_from_config(password) }, recursive: true) # rubocop:disable LineLength
30
+ Net::SCP.download!(remote_host, username, remote_path, local_path, ssh: ssh_options, recursive: true) # rubocop:disable LineLength
29
31
  on_complete
30
32
  end
31
33
 
32
34
  def upload
33
35
  Toolshed.logger.info "Attempting to SCP from #{local_path} to #{username}@#{remote_host}:#{remote_path}." # rubocop:disable LineLength
34
- Net::SCP.upload!(remote_host, username, local_path, remote_path, ssh: { password: password_from_config(password) }, recursive: true) # rubocop:disable LineLength
36
+ Net::SCP.upload!(remote_host, username, local_path, remote_path, ssh: ssh_options, recursive: true) # rubocop:disable LineLength
35
37
  on_complete
36
38
  end
37
39
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Module for toolshed
4
4
  module Toolshed
5
- VERSION = '1.0.6'
5
+ VERSION = '1.0.7'
6
6
 
7
7
  # Display the version information with the toolshed banner
8
8
  class Version
@@ -15,7 +15,7 @@ module Test
15
15
  end
16
16
 
17
17
  def test_execute
18
- Toolshed::Base.expects(:wait_for_command).returns(true)
18
+ Toolshed::Base.expects(:wait_for_command).returns({})
19
19
 
20
20
  path = '/tmp/testing/test.sql'
21
21
  username = 'test'
@@ -15,14 +15,14 @@ module Test
15
15
  end
16
16
 
17
17
  def test_execute
18
- Toolshed::Base.expects(:wait_for_command).returns(true)
18
+ Toolshed::Base.expects(:wait_for_command).returns({})
19
19
 
20
20
  path = '/tmp/testing/test.sql'
21
21
  username = 'test'
22
22
  password = 'test'
23
23
  name = 'localdb'
24
24
 
25
- Toolshed::Databases::Mysql::Backup.new(path: path, username: username, password: password, name: name, local_host: 'localhost').execute
25
+ Toolshed::Databases::Mysql::Backup.new(path: path, username: username, password: password, name: name, host: 'localhost').execute
26
26
 
27
27
  assert Toolshed::Logger.instance.logs[:info].include?("Starting execution of mysqldump -h localhost -u #{username} -p ******* #{name} > #{path}.")
28
28
  assert Toolshed::Logger.instance.logs[:info].include?('mysqldump has completed.')
@@ -35,7 +35,7 @@ module Test
35
35
  name = 'localdb'
36
36
 
37
37
  ex = assert_raises TypeError do
38
- Toolshed::Databases::Mysql::Backup.new(path: path, username: username, password: password, name: name, local_host: 'localhost', wait_time: 'bla').execute
38
+ Toolshed::Databases::Mysql::Backup.new(path: path, username: username, password: password, name: name, host: 'localhost', wait_time: 'bla').execute
39
39
  end
40
40
  assert_equal 'Wait time passed in is not a number bla', ex.message
41
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toolshed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.6
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jake Waller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty