backup_qiniu 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e036a157e6b00c1b0de07ca3a90a283a63aeeecc
4
+ data.tar.gz: 3cbdbc7f6f54b93200b685d8c5ed5d340ee8bf4d
5
+ SHA512:
6
+ metadata.gz: b59e8d7e1e2df031d566a0137cf3ee94537d1f19de66d66f4884f1eee58abdb6f533473cc764b876ad8817f04f32546e423b435b6709b81f6736f8a9a918ff5c
7
+ data.tar.gz: 7d0fd0814271500100a6aeb1e636192914eb7f6ab42cb9729eba5a2de751576066aee34110b09cfa26d5da912d6e9efede8ddc85a37f48672d2229d5853e973e
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+
19
+ .idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in backup_qiniu.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'rspec'
8
+ end
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Haibin Yu
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/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Backup to Qiniu
2
+
3
+ 此 Gem 是 [Backup](https://github.com/meskyanichi/backup) 的辅助插件,目的是让 Backup 支持存储到 [Qiniu 云存储](http://qiniu.com)。
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'backup_qiniu'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install backup_qiniu
18
+
19
+ ## Usage
20
+
21
+ 你需要在你的 Backup models 文件里面单独引用 `backup_qiniu`,比如:
22
+
23
+ ~/Backup/models/foo.rb
24
+
25
+ ```ruby
26
+ require "backup_qiniu" # 引用 backup_qiniu
27
+
28
+ Backup::Model.new(:foo, 'Description for foo') do
29
+
30
+ # 配置 Qiniu 作为备份存储方式
31
+ store_with "Qiniu" do |qiniu|
32
+ qiniu.access_key_id = 'my_access_id'
33
+ qiniu.access_key_secret = 'my_access_key'
34
+ qiniu.bucket = 'bucket-name'
35
+ qiniu.path = '/path/to/my/backups'
36
+ qiniu.keep = 10
37
+ end
38
+ end
39
+ ```
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it
44
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
45
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
46
+ 4. Push to the branch (`git push origin my-new-feature`)
47
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "backup_qiniu"
7
+ spec.version = "0.1.0"
8
+ spec.authors = ["Haibin Yu"]
9
+ spec.email = ["seashineyu@gmail.com"]
10
+ spec.description = %q{Backup storage for supporting Qiniu cloud}
11
+ spec.summary = %q{backup storage for qiniu}
12
+ spec.homepage = "https://github.com/kevyu/backup_qiniu"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "backup", ">= 4.0.0"
21
+ spec.add_dependency "qiniu", ">= 6.2.0"
22
+
23
+ end
@@ -0,0 +1,58 @@
1
+ require 'qiniu'
2
+
3
+ module Backup
4
+ module Storage
5
+ class Qiniu < Base
6
+
7
+ attr_accessor :access_key, :access_key_secret, :bucket, :path
8
+
9
+ def initialize(model, storage_id = nil, &block)
10
+ super(model, storage_id)
11
+
12
+ @bucket ||= 'backups'
13
+ @path ||= ''
14
+
15
+ instance_eval(&block) if block_given?
16
+ end
17
+
18
+ def transfer!
19
+ remote_path = remote_path_for(package)
20
+ establish_connection!
21
+
22
+ package.filenames.each do |filename|
23
+ src = File.join(Config.tmp_path, filename)
24
+ dest = File.join(remote_path, filename)
25
+
26
+ Logger.info "#{storage_name} uploading '#{ dest }'..."
27
+ upload_token = ::Qiniu.generate_upload_token :scope => bucket
28
+ result = ::Qiniu.upload_file :uptoken => upload_token,
29
+ :file => src,
30
+ :bucket => bucket,
31
+ :key => dest
32
+ raise "#{storage_name} upload #{dest} failed" unless result
33
+ end
34
+
35
+ end
36
+
37
+ def remove!(package)
38
+ remote_path = remote_path_for(package)
39
+ establish_connection!
40
+
41
+ package.filenames.each do |filename|
42
+ dest = File.join(remote_path, filename)
43
+ raise "#{storage_name} delete #{remote_path} failed" unless ::Qiniu.delete(bucket, dest)
44
+ end
45
+
46
+ end
47
+
48
+ def establish_connection!
49
+ raise 'access_key is missing' if access_key.nil?
50
+ raise 'access_key_secret is missing' if access_key_secret.nil?
51
+ ::Qiniu.establish_connection! :access_key => access_key, :secret_key => access_key_secret
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+
58
+ end
@@ -0,0 +1,3 @@
1
+ require 'backup'
2
+
3
+ Backup::Storage.autoload(:Qiniu, File.join(File.dirname(__FILE__), 'backup/storage/qiniu'))
@@ -0,0 +1,43 @@
1
+ require File.expand_path('../spec_helper.rb', __FILE__)
2
+
3
+ describe Backup::Storage::Qiniu do
4
+
5
+ let(:model) { Backup::Model.new(:test_trigger, 'test backup') }
6
+ let(:storage) do
7
+ Backup::Storage::Qiniu.new(model) do |db|
8
+ db.access_key = 'my_access_key'
9
+ db.access_key_secret = 'my_access_key_secret'
10
+ db.bucket = 'test_bucket'
11
+ db.path = 'test_backup'
12
+ db.keep = 10
13
+ end
14
+ end
15
+
16
+ describe '#initialize' do
17
+
18
+ it 'should be a subclass of Storage::Base' do
19
+ Backup::Storage::Qiniu.superclass.should == Backup::Storage::Base
20
+ end
21
+
22
+ it 'should init with config' do
23
+ expect(storage.access_key).to eq('my_access_key')
24
+ expect(storage.access_key_secret).to eq('my_access_key_secret')
25
+ expect(storage.bucket).to eq('test_bucket')
26
+ expect(storage.path).to eq('test_backup')
27
+ expect(storage.keep).to eq(10)
28
+ end
29
+
30
+ it 'should use default config value if not given' do
31
+ storage = Backup::Storage::Qiniu.new(model)
32
+
33
+ expect(storage.access_key).to be_nil
34
+ expect(storage.access_key_secret).to be_nil
35
+ expect(storage.bucket).to eq('backups')
36
+ expect(storage.path).to eq('')
37
+ expect(storage.storage_id).to be_nil
38
+ expect(storage.keep).to be_nil
39
+
40
+ end
41
+
42
+ end
43
+ end
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ require 'backup'
3
+ require 'backup_qiniu'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.treat_symbols_as_metadata_keys_with_true_values = true
8
+ config.run_all_when_everything_filtered = true
9
+ config.filter_run :focus
10
+
11
+ config.order = 'random'
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backup_qiniu
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Haibin Yu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: backup
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: qiniu
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 6.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 6.2.0
41
+ description: Backup storage for supporting Qiniu cloud
42
+ email:
43
+ - seashineyu@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - backup_qiniu.gemspec
55
+ - lib/backup/storage/qiniu.rb
56
+ - lib/backup_qiniu.rb
57
+ - spec/qiniu_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: https://github.com/kevyu/backup_qiniu
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.2.0.rc.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: backup storage for qiniu
83
+ test_files:
84
+ - spec/qiniu_spec.rb
85
+ - spec/spec_helper.rb