pg_export 1.0.0.rc6 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +23 -2
  3. data/CHANGELOG.md +6 -3
  4. data/README.md +43 -34
  5. data/bin/pg_export +13 -131
  6. data/bin/setup +0 -2
  7. data/lib/pg_export/commands_factory.rb +158 -0
  8. data/lib/pg_export/configuration.rb +15 -16
  9. data/lib/pg_export/configuration_parser.rb +126 -0
  10. data/lib/pg_export/{lib/pg_export/factories → factories}/dump_factory.rb +1 -1
  11. data/lib/pg_export/{lib/pg_export/factories → factories}/ftp_gateway_factory.rb +1 -1
  12. data/lib/pg_export/{lib/pg_export/repositories/gateway_dump_file_repository.rb → factories/gateway_dump_file_factory.rb} +4 -4
  13. data/lib/pg_export/{lib/pg_export/factories → factories}/ssh_gateway_factory.rb +1 -1
  14. data/lib/pg_export/{lib/pg_export/operations → operations}/decrypt_dump.rb +1 -1
  15. data/lib/pg_export/{lib/pg_export/operations → operations}/encrypt_dump.rb +1 -1
  16. data/lib/pg_export/{lib/pg_export/operations → operations}/open_connection.rb +1 -1
  17. data/lib/pg_export/{lib/pg_export/operations → operations}/remove_old_dumps.rb +1 -1
  18. data/lib/pg_export/{lib/pg_export/repositories → repositories}/gateway_dump_repository.rb +2 -2
  19. data/lib/pg_export/{lib/pg_export/transactions → transactions}/export_dump.rb +10 -10
  20. data/lib/pg_export/{lib/pg_export/transactions → transactions}/import_dump_interactively.rb +19 -10
  21. data/lib/pg_export/{lib/pg_export/value_objects → value_objects}/result.rb +1 -1
  22. data/lib/pg_export/version.rb +1 -1
  23. data/lib/pg_export.rb +12 -14
  24. data/pg_export.gemspec +1 -3
  25. metadata +52 -51
  26. data/lib/pg_export/factory.rb +0 -148
  27. /data/lib/pg_export/{lib/pg_export/adapters → adapters}/shell_adapter.rb +0 -0
  28. /data/lib/pg_export/{lib/pg_export/entities → entities}/dump.rb +0 -0
  29. /data/lib/pg_export/{lib/pg_export/factories → factories}/cipher_factory.rb +0 -0
  30. /data/lib/pg_export/{lib/pg_export/gateways → gateways}/ftp.rb +0 -0
  31. /data/lib/pg_export/{lib/pg_export/gateways → gateways}/ssh.rb +0 -0
  32. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/build_dump.rb +0 -0
  33. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/close_connection.rb +0 -0
  34. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/decrypt_dump.rb +0 -0
  35. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/download_dump.rb +0 -0
  36. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/encrypt_dump.rb +0 -0
  37. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/fetch_dumps.rb +0 -0
  38. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/open_connection.rb +0 -0
  39. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/remove_old_dumps.rb +0 -0
  40. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/restore.rb +0 -0
  41. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/select_database.rb +0 -0
  42. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/select_dump.rb +0 -0
  43. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive/upload_dump.rb +0 -0
  44. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/interactive_listener.rb +0 -0
  45. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/build_dump.rb +0 -0
  46. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/close_connection.rb +0 -0
  47. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/decrypt_dump.rb +0 -0
  48. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/download_dump.rb +0 -0
  49. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/encrypt_dump.rb +0 -0
  50. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/fetch_dumps.rb +0 -0
  51. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/open_connection.rb +0 -0
  52. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/prepare_params.rb +0 -0
  53. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/remove_old_dumps.rb +0 -0
  54. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/restore.rb +0 -0
  55. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain/upload_dump.rb +0 -0
  56. /data/lib/pg_export/{lib/pg_export/listeners → listeners}/plain_listener.rb +0 -0
  57. /data/lib/pg_export/{lib/pg_export/transactions → transactions}/evaluator.rb +0 -0
  58. /data/lib/pg_export/{lib/pg_export/ui → ui}/interactive/input.rb +0 -0
  59. /data/lib/pg_export/{lib/pg_export/ui → ui}/plain/input.rb +0 -0
  60. /data/lib/pg_export/{lib/pg_export/value_objects → value_objects}/dump_file.rb +0 -0
