qiniu-policy 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bee70f04323d9b50ac8fa38f924cc022fc5cc382
4
+ data.tar.gz: a7570a4bb7f774c14a3098bcd353bab7f1b74e06
5
+ SHA512:
6
+ metadata.gz: ff42edc6baa5444cd8f99e1c8ec49efc558c57f7656eaaf56f61076403a6dc8d96208e9fd0579c4093e3921ce209639ed833a7c1ea3dfe68860d1be87c32272d
7
+ data.tar.gz: 8116a76e767df49fa93fafa2965784ef7f1ab8a8c8286e60afc0987dd54c28df78b6f4bcf69f29c1c78dc462d6b3b3ff47256fbd2aabb7c292b9c045e8ba5f0d
@@ -0,0 +1,28 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ Gemfile.lock
6
+ coverage
7
+ InstalledFiles
8
+ lib/bundler/man
9
+ pkg
10
+ rdoc
11
+ spec/reports
12
+ test/tmp
13
+ test/version_tmp
14
+ tmp
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
20
+
21
+ # VIM
22
+ [._]*.s[a-w][a-z]
23
+ [._]s[a-w][a-z]
24
+ *.un~
25
+ *~
26
+
27
+ # OSX
28
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - 2.0.0
7
+ - 2.1.0
8
+ - ruby-head
9
+ - jruby-18mode
10
+ - jruby-19mode
11
+ - jruby-head
12
+ - rbx
13
+ - ree
14
+ before_script:
15
+ - export QINIU_ACCESS_KEY=key_for_test
16
+ - export QINIU_SECRET_KEY=secret_for_test
17
+ deploy:
18
+ provider: rubygems
19
+ api_key:
20
+ secure: dFb7wl5NabGx+uhx6sph47sTVV1zdgHH+n5wsaIyLkQmGZPdgDc0Kz1Gr3XrKzUTjFeiKwRnPkamqMReweq/nkH43Z/F01dgPdgWVNekDTFEd6V06VXN00yhHeCLpQo52YdJ9f/gPsZKlCiOo+4Y3uwzClS3n8pT8kXb2M8z3ao=
21
+ gem: qiniu-policy
22
+ on:
23
+ tags: true
24
+ repo: why404/qiniu-policy
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test, :development do
4
+ gem 'coveralls', :require => false
5
+ gem 'mime-types', '< 2.0', :platforms => [:ruby_18, :mri_18, :jruby]
6
+ end
7
+
8
+ # Specify your gem's dependencies in qiniu-policy.gemspec
9
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 why404
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,108 @@
1
+ # qiniu-policy
2
+
3
+ [![Build Status](https://travis-ci.org/why404/qiniu-policy.png?branch=master)](https://travis-ci.org/why404/qiniu-policy)
4
+ [![Dependency Status](https://gemnasium.com/why404/qiniu-policy.png)](https://gemnasium.com/why404/qiniu-policy)
5
+ [![Coverage Status](https://coveralls.io/repos/why404/qiniu-policy/badge.png)](https://coveralls.io/r/why404/qiniu-policy)
6
+ [![Code Climate](https://codeclimate.com/github/why404/qiniu-policy.png)](https://codeclimate.com/github/why404/qiniu-policy)
7
+ [![Gem Version](https://badge.fury.io/rb/qiniu-policy.png)](http://badge.fury.io/rb/qiniu-policy)
8
+
9
+ Authorization library used to generate upload/download tokens of Qiniu Cloud Storage.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'qiniu-policy'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install qiniu-policy
24
+
25
+ ## Usage
26
+
27
+ ```ruby
28
+ require 'qiniu-policy'
29
+
30
+ mac = Qiniu::Kit::Mac.new('your_access_key', 'your_secret_key')
31
+
32
+ put_policy = Qiniu::Policy::Put.new(mac) do |f|
33
+ f.scope = 'my_video_bucket'
34
+ f.deadline = Time.now.to_i + 3600 # expires in one hour
35
+ f.endUser = 'why404'
36
+ f.callbackBody = 'fname=$(fname)&fsize=$(fsize)&ftype=$(mimeType)&uid=$(endUser)&myvar=$(x:myvar)'
37
+ f.callbackUrl = 'http://example.com/callback?from=qiniu'
38
+ f.persistentOps = 'avthumb/flash;avthumb/ipad_high;avthumb/iphone_high;avthumb/m3u8/segtime/10/preset/video_640k'
39
+ f.persistentNotifyUrl = 'http://example.com/notify?from=qiniu'
40
+ f.insertOnly = 1
41
+ f.fsizeLimit = 1024**3 # 1GB
42
+ f.saveKey = '$(endUser)/$(year)/$(mon)/$(day)/$(hour)-$(min)-$(sec).mp4'
43
+ f.detectMime = 1
44
+ f.mimeLimit = 'video/*'
45
+ f.transform = 'avthumb/mp4'
46
+ f.fopTimeout = 1800
47
+ end
48
+
49
+ uptoken = put_policy.token
50
+ ```
51
+
52
+ Or you can configure your Qiniu account access credentials globally.
53
+
54
+ ```ruby
55
+ require 'qiniu-policy'
56
+
57
+ Qiniu.config = {:access_key => '...', :secret_key => '...'}
58
+
59
+ put_policy = Qiniu::Policy::Put.new do |f|
60
+ # ...
61
+ end
62
+
63
+ uptoken = put_policy.token
64
+ ```
65
+
66
+ Additionally, the library will attempt to load these options from `ENV`:
67
+
68
+ export QINIU_ACCESS_KEY='...'
69
+ export QINIU_SECRET_KEY='...'
70
+
71
+ For more, go to [qiniu-kit](https://github.com/why404/qiniu-kit).
72
+
73
+ ## API Reference
74
+
75
+ - [Qiniu::Policy::Put](http://developer.qiniu.com/docs/v6/api/reference/security/put-policy.html)
76
+ - [Qiniu::Policy::Get](http://developer.qiniu.com/docs/v6/api/reference/security/download-token.html)
77
+
78
+ ## TODO
79
+
80
+ - Qiniu::Policy::Get
81
+
82
+ ## Supported Ruby versions
83
+
84
+ This library aims to support and is [tested against](https://travis-ci.org/why404/qiniu-kit) the following Ruby implementations:
85
+
86
+ - MRI 2.1.0
87
+ - MRI 2.0.0
88
+ - MRI 1.9.3
89
+ - MRI 1.9.2
90
+ - MRI 1.8.7
91
+ - JRuby 1.7.9 in Ruby 1.8 mode
92
+ - JRuby 1.7.9 in Ruby 1.9 mode
93
+ - Ruby Enterprise Edition 1.8.7 2012.02
94
+ - Ruby (latest master)
95
+ - [JRuby](http://jruby.org/) (latest master)
96
+ - [Rubinius](http://rubini.us/)
97
+
98
+ If something doesn't work on one of these Ruby versions, it's a bug.
99
+
100
+ This library may inadvertently work (or seem to work) on other Ruby implementations, however support will only be provided for the versions listed above.
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it ( <http://github.com/why404/qiniu-policy/fork> )
105
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
106
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
107
+ 4. Push to the branch (`git push origin my-new-feature`)
108
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'qiniu-kit'
3
+
4
+ %w(
5
+ qiniu/policy/version.rb
6
+ qiniu/policy/get.rb
7
+ qiniu/policy/put.rb
8
+ ).each do |f|
9
+ require File.join(File.dirname(__FILE__), f)
10
+ end
@@ -0,0 +1,10 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Qiniu
4
+ module Policy
5
+ module Get
6
+ class << self
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,36 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'qiniu-kit'
3
+
4
+ module Qiniu
5
+ module Policy
6
+ class Put
7
+
8
+ attr_reader :mac, :args
9
+
10
+ def initialize(mac_object = nil, &block)
11
+ if mac_object.nil?
12
+ @mac = Qiniu::Kit::Mac.new
13
+ else
14
+ unless mac_object.instance_of?(Qiniu::Kit::Mac)
15
+ raise Qiniu::Errors::NotAnInstanceOfError.new("Invalid mac object")
16
+ end
17
+ @mac = mac_object
18
+ end
19
+ @args ||= {}
20
+ instance_eval(&block) if block_given?
21
+ end
22
+
23
+ def method_missing(sym, *args, &block)
24
+ method_id = sym.to_s
25
+ if method_id.end_with?('=')
26
+ @args[method_id.chomp('=').to_sym] = args[0]
27
+ end
28
+ end
29
+
30
+ def token
31
+ @mac.sign_with_data(Qiniu::Kit.encode_json(@args))
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ module Qiniu
4
+ module Policy
5
+ VERSION = "0.1.1"
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'qiniu/policy/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qiniu-policy"
8
+ spec.version = Qiniu::Policy::VERSION
9
+ spec.authors = ["why404"]
10
+ spec.email = ["awhy.xu@gmail.com"]
11
+ spec.summary = %q{Qiniu GET/PUT authorization library.}
12
+ spec.description = %q{Authorization library used to generate upload/download tokens of Qiniu Cloud Storage.}
13
+ spec.homepage = "https://github.com/why404/qiniu-policy"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "qiniu-kit", "~> 0.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake", "~> 10.1"
25
+ spec.add_development_dependency "rspec", "~> 2.14"
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qiniu::Policy::Get do
4
+
5
+ context '.url' do
6
+ it 'should works' do
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qiniu::Policy::Put do
4
+
5
+ context '.token' do
6
+ it 'should works' do
7
+ # cuz json string no sort
8
+ expected_result = [
9
+ 'access_key:kyLwxo3HWXBn7ZY884IpS_DVjuM=:eyJkZWFkbGluZSI6MCwic2NvcGUiOiJteV92aWRlb19idWNrZXQifQ==',
10
+ 'access_key:wyz1S9nF7Sg-KWyQqn6UxjSr4kY=:eyJzY29wZSI6Im15X3ZpZGVvX2J1Y2tldCIsImRlYWRsaW5lIjowfQ=='
11
+ ]
12
+ mac = Qiniu::Kit::Mac.new('access_key', 'secret_key')
13
+ put_policy = Qiniu::Policy::Put.new(mac) do |f|
14
+ # let ruby 1.8.x and ruby 1.9.x both follow the in insertion order
15
+ f.deadline = 0
16
+ f.scope = 'my_video_bucket'
17
+ end
18
+ result = put_policy.token
19
+ expected_result.include?(result).should be_true
20
+ end
21
+ end
22
+
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Qiniu::Policy do
4
+
5
+ it 'should have a version number' do
6
+ Qiniu::Policy::VERSION.should_not be_nil
7
+ end
8
+
9
+ it 'version should be number' do
10
+ Qiniu::Policy::VERSION.to_s.should =~ /^\d+\.\d+\.\d+?$/
11
+ end
12
+
13
+ end
@@ -0,0 +1,8 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3
+ require 'qiniu-policy'
4
+
5
+ if RUBY_VERSION >= "1.9"
6
+ require 'coveralls'
7
+ Coveralls.wear!
8
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qiniu-policy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - why404
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: qiniu-kit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ description: Authorization library used to generate upload/download tokens of Qiniu
70
+ Cloud Storage.
71
+ email:
72
+ - awhy.xu@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".travis.yml"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/qiniu-policy.rb
85
+ - lib/qiniu/policy/get.rb
86
+ - lib/qiniu/policy/put.rb
87
+ - lib/qiniu/policy/version.rb
88
+ - qiniu-policy.gemspec
89
+ - spec/qiniu/policy/get_spec.rb
90
+ - spec/qiniu/policy/put_spec.rb
91
+ - spec/qiniu/policy_spec.rb
92
+ - spec/spec_helper.rb
93
+ homepage: https://github.com/why404/qiniu-policy
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.2.2
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Qiniu GET/PUT authorization library.
117
+ test_files:
118
+ - spec/qiniu/policy/get_spec.rb
119
+ - spec/qiniu/policy/put_spec.rb
120
+ - spec/qiniu/policy_spec.rb
121
+ - spec/spec_helper.rb