webtranslateit-safe 0.4.1 → 0.4.3

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.
data/Gemfile DELETED
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in webtranslateit-safe.gemspec
4
- gemspec
5
-
6
- gem 'awesome_print'
7
- gem 'rake'
8
- gem 'rr', '~> 1.0.4'
9
- gem 'rspec'
10
- gem 'rubocop'
11
- gem 'rubocop-rspec'
data/Gemfile.lock DELETED
@@ -1,89 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- webtranslateit-safe (0.4.1)
5
- aws-s3
6
- cloudfiles
7
- net-sftp
8
-
9
- GEM
10
- remote: https://rubygems.org/
11
- specs:
12
- ast (2.4.2)
13
- awesome_print (1.9.2)
14
- aws-s3 (0.6.3)
15
- builder
16
- mime-types
17
- xml-simple
18
- builder (3.2.4)
19
- cloudfiles (1.5.0.3)
20
- json
21
- diff-lcs (1.5.0)
22
- json (2.6.3)
23
- mime-types (3.4.1)
24
- mime-types-data (~> 3.2015)
25
- mime-types-data (3.2023.0218.1)
26
- net-sftp (4.0.0)
27
- net-ssh (>= 5.0.0, < 8.0.0)
28
- net-ssh (7.1.0)
29
- parallel (1.23.0)
30
- parser (3.2.2.1)
31
- ast (~> 2.4.1)
32
- rainbow (3.1.1)
33
- rake (13.0.6)
34
- regexp_parser (2.8.0)
35
- rexml (3.2.5)
36
- rr (1.0.5)
37
- rspec (3.12.0)
38
- rspec-core (~> 3.12.0)
39
- rspec-expectations (~> 3.12.0)
40
- rspec-mocks (~> 3.12.0)
41
- rspec-core (3.12.2)
42
- rspec-support (~> 3.12.0)
43
- rspec-expectations (3.12.3)
44
- diff-lcs (>= 1.2.0, < 2.0)
45
- rspec-support (~> 3.12.0)
46
- rspec-mocks (3.12.5)
47
- diff-lcs (>= 1.2.0, < 2.0)
48
- rspec-support (~> 3.12.0)
49
- rspec-support (3.12.0)
50
- rubocop (1.51.0)
51
- json (~> 2.3)
52
- parallel (~> 1.10)
53
- parser (>= 3.2.0.0)
54
- rainbow (>= 2.2.2, < 4.0)
55
- regexp_parser (>= 1.8, < 3.0)
56
- rexml (>= 3.2.5, < 4.0)
57
- rubocop-ast (>= 1.28.0, < 2.0)
58
- ruby-progressbar (~> 1.7)
59
- unicode-display_width (>= 2.4.0, < 3.0)
60
- rubocop-ast (1.28.1)
61
- parser (>= 3.2.1.0)
62
- rubocop-capybara (2.18.0)
63
- rubocop (~> 1.41)
64
- rubocop-factory_bot (2.23.1)
65
- rubocop (~> 1.33)
66
- rubocop-rspec (2.22.0)
67
- rubocop (~> 1.33)
68
- rubocop-capybara (~> 2.17)
69
- rubocop-factory_bot (~> 2.22)
70
- ruby-progressbar (1.13.0)
71
- unicode-display_width (2.4.2)
72
- xml-simple (1.1.9)
73
- rexml
74
-
75
- PLATFORMS
76
- arm64-darwin-22
77
- x86_64-linux
78
-
79
- DEPENDENCIES
80
- awesome_print
81
- rake
82
- rr (~> 1.0.4)
83
- rspec
84
- rubocop
85
- rubocop-rspec
86
- webtranslateit-safe!
87
-
88
- BUNDLED WITH
89
- 2.4.13
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2010-2013 Astrails Ltd.
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require 'bundler/gem_tasks'
2
-
3
- require 'rspec/core/rake_task'
4
-
5
- desc 'run specs'
6
- RSpec::Core::RakeTask.new
7
-
8
- task default: :spec
data/TODO DELETED
@@ -1,31 +0,0 @@
1
- - refactor
2
- - refactor out global variables. pass a config object around instead
3
- - common logging
4
- - remove 1.8.6 support
5
- - module registry
6
- - base => prefix ?
7
- - move requires into specific modules
8
- - config.foo instead of config[:foo]
9
-
10
- - features
11
- - remote-only s3 support
12
- - generic notifier support
13
- - email notifier
14
- - hipchat
15
- - generic error notifier support
16
- - email
17
- - hipchat
18
-
19
-
20
-
21
- - add 'silent'
22
- - handle errors from mysqldump
23
- - check that gpg is installed
24
- - support percona XtraBackup as an option instead of mysqldump [patches anyone :) ?]
25
- - backup validation:
26
- - support for 'minsize' opition in backup that will check that produced backup is at least the expected size
27
- this should catch many backup failure scenarious (like broken mysql connection, insufficient disk space etc.
28
- - support differencial backups
29
- - it should be fairly easy for filesystem backups using tar's built in incremental functionality.
30
- - for mysql need to use XtraBackup
31
- - or we can keep the previous dump locally and store only diff with the latest dump
@@ -1,5 +0,0 @@
1
- module WebTranslateIt
2
- module Safe
3
- VERSION = '0.4.1'
4
- end
5
- end
@@ -1,89 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'fileutils'
4
- include FileUtils
5
-
6
- describe 'tar backup' do
7
- before(:all) do
8
- # need both local and instance vars
9
- # instance variables are used in tests
10
- # local variables are used in the backup definition (instance vars can't be seen)
11
- @root = root = 'tmp/archive_backup_example'
12
-
13
- # clean state
14
- rm_rf @root
15
- mkdir_p @root
16
-
17
- # create source tree
18
- @src = src = "#{@root}/src"
19
- mkdir_p "#{@src}/q/w/e"
20
- mkdir_p "#{@src}/a/s/d"
21
-
22
- File.open("#{@src}/qwe1", 'w') {|f| f.write('qwe') }
23
- File.open("#{@src}/q/qwe2", 'w') {|f| f.write('qwe'*2) }
24
- File.open("#{@src}/q/w/qwe3", 'w') {|f| f.write('qwe'*3) }
25
- File.open("#{@src}/q/w/e/qwe4", 'w') {|f| f.write('qwe'*4) }
26
-
27
- File.open("#{@src}/asd1", 'w') {|f| f.write('asd') }
28
- File.open("#{@src}/a/asd2", 'w') {|f| f.write('asd' * 2) }
29
- File.open("#{@src}/a/s/asd3", 'w') {|f| f.write('asd' * 3) }
30
-
31
- @dst = dst = "#{@root}/backup"
32
- mkdir_p @dst
33
-
34
- @now = Time.now
35
- @timestamp = @now.strftime('%y%m%d-%H%M')
36
-
37
- stub(Time).now {@now} # Freeze
38
-
39
- config = WebTranslateIt::Safe.safe do
40
- local :path => "#{dst}/:kind"
41
- tar do
42
- archive :test1 do
43
- files src
44
- exclude "#{src}/q/w"
45
- exclude "#{src}/q/w/e"
46
- end
47
- end
48
- end
49
- WebTranslateIt::Safe.process config
50
-
51
- @backup = "#{dst}/archive/archive-test1.#{@timestamp}.tar.gz"
52
- end
53
-
54
- it 'should create backup file' do
55
- File.exist?(@backup).should be true
56
- end
57
-
58
- describe 'after extracting' do
59
- before(:all) do
60
- # prepare target dir
61
- @target = "#{@root}/test"
62
- mkdir_p @target
63
- system "tar -zxvf #{@backup} -C #{@target}"
64
-
65
- @test = "#{@target}/#{@root}/src"
66
- puts @test
67
- end
68
-
69
- it 'should include asd1/2/3' do
70
- File.exist?("#{@test}/asd1").should be true
71
- File.exist?("#{@test}/a/asd2").should be true
72
- File.exist?("#{@test}/a/s/asd3").should be true
73
- end
74
-
75
- it 'should only include qwe 1 and 2 (no 3)' do
76
- File.exist?("#{@test}/qwe1").should be true
77
- File.exist?("#{@test}/q/qwe2").should be true
78
- File.exist?("#{@test}/q/w/qwe3").should be false
79
- File.exist?("#{@test}/q/w/e/qwe4").should be false
80
- end
81
-
82
- it 'should preserve file content' do
83
- File.read("#{@test}/qwe1").should == 'qwe'
84
- File.read("#{@test}/q/qwe2").should == 'qweqwe'
85
- File.read("#{@test}/a/s/asd3").should == 'asdasdasd'
86
- end
87
- end
88
-
89
- end
@@ -1,62 +0,0 @@
1
- require 'spec_helper'
2
-
3
- require 'fileutils'
4
- include FileUtils
5
-
6
- describe 'tar backup' do
7
- before(:all) do
8
- # need both local and instance vars
9
- # instance variables are used in tests
10
- # local variables are used in the backup definition (instance vars can't be seen)
11
- @root = root = 'tmp/cleanup_example'
12
-
13
- # clean state
14
- rm_rf @root
15
- mkdir_p @root
16
-
17
- # create source tree
18
- @src = src = "#{@root}/src"
19
- mkdir_p src
20
-
21
- File.open(qwe = "#{@src}/qwe", 'w') {|f| f.write('qwe') }
22
-
23
- @dst = dst = "#{@root}/backup"
24
- mkdir_p "#{@dst}/archive"
25
-
26
- @now = Time.now
27
- @timestamp = @now.strftime('%y%m%d-%H%M')
28
-
29
- stub(Time).now {@now} # Freeze
30
-
31
- cp qwe, "#{dst}/archive/archive-foo.000001.tar.gz"
32
- cp qwe, "#{dst}/archive/archive-foo.000002.tar.gz"
33
- cp qwe, "#{dst}/archive/archive-foobar.000001.tar.gz"
34
- cp qwe, "#{dst}/archive/archive-foobar.000002.tar.gz"
35
-
36
- config = WebTranslateIt::Safe.safe do
37
- local :path => "#{dst}/:kind"
38
- tar do
39
- keep :local => 1 # only leave the latest
40
- archive :foo do
41
- files src
42
- end
43
- end
44
- end
45
- WebTranslateIt::Safe.process config
46
-
47
- @backup = "#{dst}/archive/archive-foo.#{@timestamp}.tar.gz"
48
- end
49
-
50
- it 'should create backup file' do
51
- File.exist?(@backup).should be true
52
- end
53
-
54
- it 'should remove old backups' do
55
- Dir["#{@dst}/archive/archive-foo.*"].should == [@backup]
56
- end
57
-
58
- it 'should NOT remove backups with base having same prefix' do
59
- Dir["#{@dst}/archive/archive-foobar.*"].sort.should == ["#{@dst}/archive/archive-foobar.000001.tar.gz", "#{@dst}/archive/archive-foobar.000002.tar.gz"]
60
- end
61
-
62
- end
data/spec/spec_helper.rb DELETED
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'webtranslateit/safe'
4
-
5
- RSpec.configure do |config|
6
- config.mock_with :rr
7
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WebTranslateIt::Safe::Archive do
4
-
5
- def def_config
6
- {
7
- :options => 'OPTS',
8
- :files => 'apples',
9
- :exclude => 'oranges'
10
- }
11
- end
12
-
13
- def archive(id = :foo, config = def_config)
14
- WebTranslateIt::Safe::Archive.new(id, WebTranslateIt::Safe::Config::Node.new(nil, config))
15
- end
16
-
17
- after(:each) { WebTranslateIt::Safe::TmpFile.cleanup }
18
-
19
- describe :backup do
20
- before(:each) do
21
- @archive = archive
22
- stub(@archive).timestamp {'NOW'}
23
- end
24
-
25
- {
26
- :id => 'foo',
27
- :kind => 'archive',
28
- :extension => '.tar',
29
- :filename => 'archive-foo.NOW',
30
- :command => 'tar -cf - OPTS --exclude=oranges apples',
31
- }.each do |k, v|
32
- it "should set #{k} to #{v}" do
33
- @archive.backup.send(k).should == v
34
- end
35
- end
36
- end
37
-
38
- describe :tar_exclude_files do
39
- it "should return '' when no excludes" do
40
- archive(:foo, {}).send(:tar_exclude_files).should == ''
41
- end
42
-
43
- it 'should accept single exclude as string' do
44
- archive(:foo, {:exclude => 'bar'}).send(:tar_exclude_files).should == '--exclude=bar'
45
- end
46
-
47
- it 'should accept multiple exclude as array' do
48
- archive(:foo, {:exclude => ['foo', 'bar']}).send(:tar_exclude_files).should == '--exclude=foo --exclude=bar'
49
- end
50
- end
51
-
52
- describe :tar_files do
53
- it 'should raise RuntimeError when no files' do
54
- lambda {
55
- archive(:foo, {}).send(:tar_files)
56
- }.should raise_error(RuntimeError, 'missing files for tar')
57
- end
58
-
59
- it 'should accept single file as string' do
60
- archive(:foo, {:files => 'foo'}).send(:tar_files).should == 'foo'
61
- end
62
-
63
- it 'should accept multiple files as array' do
64
- archive(:foo, {:files => ['foo', 'bar']}).send(:tar_files).should == 'foo bar'
65
- end
66
- end
67
- end
@@ -1,175 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe WebTranslateIt::Safe::Cloudfiles do
4
-
5
- def def_config
6
- {
7
- cloudfiles: {
8
- container: '_container',
9
- user: '_user',
10
- api_key: '_api_key',
11
- },
12
- keep: { cloudfiles: 2 }
13
- }
14
- end
15
-
16
- def def_backup(extra = {})
17
- {
18
- kind: '_kind',
19
- filename: '/backup/somewhere/_kind-_id.NOW.bar',
20
- extension: '.bar',
21
- id: '_id',
22
- timestamp: 'NOW'
23
- }.merge(extra)
24
- end
25
-
26
- def cloudfiles(config = def_config, backup = def_backup)
27
- WebTranslateIt::Safe::Cloudfiles.new(
28
- WebTranslateIt::Safe::Config::Node.new.merge(config),
29
- WebTranslateIt::Safe::Backup.new(backup)
30
- )
31
- end
32
-
33
- describe :cleanup do
34
-
35
- before(:each) do
36
- @cloudfiles = cloudfiles
37
-
38
- @files = [4,1,3,2].map { |i| "aaaaa#{i}" }
39
-
40
- @container = 'container'
41
-
42
- stub(@container).objects(prefix: '_kind/_id/_kind-_id.') { @files }
43
- stub(@container).delete_object(anything)
44
-
45
- stub(CloudFiles::Connection).
46
- new('_user', '_api_key', true, false).stub!.
47
- container('_container') {@container}
48
- end
49
-
50
- it 'should check [:keep, :cloudfiles]' do
51
- @cloudfiles.config[:keep].data['cloudfiles'] = nil
52
- dont_allow(@cloudfiles.backup).filename
53
- @cloudfiles.send :cleanup
54
- end
55
-
56
- it 'should delete extra files' do
57
- mock(@container).delete_object('aaaaa1')
58
- mock(@container).delete_object('aaaaa2')
59
- @cloudfiles.send :cleanup
60
- end
61
-
62
- end
63
-
64
- describe :active do
65
- before(:each) do
66
- @cloudfiles = cloudfiles
67
- end
68
-
69
- it 'should be true when all params are set' do
70
- expect(@cloudfiles.active?).to be_truthy
71
- end
72
-
73
- it 'should be false if container is missing' do
74
- @cloudfiles.config[:cloudfiles].data['container'] = nil
75
- expect(@cloudfiles.active?).to be_falsy
76
- end
77
-
78
- it 'should be false if user is missing' do
79
- @cloudfiles.config[:cloudfiles].data['user'] = nil
80
- expect(@cloudfiles.active?).to be_falsy
81
- end
82
-
83
- it 'should be false if api_key is missing' do
84
- @cloudfiles.config[:cloudfiles].data['api_key'] = nil
85
- expect(@cloudfiles.active?).to be_falsy
86
- end
87
- end
88
-
89
- describe :path do
90
- before(:each) do
91
- @cloudfiles = cloudfiles
92
- end
93
- it 'should use cloudfiles/path 1st' do
94
- @cloudfiles.config[:cloudfiles].data['path'] = 'cloudfiles_path'
95
- @cloudfiles.config[:local] = {path: 'local_path'}
96
- @cloudfiles.send(:path).should == 'cloudfiles_path'
97
- end
98
-
99
- it 'should use local/path 2nd' do
100
- @cloudfiles.config.merge local: {path: 'local_path'}
101
- @cloudfiles.send(:path).should == 'local_path'
102
- end
103
-
104
- it 'should use constant 3rd' do
105
- @cloudfiles.send(:path).should == '_kind/_id'
106
- end
107
-
108
- end
109
-
110
- describe :save do
111
- def add_stubs(*stubs)
112
- stubs.each do |s|
113
- case s
114
- when :connection
115
- @connection = 'connection'
116
- stub(CloudFiles::Authentication).new
117
- stub(CloudFiles::Connection).
118
- new('_user', '_api_key', true, false) {@connection}
119
- when :file_size
120
- stub(@cloudfiles).get_file_size('foo') {123}
121
- when :create_container
122
- @container = 'container'
123
- stub(@container).create_object('_kind/_id/backup/somewhere/_kind-_id.NOW.bar.bar', true) {@object}
124
- stub(@connection).create_container {@container}
125
- when :file_open
126
- stub(File).open('foo')
127
- when :cloudfiles_store
128
- @object = 'object'
129
- stub(@object).write(nil) {true}
130
- end
131
- end
132
- end
133
-
134
- before(:each) do
135
- @cloudfiles = cloudfiles(def_config, def_backup(path: 'foo'))
136
- @full_path = '_kind/_id/backup/somewhere/_kind-_id.NOW.bar.bar'
137
- end
138
-
139
- it 'should fail if no backup.file is set' do
140
- @cloudfiles.backup.path = nil
141
- proc {@cloudfiles.send(:save)}.should raise_error(RuntimeError)
142
- end
143
-
144
- it 'should establish Cloud Files connection' do
145
- add_stubs(:connection, :file_size, :create_container, :file_open, :cloudfiles_store)
146
- @cloudfiles.send(:save)
147
- end
148
-
149
- it 'should open local file' do
150
- add_stubs(:connection, :file_size, :create_container, :cloudfiles_store)
151
- mock(File).open('foo')
152
- @cloudfiles.send(:save)
153
- end
154
-
155
- it "should call write on the cloudfile object with files' descriptor" do
156
- add_stubs(:connection, :file_size, :create_container, :cloudfiles_store)
157
- stub(File).open('foo') {'qqq'}
158
- mock(@object).write('qqq') {true}
159
- @cloudfiles.send(:save)
160
- end
161
-
162
- it 'should upload file' do
163
- add_stubs(:connection, :file_size, :create_container, :file_open, :cloudfiles_store)
164
- @cloudfiles.send(:save)
165
- end
166
-
167
- it 'should fail on files bigger then 5G' do
168
- add_stubs(:connection)
169
- mock(File).stat('foo').stub!.size {5*1024*1024*1024+1}
170
- mock(STDERR).puts(anything)
171
- dont_allow(Benchmark).realtime
172
- @cloudfiles.send(:save)
173
- end
174
- end
175
- end