@@ -1,148 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class PgExport
4
- class Factory
5
- attr_reader :config
6
-
7
- def initialize(config:)
8
- @config = config
9
- end
10
-
11
- def gateway_factory
12
- if config.gateway == :ftp
13
- require 'pg_export/lib/pg_export/factories/ftp_gateway_factory'
14
-
15
- Factories::FtpGatewayFactory.new(config: config)
16
- elsif config.gateway == :ssh
17
- require 'pg_export/lib/pg_export/factories/ssh_gateway_factory'
18
-
19
- Factories::SshGatewayFactory.new(config: config)
20
- else
21
- raise ArgumentError, "Unknown gateway #{config.gateway}"
22
- end
23
- end
24
-
25
- def transaction
26
- require 'pg_export/lib/pg_export/operations/encrypt_dump'
27
- require 'pg_export/lib/pg_export/operations/decrypt_dump'
28
- require 'pg_export/lib/pg_export/operations/open_connection'
29
- require 'pg_export/lib/pg_export/factories/cipher_factory'
30
- require 'pg_export/lib/pg_export/factories/dump_factory'
31
- require 'pg_export/lib/pg_export/adapters/shell_adapter'
32
- require 'pg_export/lib/pg_export/repositories/gateway_dump_repository'
33
- require 'pg_export/lib/pg_export/repositories/gateway_dump_file_repository'
34
-
35
- cipher_factory = Factories::CipherFactory.new(
36
- encryption_algorithm: config.encryption_algorithm,
37
- encryption_key: config.encryption_key
38
- )
39
-
40
- gateway_dump_repository = Repositories::GatewayDumpRepository.new
41
- gateway_dump_file_repository = Repositories::GatewayDumpFileRepository.new
42
- open_connection = Operations::OpenConnection.new(gateway_factory: gateway_factory)
43
- bash_adapter = Adapters::ShellAdapter.new
44
-
45
- encrypt_dump = Operations::EncryptDump.new(cipher_factory: cipher_factory)
46
-
47
- if config.mode == :plain
48
- require 'pg_export/lib/pg_export/operations/remove_old_dumps'
49
- require 'pg_export/lib/pg_export/transactions/export_dump'
50
-
51
- remove_old_dumps = Operations::RemoveOldDumps.new(
52
- gateway_dump_repository: gateway_dump_repository,
53
- keep: config.keep_dumps
54
- )
55
-
56
- PgExport::Transactions::ExportDump.new(
57
- dump_factory: Factories::DumpFactory.new,
58
- bash_adapter: bash_adapter,
59
- encrypt_dump: encrypt_dump,
60
- open_connection: open_connection,
61
- remove_old_dumps: remove_old_dumps,
62
- listeners: plain_listeners
63
- )
64
- elsif config.mode == :interactive
65
- require 'pg_export/lib/pg_export/transactions/import_dump_interactively'
66
- require 'pg_export/lib/pg_export/ui/interactive/input'
67
-
68
- decrypt_dump = Operations::DecryptDump.new(cipher_factory: cipher_factory)
69
-
70
- PgExport::Transactions::ImportDumpInteractively.new(
71
- input: Ui::Interactive::Input.new,
72
- bash_adapter: bash_adapter,
73
- gateway_dump_file_repository: gateway_dump_file_repository,
74
- gateway_dump_repository: gateway_dump_repository,
75
- open_connection: open_connection,
76
- decrypt_dump: decrypt_dump,
77
- listeners: interactive_listeners
78
- )
79
- else
80
- raise ArgumentError, "Unknown mode #{config.mode}"
81
- end
82
- end
83
-
84
- private
85
-
86
- def plain_listeners
87
- require 'pg_export/lib/pg_export/listeners/plain/prepare_params'
88
- require 'pg_export/lib/pg_export/listeners/plain/build_dump'
89
- require 'pg_export/lib/pg_export/listeners/plain/close_connection'
90
- require 'pg_export/lib/pg_export/listeners/plain/decrypt_dump'
91
- require 'pg_export/lib/pg_export/listeners/plain/download_dump'
92
- require 'pg_export/lib/pg_export/listeners/plain/encrypt_dump'
93
- require 'pg_export/lib/pg_export/listeners/plain/fetch_dumps'
94
- require 'pg_export/lib/pg_export/listeners/plain/open_connection'
95
- require 'pg_export/lib/pg_export/listeners/plain/remove_old_dumps'
96
- require 'pg_export/lib/pg_export/listeners/plain/restore'
97
- require 'pg_export/lib/pg_export/listeners/plain/upload_dump'
98
-
99
- logger = build_logger(config.logger_format)
100
-
101
- {
102
- prepare_params: Listeners::Plain::PrepareParams.new(logger: logger),
103
- build_dump: Listeners::Plain::BuildDump.new(logger: logger),
104
- encrypt_dump: Listeners::Plain::EncryptDump.new(logger: logger),
105
- open_connection: Listeners::Plain::OpenConnection.new(logger: logger),
106
- upload_dump: Listeners::Plain::UploadDump.new(logger: logger),
107
- remove_old_dumps: Listeners::Plain::RemoveOldDumps.new(logger: logger),
108
- close_connection: Listeners::Plain::CloseConnection.new(logger: logger)
109
- }
110
- end
111
-
112
- def interactive_listeners
113
- require 'pg_export/lib/pg_export/listeners/interactive/open_connection'
114
- require 'pg_export/lib/pg_export/listeners/interactive/fetch_dumps'
115
- require 'pg_export/lib/pg_export/listeners/interactive/select_dump'
116
- require 'pg_export/lib/pg_export/listeners/interactive/download_dump'
117
- require 'pg_export/lib/pg_export/listeners/interactive/close_connection'
118
- require 'pg_export/lib/pg_export/listeners/interactive/decrypt_dump'
119
- require 'pg_export/lib/pg_export/listeners/interactive/select_database'
120
- require 'pg_export/lib/pg_export/listeners/interactive/restore'
121
-
122
- {
123
- open_connection: Listeners::Interactive::OpenConnection.new,
124
- fetch_dumps: Listeners::Interactive::FetchDumps.new,
125
- select_dump: Listeners::Interactive::SelectDump.new,
126
- download_dump: Listeners::Interactive::DownloadDump.new,
127
- close_connection: Listeners::Interactive::CloseConnection.new,
128
- decrypt_dump: Listeners::Interactive::DecryptDump.new,
129
- select_database: Listeners::Interactive::SelectDatabase.new,
130
- restore: Listeners::Interactive::Restore.new,
131
- }
132
- end
133
-
134
- def build_logger(logger_format)
135
- require 'logger'
136
-
137
- formatters = {
138
- plain: ->(_, _, _, message) { "#{message}\n" },
139
- muted: ->(*) {},
140
- timestamped: lambda do |severity, datetime, progname, message|
141
- "#{datetime} #{Process.pid} TID-#{Thread.current.object_id.to_s(36)}#{progname} #{severity}: #{message}\n"
142
- end
143
- }
144
-
145
- Logger.new($stdout, formatter: formatters.fetch(logger_format))
146
- end
147
- end
148
- end