pg_export 0.7.6 → 1.0.0.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +6 -3
  4. data/CHANGELOG.md +15 -0
  5. data/README.md +14 -11
  6. data/bin/pg_export +91 -26
  7. data/lib/pg_export.rb +5 -13
  8. data/lib/pg_export/configuration.rb +21 -13
  9. data/lib/pg_export/container.rb +5 -30
  10. data/lib/pg_export/import.rb +1 -1
  11. data/lib/pg_export/lib/pg_export/factories/cipher_factory.rb +7 -10
  12. data/lib/pg_export/lib/pg_export/factories/ftp_gateway_factory.rb +22 -0
  13. data/lib/pg_export/lib/pg_export/factories/ssh_gateway_factory.rb +22 -0
  14. data/lib/pg_export/lib/pg_export/{adapters/ftp_adapter.rb → gateways/ftp.rb} +11 -8
  15. data/lib/pg_export/lib/pg_export/gateways/ssh.rb +83 -0
  16. data/lib/pg_export/lib/pg_export/listeners/interactive/build_dump.rb +4 -4
  17. data/lib/pg_export/lib/pg_export/listeners/interactive/{close_ftp_connection.rb → close_connection.rb} +1 -1
  18. data/lib/pg_export/lib/pg_export/listeners/interactive/decrypt_dump.rb +2 -2
  19. data/lib/pg_export/lib/pg_export/listeners/interactive/{download_dump_from_ftp.rb → download_dump.rb} +3 -3
  20. data/lib/pg_export/lib/pg_export/listeners/interactive/encrypt_dump.rb +2 -2
  21. data/lib/pg_export/lib/pg_export/listeners/interactive/{fetch_dumps_from_ftp.rb → fetch_dumps.rb} +1 -1
  22. data/lib/pg_export/lib/pg_export/listeners/interactive/{open_ftp_connection.rb → open_connection.rb} +2 -2
  23. data/lib/pg_export/lib/pg_export/listeners/interactive/{remove_old_dumps_from_ftp.rb → remove_old_dumps.rb} +6 -6
  24. data/lib/pg_export/lib/pg_export/listeners/interactive/restore.rb +2 -2
  25. data/lib/pg_export/lib/pg_export/listeners/interactive/{upload_dump_to_ftp.rb → upload_dump.rb} +3 -3
  26. data/lib/pg_export/lib/pg_export/listeners/interactive_listener.rb +2 -2
  27. data/lib/pg_export/lib/pg_export/listeners/plain/build_dump.rb +2 -2
  28. data/lib/pg_export/lib/pg_export/listeners/plain/{close_ftp_connection.rb → close_connection.rb} +2 -2
  29. data/lib/pg_export/lib/pg_export/listeners/plain/decrypt_dump.rb +2 -2
  30. data/lib/pg_export/lib/pg_export/listeners/plain/{download_dump_from_ftp.rb → download_dump.rb} +3 -3
  31. data/lib/pg_export/lib/pg_export/listeners/plain/encrypt_dump.rb +2 -2
  32. data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps.rb +15 -0
  33. data/lib/pg_export/lib/pg_export/listeners/plain/open_connection.rb +15 -0
  34. data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps.rb +17 -0
  35. data/lib/pg_export/lib/pg_export/listeners/plain/restore.rb +1 -1
  36. data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump.rb +15 -0
  37. data/lib/pg_export/lib/pg_export/listeners/plain_listener.rb +2 -2
  38. data/lib/pg_export/lib/pg_export/operations/{open_ftp_connection.rb → open_connection.rb} +5 -5
  39. data/lib/pg_export/lib/pg_export/operations/{remove_old_dumps_from_ftp.rb → remove_old_dumps.rb} +7 -7
  40. data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_file_repository.rb → gateway_dump_file_repository.rb} +3 -3
  41. data/lib/pg_export/lib/pg_export/repositories/{ftp_dump_repository.rb → gateway_dump_repository.rb} +7 -7
  42. data/lib/pg_export/lib/pg_export/transactions/export_dump.rb +10 -10
  43. data/lib/pg_export/lib/pg_export/transactions/import_dump_interactively.rb +16 -16
  44. data/lib/pg_export/system/boot/config.rb +17 -1
  45. data/lib/pg_export/system/boot/ftp.rb +11 -0
  46. data/lib/pg_export/system/boot/interactive.rb +4 -10
  47. data/lib/pg_export/system/boot/operations.rb +17 -0
  48. data/lib/pg_export/system/boot/plain.rb +5 -11
  49. data/lib/pg_export/system/boot/ssh.rb +11 -0
  50. data/lib/pg_export/version.rb +1 -1
  51. data/pg_export.gemspec +10 -6
  52. metadata +98 -39
  53. data/lib/pg_export/build_logger.rb +0 -21
  54. data/lib/pg_export/lib/pg_export/factories/ftp_adapter_factory.rb +0 -22
  55. data/lib/pg_export/lib/pg_export/listeners/plain/fetch_dumps_from_ftp.rb +0 -15
  56. data/lib/pg_export/lib/pg_export/listeners/plain/open_ftp_connection.rb +0 -15
  57. data/lib/pg_export/lib/pg_export/listeners/plain/remove_old_dumps_from_ftp.rb +0 -17
  58. data/lib/pg_export/lib/pg_export/listeners/plain/upload_dump_to_ftp.rb +0 -15
  59. 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: cdfc6a58d21d779b24330b9fceeacebd4742a2aa04a13a2dd92510ad86a19d46
