pg_export 0.7.7 → 1.0.0.rc5
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/.gitignore +1 -0
- data/.travis.yml +6 -3
- data/CHANGELOG.md +11 -0
- data/README.md +14 -11
- data/bin/pg_export +92 -26
- data/lib/pg_export.rb +5 -13
- data/lib/pg_export/configuration.rb +18 -18
- data/lib/pg_export/container.rb +5 -30
- data/lib/pg_export/import.rb +1 -1
- data/lib/pg_export/lib/pg_export/factories/cipher_factory.rb +7 -10
- data/lib/pg_export/lib/pg_export/factories/ftp_gateway_factory.rb +22 -0
- data/lib/pg_export/lib/pg_export/factories/ssh_gateway_factory.rb +22 -0
- data/lib/pg_export/lib/pg_export/{adapters/ftp_adapter.rb → gateways/ftp.rb} +11 -8
- data/lib/pg_export/lib/pg_export/gateways/ssh.rb +83 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb +4 -4
- data/lib/pg_export/lib/pg_export/listeners/interactive/{close_ftp_connection.rb → close_connection.rb} +1 -1
- data/lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/{download_dump_from_ftp.rb → download_dump.rb} +3 -3
- data/lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/{fetch_dumps_from_ftp.rb → fetch_dumps.rb} +1 -1
- data/lib/pg_export/lib/pg_export/listeners/interactive/{open_ftp_connection.rb → open_connection.rb} +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/{remove_old_dumps_from_ftp.rb → remove_old_dumps.rb} +6 -6
- data/lib/pg_export/lib/pg_export/listeners/interactive/restore.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/interactive/select_database.rb +12 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/select_dump.rb +12 -0
- data/lib/pg_export/lib/pg_export/listeners/interactive/{upload_dump_to_ftp.rb → upload_dump.rb} +3 -3
- data/lib/pg_export/lib/pg_export/listeners/interactive_listener.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/{close_ftp_connection.rb → close_connection.rb} +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/{download_dump_from_ftp.rb → download_dump.rb} +3 -3
- data/lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb +2 -2
- data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/open_connection.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/prepare_params.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps.rb +17 -0
- data/lib/pg_export/lib/pg_export/listeners/plain/restore.rb +1 -1
- data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump.rb +15 -0
- data/lib/pg_export/lib/pg_export/listeners/plain_listener.rb +2 -2
- data/lib/pg_export/lib/pg_export/operations/{open_ftp_connection.rb → open_connection.rb} +5 -5
- data/lib/pg_export/lib/pg_export/operations/{remove_old_dumps_from_ftp.rb → remove_old_dumps.rb} +7 -7
- data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_file_repository.rb → gateway_dump_file_repository.rb} +3 -3
- data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_repository.rb → gateway_dump_repository.rb} +7 -7
- data/lib/pg_export/lib/pg_export/transactions/export_dump.rb +10 -10
- data/lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb +19 -19
- data/lib/pg_export/system/boot/config.rb +17 -1
- data/lib/pg_export/system/boot/ftp.rb +11 -0
- data/lib/pg_export/system/boot/interactive.rb +4 -20
- data/lib/pg_export/system/boot/operations.rb +17 -0
- data/lib/pg_export/system/boot/plain.rb +3 -20
- data/lib/pg_export/system/boot/ssh.rb +11 -0
- data/lib/pg_export/version.rb +1 -1
- data/pg_export.gemspec +9 -5
- metadata +101 -39
- data/lib/pg_export/build_logger.rb +0 -21
- data/lib/pg_export/lib/pg_export/factories/ftp_adapter_factory.rb +0 -22
- data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb +0 -15
- data/lib/pg_export/lib/pg_export/listeners/plain/open_ftp_connection.rb +0 -15
- data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb +0 -17
- data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb +0 -15
- data/lib/pg_export/system/boot/logger.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b927b4b2f8c0ca36682a15ae9f90aa975980d9d3874989f7ab19fe256fcecb7d
|
4
|
+
data.tar.gz: b653c480d52143bf58864f7904a404a21802aa389e9b24ee9f271dbafa064969
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1ae01b513f51ef4675b1dbae7337ac6ffe11d3ca481bf272ea6338e1f1b1bcd5fb75b240aefdcc12117e721a6097e945b1832af56344ac232ebfad55a5e98db
|
7
|
+
data.tar.gz: 31dc4ab7b943ce973f14b6a42867d388fa18a8c8f56d52bd9c0e5e30b241258555e804a4d59b53ed9d409fae8d7a8aa8ad8a130356383b66cbbbc4b1a1b75aba
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,9 +1,12 @@
|
|
1
|
-
sudo: false
|
2
1
|
language: ruby
|
3
2
|
rvm:
|
4
|
-
-
|
3
|
+
- 3.0.0
|
4
|
+
- 2.7.2
|
5
|
+
- 2.4.10
|
6
|
+
services:
|
7
|
+
- postgresql
|
5
8
|
addons:
|
6
9
|
code_climate:
|
7
10
|
repo_token: db03e5968c5bcd68b12ca50f5d41ae07dd74fe80d4e1421d754e31c316e7477a
|
8
|
-
before_install: gem install bundler -v
|
11
|
+
before_install: gem install bundler -v 2.2.3
|
9
12
|
after_success: codeclimate-test-reporter
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,14 @@
|
|
1
|
+
### 1.0.0 - 2021.03.20
|
2
|
+
- Make it compatible with Ruby 3.0
|
3
|
+
- Change configuration envs:
|
4
|
+
- BACKUP_FTP_HOST -> PG_EXPORT_GATEWAY_HOST
|
5
|
+
- BACKUP_FTP_USER -> PG_EXPORT_GATEWAY_USER
|
6
|
+
- BACKUP_FTP_PASSWORD -> PG_EXPORT_GATEWAY_PASSWORD
|
7
|
+
- DUMP_ENCRYPTION_KEY -> PG_EXPORT_ENCRYPTION_KEY
|
8
|
+
- Drop Ruby 2.3 support
|
9
|
+
- Add SSH option
|
10
|
+
- Add +encryption_algorith+ moption to interface
|
11
|
+
|
1
12
|
### 0.7.7 - 2020.09.07
|
2
13
|
|
3
14
|
- Upgrade dry-initializer
|
data/README.md
CHANGED
@@ -26,7 +26,7 @@ Features:
|
|
26
26
|
|
27
27
|
## Dependencies
|
28
28
|
|
29
|
-
* Ruby >= 2.3.0
|
29
|
+
* Ruby >= 2.4 (works with Ruby 3.0)
|
30
30
|
* $ pg_dump
|
31
31
|
* $ pg_restore
|
32
32
|
|
@@ -51,29 +51,32 @@ Or install it yourself as:
|
|
51
51
|
$ pg_export -h
|
52
52
|
|
53
53
|
Usage: pg_export [options]
|
54
|
+
-g, --gateway GATEWAY [Optional] ssh or ftp (default: ftp)
|
54
55
|
-d, --database DATABASE [Required] Name of the database to export
|
55
56
|
-k, --keep [KEEP] [Optional] Number of dump files to keep on FTP (default: 10)
|
56
57
|
-t, --timestamped [Optional] Enables log messages with timestamps
|
57
58
|
-m, --muted [Optional] Mutes log messages (overrides -t option)
|
58
59
|
-i, --interactive [Optional] Interactive command line mode - for restoring dumps into databases
|
60
|
+
-v, --version Show version
|
59
61
|
-h, --help Show this message
|
60
|
-
|
62
|
+
|
61
63
|
Setting can be verified by running following commands:
|
62
64
|
-c, --configuration Prints the configuration
|
63
|
-
-
|
65
|
+
-w, --welcome Tries connecting to the gateway (FTP or SSH) to verify the connection
|
66
|
+
|
64
67
|
|
65
68
|
## How to start
|
66
69
|
|
67
70
|
__Step 1.__ Prepare ENV variables.
|
68
71
|
|
69
72
|
/* FTP storage for database dumps. */
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
PG_EXPORT_GATEWAY_HOST=yourftp.example.com
|
74
|
+
PG_EXPORT_GATEWAY_USER=user
|
75
|
+
PG_EXPORT_GATEWAY_PASSWORD=password
|
73
76
|
|
74
|
-
/* Encryption key
|
77
|
+
/* Encryption key should have exactly 16 characters. */
|
75
78
|
/* Dumps will be SSL(AES-128-CBC) encrypted using this key. */
|
76
|
-
|
79
|
+
PG_EXPORT_ENCRYPTION_KEY=1234567890abcdef
|
77
80
|
|
78
81
|
/* Dumps to be kept on FTP */
|
79
82
|
/* Optional, defaults to 10 */
|
@@ -84,12 +87,12 @@ Note, that variables cannot include `#` sign, [more info](http://serverfault.com
|
|
84
87
|
__Step 2.__ Print the configuration to verify if env variables has been loaded properly.
|
85
88
|
|
86
89
|
$ pg_export --configuration
|
87
|
-
=> {:
|
88
|
-
:
|
90
|
+
=> {:encryption_key=>"k4***", :gateway_host=>"yourftp.example.com", :gateway_user=>"your_gateway_user",
|
91
|
+
:gateway_password=>"pass***", :logger_format=>"plain", :keep_dumps=>2}
|
89
92
|
|
90
93
|
__Step 3.__ Try connecting to FTP to verify the connection.
|
91
94
|
|
92
|
-
$ pg_export --ftp
|
95
|
+
$ pg_export --gateway ftp --welcome
|
93
96
|
=> 230 User your_ftp_user logged in
|
94
97
|
|
95
98
|
__Step 4.__ Perform database export.
|
data/bin/pg_export
CHANGED
@@ -4,33 +4,79 @@
|
|
4
4
|
require 'optparse'
|
5
5
|
|
6
6
|
require 'pg_export'
|
7
|
-
require 'pg_export/
|
7
|
+
require 'pg_export/version'
|
8
8
|
|
9
9
|
ENV['KEEP_DUMPS'] = ENV['KEEP_DUMPS'] || '10'
|
10
|
-
|
10
|
+
ENV['GATEWAY'] = 'ftp'
|
11
|
+
ENV['PG_EXPORT_MODE'] = 'plain'
|
12
|
+
ENV['PG_EXPORT_ENCRYPTION_ALGORITHM'] = 'AES-128-CBC'
|
13
|
+
|
11
14
|
database = nil
|
12
15
|
|
13
16
|
option_parser = OptionParser.new do |opts|
|
14
|
-
opts.banner =
|
17
|
+
opts.banner = <<~TXT
|
18
|
+
NAME
|
19
|
+
pg_export - CLI for exporting/importing PostgreSQL dumps via FTP/SSH
|
20
|
+
|
21
|
+
SYNOPSIS (default mode)
|
22
|
+
pg_export DATABASE [options]
|
23
|
+
|
24
|
+
SYNOPSIS (interactive mode)
|
25
|
+
pg_export --interactive [DATABASE] [options]
|
15
26
|
|
16
|
-
|
27
|
+
ARGUMENTS
|
28
|
+
DATABASE - database name to export (when default mode)
|
29
|
+
- phrase to filter database dumps by (when interactive mode)
|
30
|
+
|
31
|
+
OPTIONS
|
32
|
+
TXT
|
33
|
+
|
34
|
+
opts.program_name = 'pg_export'
|
35
|
+
opts.version = PgExport::VERSION
|
36
|
+
|
37
|
+
opts.on('-g', '--gateway GATEWAY', %w[ftp ssh], 'Allowed values: ftp, ssh. Default: ftp. Credentials need to be set via ENVs') do |g|
|
38
|
+
ENV['GATEWAY'] = g
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on('-s', '--ssh', 'Same as "--gateway ssh"') do
|
42
|
+
ENV['GATEWAY'] = 'ssh'
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on('-f', '--ftp', 'Same as "--gateway ftp"') do
|
46
|
+
ENV['GATEWAY'] = 'ftp'
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on('-d', '--database DATABASE', String, 'Alternative way of specifying name of the database to export or phrase to filter by') do |d|
|
17
50
|
database = d
|
18
51
|
end
|
19
52
|
|
20
|
-
opts.on('-
|
53
|
+
opts.on('-e', '--encryption_key KEY', String, 'Dumps will be SSL encrypted using this key. Should have exactly 16 characters. Overwrites PG_EXPORT_ENCRYPTION_KEY env') do |key|
|
54
|
+
ENV['PG_EXPORT_ENCRYPTION_KEY'] = key
|
55
|
+
end
|
56
|
+
|
57
|
+
opts.on('-a', '--algorithm ALGORITHM', String, 'Encryption cipher algorithm (default: AES-128-CBC). Overwrites PG_EXPORT_ENCRYPTION_ALGORITHM env. For available option see `$ openssl list -cipher-algorithms`') do |key|
|
58
|
+
ENV['PG_EXPORT_ENCRYPTION_KEY'] = key
|
59
|
+
end
|
60
|
+
|
61
|
+
opts.on('-k', '--keep KEEP', String, 'Number of dump files to keep on FTP (default: 10). Overwrites KEEP_DUMPS env') do |keep|
|
21
62
|
ENV['KEEP_DUMPS'] = keep
|
22
63
|
end
|
23
64
|
|
24
|
-
opts.on('-t', '--timestamped', '
|
65
|
+
opts.on('-t', '--timestamped', 'Enables log messages with timestamps') do
|
25
66
|
ENV['LOGGER_FORMAT'] = 'timestamped'
|
26
67
|
end
|
27
68
|
|
28
|
-
opts.on('-m', '--muted', '
|
69
|
+
opts.on('-m', '--muted', 'Mutes log messages (overrides -t option)') do
|
29
70
|
ENV['LOGGER_FORMAT'] = 'muted'
|
30
71
|
end
|
31
72
|
|
32
|
-
opts.on('-i', '--interactive', '
|
33
|
-
|
73
|
+
opts.on('-i', '--interactive', 'Interactive mode, for importing dumps') do
|
74
|
+
ENV['PG_EXPORT_MODE'] = 'interactive'
|
75
|
+
end
|
76
|
+
|
77
|
+
opts.on('-v', '--version', 'Show version') do
|
78
|
+
puts PgExport::VERSION
|
79
|
+
exit
|
34
80
|
end
|
35
81
|
|
36
82
|
opts.on('-h', '--help', 'Show this message') do
|
@@ -38,45 +84,65 @@ option_parser = OptionParser.new do |opts|
|
|
38
84
|
exit
|
39
85
|
end
|
40
86
|
|
41
|
-
opts.separator
|
87
|
+
opts.separator <<~TXT
|
88
|
+
|
89
|
+
ENV
|
90
|
+
PG_EXPORT_GATEWAY_HOST required
|
91
|
+
PG_EXPORT_GATEWAY_USER required
|
92
|
+
PG_EXPORT_GATEWAY_PASSWORD optional when eg. authorized key is added
|
93
|
+
PG_EXPORT_ENCRYPTION_KEY required or set by --encryption_key)
|
94
|
+
PG_EXPORT_ENCRYPTION_ALGORITHM required or set by --algorithm)
|
95
|
+
TXT
|
42
96
|
|
43
|
-
opts.
|
97
|
+
opts.separator "\nTEST RUN"
|
98
|
+
|
99
|
+
opts.on('-c', '--configuration', 'Print the configuration') do
|
100
|
+
require 'pg_export/container'
|
44
101
|
PgExport::Container.start(:config)
|
45
102
|
puts PgExport::Container['config'].to_h
|
46
103
|
exit
|
47
104
|
end
|
48
105
|
|
49
|
-
opts.on('-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
puts
|
106
|
+
opts.on('-w', '--welcome', 'Try connecting to the gateway (FTP or SSH) to verify the connection') do
|
107
|
+
require 'pg_export/container'
|
108
|
+
PgExport::Container.start(ENV['GATEWAY'].to_sym)
|
109
|
+
gateway = PgExport::Container['factories.gateway_factory'].gateway
|
110
|
+
puts gateway.welcome
|
111
|
+
exit
|
112
|
+
end
|
113
|
+
|
114
|
+
if ARGV.empty?
|
115
|
+
puts opts
|
54
116
|
exit
|
55
117
|
end
|
56
118
|
end
|
57
119
|
|
58
120
|
begin
|
59
121
|
option_parser.parse!
|
122
|
+
database = ARGV.first unless ARGV.empty?
|
60
123
|
rescue OptionParser::ParseError => e
|
61
124
|
warn e.message.capitalize
|
62
|
-
warn '
|
125
|
+
warn 'Details:'
|
126
|
+
warn option_parser.to_s.split("\n").grep(/ #{e.args.first}/).join("\n")
|
127
|
+
warn 'Type "pg_export" for available options'
|
63
128
|
exit
|
64
129
|
end
|
65
130
|
|
131
|
+
require 'pg_export/container'
|
132
|
+
|
66
133
|
begin
|
67
|
-
pg_export =
|
68
|
-
if interactive
|
69
|
-
PgExport.interactive
|
70
|
-
else
|
71
|
-
PgExport.plain
|
72
|
-
end
|
134
|
+
pg_export = PgExport.boot
|
73
135
|
rescue PgExport::InitializationError => e
|
74
136
|
warn 'Unable to initialize PgExport due to invalid configuration. Check you ENVs.'
|
75
137
|
warn "Detailed message: #{e.message}"
|
76
138
|
exit
|
77
139
|
end
|
78
140
|
|
79
|
-
|
80
|
-
|
81
|
-
|
141
|
+
begin
|
142
|
+
pg_export.call(database) do |result|
|
143
|
+
result.success { puts 'Success' }
|
144
|
+
result.failure { |outcome| warn outcome[:message] }
|
145
|
+
end
|
146
|
+
rescue Interrupt
|
147
|
+
puts
|
82
148
|
end
|
data/lib/pg_export.rb
CHANGED
@@ -1,24 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'pg_export/container'
|
4
|
+
require 'pg_export/import'
|
4
5
|
|
5
6
|
class PgExport
|
6
7
|
class InitializationError < StandardError; end
|
7
8
|
|
8
|
-
|
9
|
-
def interactive
|
10
|
-
PgExport::Container.start(:interactive)
|
11
|
-
new(transaction: PgExport::Container['transactions.import_dump_interactively'])
|
12
|
-
end
|
9
|
+
include Import['transaction']
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def initialize(transaction:)
|
21
|
-
@transaction = transaction
|
11
|
+
def self.boot
|
12
|
+
PgExport::Container.start(:main)
|
13
|
+
new
|
22
14
|
end
|
23
15
|
|
24
16
|
def call(database_name, &block)
|
@@ -1,34 +1,34 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'pg_export/lib/pg_export/types'
|
4
4
|
require 'dry-struct'
|
5
5
|
|
6
6
|
class PgExport
|
7
7
|
class Configuration < Dry::Struct
|
8
|
-
|
9
|
-
|
10
|
-
attribute :
|
11
|
-
attribute :
|
12
|
-
attribute :
|
13
|
-
attribute :
|
14
|
-
attribute :
|
15
|
-
attribute :
|
8
|
+
attribute :encryption_key, PgExport::Types::Strict::String.constrained(size: 16)
|
9
|
+
attribute :encryption_algorithm, PgExport::Types::Strict::String
|
10
|
+
attribute :gateway_host, PgExport::Types::Strict::String
|
11
|
+
attribute :gateway_user, PgExport::Types::Strict::String
|
12
|
+
attribute :gateway_password, PgExport::Types::Strict::String.optional
|
13
|
+
attribute :logger_format, PgExport::Types::Coercible::Symbol.enum(:plain, :timestamped, :muted)
|
14
|
+
attribute :keep_dumps, PgExport::Types::Coercible::Integer.constrained(gteq: 0)
|
15
|
+
attribute :gateway, PgExport::Types::Coercible::Symbol.enum(:ftp, :ssh)
|
16
|
+
attribute :mode, PgExport::Types::Coercible::Symbol.enum(:plain, :interactive)
|
16
17
|
|
17
18
|
def self.build(env)
|
18
19
|
new(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
encryption_key: env['PG_EXPORT_ENCRYPTION_KEY'],
|
21
|
+
encryption_algorithm: env['PG_EXPORT_ENCRYPTION_ALGORITHM'],
|
22
|
+
gateway_host: env['PG_EXPORT_GATEWAY_HOST'],
|
23
|
+
gateway_user: env['PG_EXPORT_GATEWAY_USER'],
|
24
|
+
gateway_password: env['PG_EXPORT_GATEWAY_PASSWORD'] == '' ? nil : env['PG_EXPORT_GATEWAY_PASSWORD'],
|
23
25
|
logger_format: env['LOGGER_FORMAT'] || 'plain',
|
24
|
-
keep_dumps: env['KEEP_DUMPS'] || 10
|
26
|
+
keep_dumps: env['KEEP_DUMPS'] || 10,
|
27
|
+
gateway: env['GATEWAY'],
|
28
|
+
mode: env['PG_EXPORT_MODE']
|
25
29
|
)
|
26
30
|
rescue Dry::Struct::Error => e
|
27
31
|
raise PgExport::InitializationError, e.message.gsub('[PgExport::Configuration.new] ', '')
|
28
32
|
end
|
29
|
-
|
30
|
-
def logger_muted?
|
31
|
-
logger_format == 'muted'
|
32
|
-
end
|
33
33
|
end
|
34
34
|
end
|
data/lib/pg_export/container.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'dry/system/container'
|
4
|
-
require 'pg_export/lib/pg_export/types'
|
5
4
|
|
6
5
|
class PgExport
|
7
6
|
class Container < Dry::System::Container
|
@@ -14,35 +13,11 @@ class PgExport
|
|
14
13
|
|
15
14
|
load_paths!('lib')
|
16
15
|
|
17
|
-
boot(:
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
start do
|
23
|
-
use :config
|
24
|
-
|
25
|
-
register('factories.ftp_adapter_factory') do
|
26
|
-
::PgExport::Factories::FtpAdapterFactory.new
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
boot(:main) do
|
32
|
-
init do
|
33
|
-
require 'pg_export/lib/pg_export/operations/encrypt_dump'
|
34
|
-
require 'pg_export/lib/pg_export/operations/decrypt_dump'
|
35
|
-
require 'pg_export/lib/pg_export/operations/remove_old_dumps_from_ftp'
|
36
|
-
require 'pg_export/lib/pg_export/operations/open_ftp_connection'
|
37
|
-
end
|
38
|
-
|
39
|
-
start do
|
40
|
-
use :ftp
|
41
|
-
register('operations.encrypt_dump') { ::PgExport::Operations::EncryptDump.new }
|
42
|
-
register('operations.decrypt_dump') { ::PgExport::Operations::DecryptDump.new }
|
43
|
-
register('operations.remove_old_dumps_from_ftp') { ::PgExport::Operations::RemoveOldDumpsFromFtp.new }
|
44
|
-
register('operations.open_ftp_connection') { ::PgExport::Operations::OpenFtpConnection.new }
|
45
|
-
end
|
16
|
+
boot(:main) do |system|
|
17
|
+
use(:config)
|
18
|
+
use(system[:config].gateway) # ftp/ssh
|
19
|
+
use(:operations)
|
20
|
+
use(system[:config].mode) # plain/interactive
|
46
21
|
end
|
47
22
|
end
|
48
23
|
end
|
data/lib/pg_export/import.rb
CHANGED
@@ -9,23 +9,20 @@ class PgExport
|
|
9
9
|
include Import['config']
|
10
10
|
|
11
11
|
def encryptor
|
12
|
-
|
12
|
+
build_cipher(:encrypt)
|
13
13
|
end
|
14
14
|
|
15
15
|
def decryptor
|
16
|
-
|
16
|
+
build_cipher(:decrypt)
|
17
17
|
end
|
18
18
|
|
19
19
|
private
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
cipher.public_send(type)
|
27
|
-
cipher.key = config.dump_encryption_key
|
28
|
-
end
|
21
|
+
def build_cipher(type)
|
22
|
+
cipher = OpenSSL::Cipher.new(config.encryption_algorithm)
|
23
|
+
cipher.public_send(type)
|
24
|
+
cipher.key = config.encryption_key
|
25
|
+
cipher
|
29
26
|
end
|
30
27
|
end
|
31
28
|
end
|