glacier_on_rails 0.9.9 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e064638350da90807ab8f7c14b788295bbdba127
4
- data.tar.gz: 409fb6e65fd668c57265f8040f231e30a3c8f1a4
3
+ metadata.gz: 2c3545972de61ff80f578bb26a1e4d3df5b889e4
4
+ data.tar.gz: 707c970982ccdc1c57d22f2bcdf9710d9ec4159b
5
5
  SHA512:
6
- metadata.gz: f38b8ea5ed087142468409256cad1d3a448ce036a6a8950c4593ebc2a70533c18f12a06733b3b1fd69f487d31e96d06953f1f7412b01ac29d4db8fd1c41047f2
7
- data.tar.gz: 3618d038b088fdfb83bf6ea31fab36647bc4e96a8c5efac6836f167dc7c03578a77169a85ca9802c63becf8bcb1659b08a0ee7fb0a5ba14e8fa1a8606da397be
6
+ metadata.gz: 10246ae2a0d64d9b0df6bbf01bd90cbfd22392eda37f7a3f37ffcf1335de0decf8331a6155d19967fc9ecc794d9528db24e02c95a9311aa8ac801d56db594f77
7
+ data.tar.gz: 5bd6139d008f6c6cfa4417dbbb88b2758cb3bf2e3df5ea26726fdf10ec2daa3d6d40198ba732f8e3bef794408b7ffd542546b6414de97ffdaf4679f9b03a1e85
@@ -1,8 +1,14 @@
1
1
  class ApplicationDatabase
2
- class MissingConfigurationKeys < StandardError
2
+ class ConfigurationError < StandardError
3
+ def initialize(message)
4
+ AwsLog.error "#{self.class.name} exception: #{message}"
5
+ super
6
+ end
7
+ end
8
+
9
+ class MissingConfigurationKeys < ConfigurationError
3
10
  def initialize(missing_keys)
4
11
  message = "#{missing_keys.join(' and ')} must be specified in config/database.yml"
5
- AwsLog.error "ApplicationDatabase::MissingConfigurationKeys exception: #{message}"
6
12
  super(message)
7
13
  end
8
14
  end
@@ -17,6 +23,8 @@ class ApplicationDatabase
17
23
  when "mysql"
18
24
  MysqlAdapter.new(db_config)
19
25
  end
26
+ rescue ConfigurationError
27
+ @adapter = Struct.new(:contents).new(nil)
20
28
  end
21
29
 
22
30
  def db_config
@@ -2,20 +2,6 @@ class ApplicationDatabase::PostgresAdapter < ApplicationDatabase::BaseAdapter
2
2
  class PgDumpCmdMissing < StandardError; end
3
3
  class PgRestoreCmdMissing < StandardError; end
4
4
  class PgRestoreFileMissing < StandardError; end
5
- class PgPassFileMissing < StandardError
6
- def initialize
7
- message = "#{File.expand_path("~/.pgpass")} file not found, cannot dump database contents"
8
- AwsLog.error "ApplicationDatabase::PostgresAdapter::PgPassFileMissing exception: #{message}"
9
- super(message)
10
- end
11
- end
12
- class PgPassFilePermissionsError < StandardError
13
- def initialize
14
- message = "password file #{File.expand_path("~/.pgpass")} has group or world access; permissions should be u=rw (0600)"
15
- AwsLog.error "ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError exception: #{message}"
16
- super(message)
17
- end
18
- end
19
5
 