4
- data.tar.gz: e97bf165bd85f143516a04dbee83bb8953b8ac2bec6e2c839527e5ca178855bf
3
+ metadata.gz: d0f62f09db68ae3716d4ae83fea7780240cc66af83d7cbe813cd5d2e7bfae3e7
4
+ data.tar.gz: 0f80f6ad47217232ec83877f4bfc1b15c62a248e214229a9a6444bdecee61f44
5
5
  SHA512:
6
- metadata.gz: d4ba28ba8d124bc9638e40d8f711ca67bc92d82a8293d9f9c9d48681fea22f0c925d6baa96f57a4b7155f8ac0336fcd602b9218bfd6423227f49dfe6ea7f28be
7
- data.tar.gz: cc50c6604fb5d177766d64617cd5538a0ff9e144091b78e2e2db058d59f006b1c5b9660ce27615baa27fb6d66b5adf12365cc13d578a6a32ac8dc3de1d2ad4bd
6
+ metadata.gz: ecb017891a15fd94e15eef06972066655f13aeff22a4030ea840dc1ff2df6dd00451b2c7eb2e1dad248f95bc27b63d56cfe6275f675c0f2a2be6ab6f0ad7bdcd
7
+ data.tar.gz: e89de78f4a3a3d804f3ee82573fd97d03154a8f792f3e1a63a52f475798a091e96d0fc556e4dabbe8aa3c37497a7ae69c743a232e7bdd8a3a19d70547468df69
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .idea
data/.travis.yml CHANGED
@@ -1,9 +1,12 @@
1
- sudo: false
2
1
  language: ruby
3
2
  rvm:
4
- - 2.3.0
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 1.16.6
11
+ before_install: gem install bundler -v 2.2.3
9
12
  after_success: codeclimate-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
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
+
12
+ ### 0.7.7 - 2020.09.07
13
+
14
+ - Upgrade dry-initializer
15
+
1
16
  ### 0.7.6 - 2020.09.05
2
17
 
3
18
  - Upgrade dry-types, dry-struct dry-system
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
- -f, --ftp Tries connecting to FTP to verify the connection
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
- BACKUP_FTP_HOST=yourftp.example.com
71
- BACKUP_FTP_USER=user
72
- BACKUP_FTP_PASSWORD=password
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 shoul have exactly 16 characters. */
77
+ /* Encryption key should have exactly 16 characters. */
75
78
  /* Dumps will be SSL(AES-128-CBC) encrypted using this key. */
76
- DUMP_ENCRYPTION_KEY=1234567890abcdef
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
- => {:dump_encryption_key=>"k4***", :ftp_host=>"yourftp.example.com", :ftp_user=>"your_ftp_user",
88
- :ftp_password=>"pass***", :logger_format=>"plain", :keep_dumps=>2}
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,78 @@
4
4
  require 'optparse'
5
5
 
6
6
  require 'pg_export'
7
- require 'pg_export/container'
8
7
 
9
8
  ENV['KEEP_DUMPS'] = ENV['KEEP_DUMPS'] || '10'
10
- interactive = false
9
+ ENV['GATEWAY'] = 'ftp'
10
+ ENV['PG_EXPORT_MODE'] = 'plain'
11
+ ENV['PG_EXPORT_ENCRYPTION_ALGORITHM'] = 'AES-128-CBC'
12
+
11
13
  database = nil
12
14
 
13
15
  option_parser = OptionParser.new do |opts|
14
- opts.banner = 'Usage: pg_export [options]'
16
+ opts.banner = <<~TXT
17
+ NAME
18
+ pg_export - CLI for exporting/importing PostgreSQL dumps via FTP/SSH
19
+
20
+ SYNOPSIS (default mode)
21
+ pg_export DATABASE [options]
22
+
23
+ SYNOPSIS (interactive mode)
24
+ pg_export --interactive [DATABASE] [options]
15
25
 
