toolshed 1.0.6 → 1.0.7
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 +4 -4
- data/lib/toolshed/base.rb +1 -1
- data/lib/toolshed/commands/mysql/backup.rb +2 -2
- data/lib/toolshed/databases/mysql/backup.rb +18 -5
- data/lib/toolshed/password.rb +6 -3
- data/lib/toolshed/server_administration/scp.rb +6 -4
- data/lib/toolshed/version.rb +1 -1
- data/test/commands/mysql/backup_test.rb +1 -1
- data/test/databases/mysql/backup_test.rb +3 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03f1f1b3fbd050039f62bf6a6c1a3cbfeedd8bce
|
4
|
+
data.tar.gz: b83471543158bd0015e7ed86e24fdda070946f5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e3592c41d1e744f1f903eaadd6d45faec1f71781a0936f9f35173efb1f45fe75cda1c3451e48486d291fa65dd61010cbaa5d71c6bf795c2b5e8bc0015e2c3f7
|
7
|
+
data.tar.gz: 1b619b9bb06b8c9322245261baa2924003ff0ce67ba148f0bac73cc825cbc36e428c6d1459ef8cf03f809e95b584d4a5ca8d71796be41c2e628140a49ee966d5
|
data/lib/toolshed/base.rb
CHANGED
@@ -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
|
-
|
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[:
|
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 :
|
12
|
+
attr_reader :host, :name, :path, :password, :username, :wait_time
|
11
13
|
|
12
14
|
def initialize(options = nil)
|
13
15
|
options ||= {}
|
14
|
-
@
|
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 #{
|
25
|
-
|
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
|
43
|
+
password.nil? || password.empty? ? '' : "-p#{password_from_config(password)}"
|
31
44
|
end
|
32
45
|
|
33
46
|
def hidden_password_param
|
data/lib/toolshed/password.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
19
|
+
translated_password
|
17
20
|
rescue => e
|
18
21
|
Toolshed::Logger.instance.fatal e.message
|
19
22
|
Toolshed::Logger.instance.fatal e.inspect
|
20
|
-
|
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:
|
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:
|
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
|
|
data/lib/toolshed/version.rb
CHANGED
@@ -15,14 +15,14 @@ module Test
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def test_execute
|
18
|
-
Toolshed::Base.expects(:wait_for_command).returns(
|
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,
|
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,
|
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.
|
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:
|
11
|
+
date: 2016-04-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|