20
6
  RestoreExclusions = %w{ application_data_backups
21
7
  glacier_archives
@@ -24,12 +10,10 @@ class ApplicationDatabase::PostgresAdapter < ApplicationDatabase::BaseAdapter
24
10
  RestoreList = GlacierArchive::BackupFileDir.join('restore.list')
25
11
 
26
12
  def contents
27
- if db_config["password"].present?
28
- password_file = File.expand_path("~/.pgpass")
29
- raise PgPassFileMissing unless File.exists?(password_file)
30
- raise PgPassFilePermissionsError unless sprintf("%o", File.stat(password_file).mode) =~ /600$/
31
- end
13
+ PgPass.ensure if db_config["password"].present?
32
14
  `#{pg_dump} -w -Fc -U #{db_config['username']} #{db_config['database']}`
15
+ rescue ApplicationDatabase::ConfigurationError
16
+ nil
33
17
  end
34
18
 
35
19
  def restore(file)
@@ -11,12 +11,6 @@ class GlacierDbArchive < GlacierArchive
11
11
 
12
12
  def archive_contents
13
13
  ApplicationDatabase.new.contents
14
- rescue ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError
15
- nil
16
- rescue ApplicationDatabase::PostgresAdapter::PgPassFileMissing
17
- nil
18
- rescue ApplicationDatabase::MissingConfigurationKeys
19
- nil
20
14
  end
21
15
 
22
16
  # for file archive, true inhibits fetching archive from AWS
@@ -0,0 +1,24 @@
1
+ class PgPass
2
+
3
+ class FileMissing < ApplicationDatabase::ConfigurationError
4
+ def initialize
5
+ message = "#{File.expand_path("~/.pgpass")} file not found, cannot dump database contents"
6
+ super(message)
7
+ end
8
+ end
9
+
10
+ class FilePermissionsError < ApplicationDatabase::ConfigurationError
11
+ def initialize
12
+ message = "password file #{File.expand_path("~/.pgpass")} has group or world access; permissions should be u=rw (0600)"
13
+ super(message)
14
+ end
15
+ end
16
+
17
+ def self.ensure
18
+ # TODO missing file and permissions errors are recoverable
19
+ # create or chmod the file instead of triggering an exception
20
+ password_file = File.expand_path("~/.pgpass")
21
+ raise FileMissing unless File.exists?(password_file)
22
+ raise FilePermissionsError unless sprintf("%o", File.stat(password_file).mode) =~ /600$/
23
+ end
24
+ end
@@ -1,6 +1,6 @@
1
1
  class CreateGlacierArchivesTable < ActiveRecord::Migration[5.0]
2
2
  def change
3
- create_table :glacier_archives do |t|
3
+ create_table :glacier_archives, :force => true do |t|
4
4
  t.text :description
5
5
  t.text :archive_id
6
6
  t.text :checksum
@@ -1,6 +1,6 @@
1
1
  class CreateApplicationDataBackups < ActiveRecord::Migration[5.0]
2
2
  def change
3
- create_table :application_data_backups do |t|
3
+ create_table :application_data_backups, :force => true do |t|
4
4
  t.timestamps
5
5
  end
6
6
  end
@@ -1,5 +1,5 @@
1
1
  class CreateGlacierFileArchiveJoinTable < ActiveRecord::Migration[5.0]
2
2
  def change
3
- create_join_table :application_data_backups, :glacier_file_archives
3
+ create_join_table :application_data_backups, :glacier_file_archives, :force => true
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "glacier_on_rails"
6
- s.version = "0.9.9"
6
+ s.version = "1.0.0"
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
9
9
  s.authors = ["Les Nightingill"]
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
15
15
  s.rubygems_version = "2.1.11"
16
16
  s.summary = "database backup/restore utilities"
17
17
 
18
- s.add_runtime_dependency "rails", "~> 5.1"
18
+ s.add_runtime_dependency "rails", "~> 6.0.0rc1"
19
19
  s.add_runtime_dependency "httparty", "~> 0.15.5"
20
20
  s.add_development_dependency "byebug", "~> 9.0", ">= 9.0.6"
21
21
  s.add_development_dependency("capybara", "~> 2.4")
@@ -1,6 +1,7 @@
1
1
  namespace :aws do
2
2
  desc "create and save to aws glacier a copy of the postgres database"
3
3
  task :create_db_archive => :environment do
4
+ puts "#{Time.now} create db archive"
4
5
  ApplicationDataBackup.create
5
6
  end
6
7
  end
@@ -192,7 +192,7 @@ feature "backup_now", :js => true do
192
192
  expect{page.find('#backup_now').click; wait_for_ajax}.not_to change{ApplicationDataBackup.count}
193
193
  expect(page).not_to have_selector("#application_data_backups .application_data_backup")
194
194
  expect(flash_message).to eq "failed to create backup"
195
- expect(aws_log).to match /ApplicationDatabase::PostgresAdapter::PgPassFileMissing exception: #{File.expand_path("~/.pgpass")} file not found, cannot dump database contents/
195
+ expect(aws_log).to match /PgPass::FileMissing exception: #{File.expand_path("~/.pgpass")} file not found, cannot dump database contents/
196
196
  end
197
197
  end
198
198
 
@@ -215,7 +215,7 @@ feature "backup_now", :js => true do
215
215
  expect{page.find('#backup_now').click; wait_for_ajax}.not_to change{ApplicationDataBackup.count}
216
216
  expect(page).not_to have_selector("#application_data_backups .application_data_backup")
217
217
  expect(flash_message).to eq "failed to create backup"
218
- expect(aws_log).to match /#{Regexp.escape ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError.new.message}/
218
+ expect(aws_log).to match /#{Regexp.escape PgPass::FilePermissionsError.new.message}/
219
219
  end
220
220
  end
221
221
  end
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foo" do
4
+ it "bar" do
5
+ expect(1).to eq 0
6
+ end
7
+ end
@@ -28,8 +28,8 @@ describe "PostgresAdapter#contents dependence on password file ~/.pgpass" do
28
28
  allow(File).to receive(:exists?).with(File.expand_path("~/.pgpass")).and_return(false)
29
29
  end
30
30
 
31
- it "should raise an exception" do
32
- expect{ ApplicationDatabase.new.contents }.to raise_exception ApplicationDatabase::PostgresAdapter::PgPassFileMissing
31
+ it "should be nil" do
32
+ expect( ApplicationDatabase.new.contents ).to be_nil
33
33
  end
34
34
  end
35
35
 
@@ -58,8 +58,8 @@ describe "PostgresAdapter#contents dependence on password file ~/.pgpass" do
58
58
  allow(File).to receive(:stat).with(File.expand_path("~/.pgpass")).and_return(status)
59
59
  end
60
60
 
61
- it "should raise an exception" do
62
- expect{ ApplicationDatabase.new.contents }.to raise_exception ApplicationDatabase::PostgresAdapter::PgPassFilePermissionsError
61
+ it "should be nil" do
62
+ expect(ApplicationDatabase.new.contents).to be_nil
63
63
  end
64
64
  end
65
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glacier_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Les Nightingill
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '5.1'
19
+ version: 6.0.0rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '5.1'
26
+ version: 6.0.0rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: httparty
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +192,7 @@ files:
192
192
  - app/models/glacier_archive.rb
193
193
  - app/models/glacier_db_archive.rb
194
194
  - app/models/glacier_file_archive.rb
195
+ - app/models/pg_pass.rb
195
196
  - app/views/glacier_on_rails/aws_archive_retrieval_jobs/_application_data_backup.haml
196
197
  - app/views/glacier_on_rails/aws_archive_retrieval_jobs/_available.haml
197
198
  - app/views/glacier_on_rails/aws_archive_retrieval_jobs/_index.haml
@@ -267,6 +268,7 @@ files:
267
268
  - spec/models/application_file_spec.rb
268
269
  - spec/models/glacier_db_archive_spec.rb
269
270
  - spec/models/glacier_file_archive_spec.rb
271
+ - spec/models/pg_pass_spec.rb
270
272
  - spec/models/postgres_adapter_spec.rb
271
273
  - spec/rails_helper.rb
272
274
  - spec/spec_helper.rb