16
- opts.on('-d', '--database DATABASE', String, '[Required] Name of the database to export') do |d|
26
+ ARGUMENTS
27
+ DATABASE - database name to export (when default mode)
28
+ - phrase to filter database dumps by (when interactive mode)
29
+
30
+ OPTIONS
31
+ TXT
32
+
33
+ opts.program_name = 'pg_export'
34
+ opts.version = PgExport::VERSION
35
+
36
+ opts.on('-g', '--gateway GATEWAY', %w[ftp ssh], 'Allowed values: ftp, ssh. Default: ftp. Credentials need to be set via ENVs') do |g|
37
+ ENV['GATEWAY'] = g
38
+ end
39
+
40
+ opts.on('-s', '--ssh', 'Same as "--gateway ssh"') do
41
+ ENV['GATEWAY'] = 'ssh'
42
+ end
43
+
44
+ opts.on('-f', '--ftp', 'Same as "--gateway ftp"') do
45
+ ENV['GATEWAY'] = 'ftp'
46
+ end
47
+
48
+ opts.on('-d', '--database DATABASE', String, 'Alternative way of specifying name of the database to export or phrase to filter by') do |d|
17
49
  database = d
18
50
  end
19
51
 
20
- opts.on('-k', '--keep [KEEP]', String, "[Optional] Number of dump files to keep on FTP (default: #{ENV['KEEP_DUMPS']})") do |keep|
52
+ 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|
53
+ ENV['PG_EXPORT_ENCRYPTION_KEY'] = key
54
+ end
55
+
56
+ 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|
57
+ ENV['PG_EXPORT_ENCRYPTION_KEY'] = key
58
+ end
59
+
60
+ opts.on('-k', '--keep KEEP', String, 'Number of dump files to keep on FTP (default: 10). Overwrites KEEP_DUMPS env') do |keep|
21
61
  ENV['KEEP_DUMPS'] = keep
22
62
  end
23
63
 
24
- opts.on('-t', '--timestamped', '[Optional] Enables log messages with timestamps') do
64
+ opts.on('-t', '--timestamped', 'Enables log messages with timestamps') do
25
65
  ENV['LOGGER_FORMAT'] = 'timestamped'
26
66
  end
27
67
 
28
- opts.on('-m', '--muted', '[Optional] Mutes log messages (overrides -t option)') do
68
+ opts.on('-m', '--muted', 'Mutes log messages (overrides -t option)') do
29
69
  ENV['LOGGER_FORMAT'] = 'muted'
30
70
  end
31
71
 
32
- opts.on('-i', '--interactive', '[Optional] Interactive command line mode - for restoring dumps into databases') do
33
- interactive = true
72
+ opts.on('-i', '--interactive', 'Interactive mode, for importing dumps') do
73
+ ENV['PG_EXPORT_MODE'] = 'interactive'
74
+ end
75
+
76
+ opts.on('-v', '--version', 'Show version') do
77
+ puts PgExport::VERSION
78
+ exit
34
79
  end
35
80
 
36
81
  opts.on('-h', '--help', 'Show this message') do
@@ -38,45 +83,65 @@ option_parser = OptionParser.new do |opts|
38
83
  exit
39
84
  end
40
85
 
41
- opts.separator "\nSetting can be verified by running following commands:"
86
+ opts.separator <<~TXT
87
+
88
+ ENV
89
+ PG_EXPORT_GATEWAY_HOST required
90
+ PG_EXPORT_GATEWAY_USER required
91
+ PG_EXPORT_GATEWAY_PASSWORD optional when eg. authorized key is added
92
+ PG_EXPORT_ENCRYPTION_KEY required or set by --encryption_key)
93
+ PG_EXPORT_ENCRYPTION_ALGORITHM required or set by --algorithm)
94
+ TXT
42
95
 
43
- opts.on('-c', '--configuration', 'Prints the configuration') do
96
+ opts.separator "\nTEST RUN"
97
+
98
+ opts.on('-c', '--configuration', 'Print the configuration') do
99
+ require 'pg_export/container'
44
100
  PgExport::Container.start(:config)
45
101
  puts PgExport::Container['config'].to_h
46
102
  exit
47
103
  end
48
104
 
49
- opts.on('-f', '--ftp', 'Tries connecting to FTP to verify the connection') do
50
- PgExport::Container.start(:ftp)
51
- ftp_adapter = PgExport::Container['factories.ftp_adapter_factory'].ftp_adapter
52
- ftp = ftp_adapter.open_ftp
53
- puts ftp.welcome
105
+ opts.on('-w', '--welcome', 'Try connecting to the gateway (FTP or SSH) to verify the connection') do
106
+ require 'pg_export/container'
107
+ PgExport::Container.start(ENV['GATEWAY'].to_sym)
108
+ gateway = PgExport::Container['factories.gateway_factory'].gateway
109
+ puts gateway.welcome
110
+ exit
111
+ end
112
+
113
+ if ARGV.empty?
114
+ puts opts
54
115
  exit
55
116
  end
56
117
  end
57
118
 
58
119
  begin
59
120
  option_parser.parse!
121
+ database = ARGV.first unless ARGV.empty?
60
122
  rescue OptionParser::ParseError => e
61
123
  warn e.message.capitalize
62
- warn 'Type "pg_export -h" for available options'
124
+ warn 'Details:'
125
+ warn option_parser.to_s.split("\n").grep(/ #{e.args.first}/).join("\n")
126
+ warn 'Type "pg_export" for available options'
63
127
  exit
64
128
  end
65
129
 
130
+ require 'pg_export/container'
131
+
66
132
  begin
67
- pg_export =
68
- if interactive
69
- PgExport.interactive
70
- else
71
- PgExport.plain
72
- end
133
+ pg_export = PgExport.boot
73
134
  rescue PgExport::InitializationError => e
74
135
  warn 'Unable to initialize PgExport due to invalid configuration. Check you ENVs.'
75
136
  warn "Detailed message: #{e.message}"
76
137
  exit
77
138
  end
78
139
 
79
- pg_export.call(database) do |result|
80
- result.success { puts 'Success' }
81
- result.failure { |message:| warn message }
140
+ begin
141
+ pg_export.call(database) do |result|
142
+ result.success { puts 'Success' }
143
+ result.failure { |outcome| warn outcome[:message] }
144
+ end
145
+ rescue Interrupt
146
+ puts
82
147
  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
- class << self
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
- def plain
15
- PgExport::Container.start(:plain)
16
- new(transaction: PgExport::Container['transactions.export_dump'])
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,25 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-types'
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
- include Dry::Types()
9
-
10
- attribute :dump_encryption_key, Strict::String.constrained(size: 16)
11
- attribute :ftp_host, Strict::String
12
- attribute :ftp_user, Strict::String
13
- attribute :ftp_password, Strict::String
14
- attribute :logger_format, Coercible::String.enum('plain', 'timestamped', 'muted')
15
- attribute :keep_dumps, Coercible::Integer.constrained(gteq: 0)
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::String.enum('plain', 'timestamped', 'muted')
14
+ attribute :keep_dumps, PgExport::Types::Coercible::Integer.constrained(gteq: 0)
16
15
 
17
16
  def self.build(env)
18
17
  new(
19
- dump_encryption_key: env['DUMP_ENCRYPTION_KEY'],
20
- ftp_host: env['BACKUP_FTP_HOST'],
21
- ftp_user: env['BACKUP_FTP_USER'],
22
- ftp_password: env['BACKUP_FTP_PASSWORD'],
18
+ encryption_key: env['PG_EXPORT_ENCRYPTION_KEY'],
19
+ encryption_algorithm: env['PG_EXPORT_ENCRYPTION_ALGORITHM'],
20
+ gateway_host: env['PG_EXPORT_GATEWAY_HOST'],
21
+ gateway_user: env['PG_EXPORT_GATEWAY_USER'],
22
+ gateway_password: env['PG_EXPORT_GATEWAY_PASSWORD'] == '' ? nil : env['PG_EXPORT_GATEWAY_PASSWORD'],
23
23
  logger_format: env['LOGGER_FORMAT'] || 'plain',
24
24
  keep_dumps: env['KEEP_DUMPS'] || 10
25
25
  )
@@ -27,6 +27,14 @@ class PgExport
27
27
  raise PgExport::InitializationError, e.message.gsub('[PgExport::Configuration.new] ', '')
28
28
  end
29
29
 
30
+ def gateway
31
+ ENV['GATEWAY'].to_sym
32
+ end
33
+
34
+ def mode
35
+ ENV['PG_EXPORT_MODE'].to_sym
36
+ end
37
+
30
38
  def logger_muted?
31
39
  logger_format == 'muted'
32
40
  end
@@ -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(:ftp) do
18
- init do
19
- require 'pg_export/lib/pg_export/factories/ftp_adapter_factory'
20
- end
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
@@ -3,5 +3,5 @@
3
3
  require_relative 'container'
4
4
 
5
5
  class PgExport
6
- Import = PgExport::Container.injector.hash
6
+ Import = PgExport::Container.injector
7
7
  end
@@ -9,23 +9,20 @@ class PgExport
9
9
  include Import['config']
10
10
 
11
11
  def encryptor
12
- cipher(:encrypt)
12
+ build_cipher(:encrypt)
13
13
  end
14
14
 
15
15
  def decryptor
16
- cipher(:decrypt)
16
+ build_cipher(:decrypt)
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- ALGORITHM = 'AES-128-CBC'
22
- private_constant :ALGORITHM
23
-
24
- def cipher(type)
25
- OpenSSL::Cipher.new(ALGORITHM).tap do |cipher|
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