aliyun-odps 0.1.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.rubocop.yml +31 -0
- data/Gemfile +3 -0
- data/README.md +55 -12
- data/Rakefile +15 -5
- data/aliyun-odps.gemspec +22 -11
- data/bin/console +10 -3
- data/lib/aliyun/odps.rb +69 -2
- data/lib/aliyun/odps/authorization.rb +90 -0
- data/lib/aliyun/odps/client.rb +40 -0
- data/lib/aliyun/odps/configuration.rb +16 -0
- data/lib/aliyun/odps/error.rb +97 -0
- data/lib/aliyun/odps/http.rb +138 -0
- data/lib/aliyun/odps/list.rb +40 -0
- data/lib/aliyun/odps/model/function.rb +16 -0
- data/lib/aliyun/odps/model/functions.rb +113 -0
- data/lib/aliyun/odps/model/instance.rb +130 -0
- data/lib/aliyun/odps/model/instance_task.rb +30 -0
- data/lib/aliyun/odps/model/instances.rb +119 -0
- data/lib/aliyun/odps/model/projects.rb +73 -0
- data/lib/aliyun/odps/model/resource.rb +26 -0
- data/lib/aliyun/odps/model/resources.rb +144 -0
- data/lib/aliyun/odps/model/table.rb +37 -0
- data/lib/aliyun/odps/model/table_column.rb +13 -0
- data/lib/aliyun/odps/model/table_partition.rb +9 -0
- data/lib/aliyun/odps/model/table_partitions.rb +90 -0
- data/lib/aliyun/odps/model/table_schema.rb +13 -0
- data/lib/aliyun/odps/model/tables.rb +125 -0
- data/lib/aliyun/odps/model/task_result.rb +9 -0
- data/lib/aliyun/odps/modelable.rb +16 -0
- data/lib/aliyun/odps/project.rb +47 -0
- data/lib/aliyun/odps/service_object.rb +27 -0
- data/lib/aliyun/odps/struct.rb +126 -0
- data/lib/aliyun/odps/tunnel/download_session.rb +98 -0
- data/lib/aliyun/odps/tunnel/router.rb +15 -0
- data/lib/aliyun/odps/tunnel/snappy_reader.rb +19 -0
- data/lib/aliyun/odps/tunnel/snappy_writer.rb +45 -0
- data/lib/aliyun/odps/tunnel/table_tunnels.rb +81 -0
- data/lib/aliyun/odps/tunnel/upload_block.rb +9 -0
- data/lib/aliyun/odps/tunnel/upload_session.rb +132 -0
- data/lib/aliyun/odps/utils.rb +102 -0
- data/lib/aliyun/odps/version.rb +1 -1
- data/requirements.png +0 -0
- data/wiki/error.md +188 -0
- data/wiki/functions.md +39 -0
- data/wiki/get_start.md +34 -0
- data/wiki/installation.md +15 -0
- data/wiki/instances.md +32 -0
- data/wiki/projects.md +51 -0
- data/wiki/resources.md +62 -0
- data/wiki/ssl.md +7 -0
- data/wiki/tables.md +75 -0
- data/wiki/tunnels.md +80 -0
- metadata +195 -13
- data/requirements.mindnode/QuickLook/Preview.jpg +0 -0
- data/requirements.mindnode/contents.xml +0 -10711
- data/requirements.mindnode/viewState.plist +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 668bb0a1605386f0934814e45f60e6550a8d21d8
|
4
|
+
data.tar.gz: 2b94dd56d05754e2b7ad7e674ec5d78cf4fc8235
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3066f7654504c549c91823f88ffecdaeb319f8614f59386920fd70ec08955198c7717d5cc99075d9a820a3f406fd8c02bc1cc62ece513f0b0b194f24f302c7a6
|
7
|
+
data.tar.gz: b65df29d07ea272729c4d8cbf72c2ee9fe6ca6b8f14cfee6c7223cd8e81a7046d8dfe0d2e7a26848571752d006a4a1b38f7fcc51a42b304c920ef7a36b1d4e96
|
data/.gitignore
CHANGED
data/.rubocop.yml
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# This is the configuration used to check the rubocop source code.
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
Exclude:
|
5
|
+
- 'demo/**/*'
|
6
|
+
- 'test/**/*'
|
7
|
+
|
8
|
+
Metrics/LineLength:
|
9
|
+
Max: 100
|
10
|
+
Enabled: false
|
11
|
+
|
12
|
+
Style/Documentation:
|
13
|
+
Enabled: false
|
14
|
+
|
15
|
+
Style/DoubleNegation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Metrics/ClassLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Style/AccessorMethodName:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/PredicateName:
|
25
|
+
Enabled: false
|
26
|
+
|
27
|
+
Style/Lambda:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Lint/UnusedMethodArgument:
|
31
|
+
Enabled: false
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
# Aliyun
|
1
|
+
# Aliyun ODPS SDK
|
2
2
|
|
3
3
|
-----
|
4
4
|
|
5
5
|
It is a full-featured Ruby Library for Aliyun ODPS API. Enjoy it!
|
6
6
|
|
7
|
-
|
8
7
|
## Installation
|
9
8
|
|
10
9
|
It's a Ruby Gem, so you can install it like any Gem:
|
@@ -19,39 +18,83 @@ And run:
|
|
19
18
|
|
20
19
|
bundle install
|
21
20
|
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
### Quick Start
|
25
|
+
|
26
|
+
First of all, config your environment.
|
27
|
+
|
28
|
+
If you use Rails, you can place it in `config/initializers/aliyun_odps.rb`, for other framework, just place it before your other odps code.
|
29
|
+
|
30
|
+
Aliyun::Odps.configure do |config|
|
31
|
+
config.access_key = '<your-access-key>'
|
32
|
+
config.secret_key = '<your-secret-key>'
|
33
|
+
config.endpoint = '<odps-server-api>' # "http://service.odps.aliyun.com/api"
|
34
|
+
config.project = '<your-default-project>'
|
35
|
+
end
|
36
|
+
|
37
|
+
After that, you can get your project and start party now!
|
38
|
+
|
39
|
+
project = Aliyun::Odps.project
|
40
|
+
|
41
|
+
# Accesss tables
|
42
|
+
project.tables.list
|
43
|
+
|
44
|
+
# Access resources
|
45
|
+
project.resources.list
|
46
|
+
|
47
|
+
# Access instances
|
48
|
+
project.instances.list
|
49
|
+
|
50
|
+
# Access functions
|
51
|
+
project.functions.list
|
52
|
+
|
53
|
+
|
54
|
+
# For Tunnel
|
55
|
+
project.table_tunnels
|
56
|
+
|
57
|
+
More Example and Scenario, visit our [Document](#document)
|
58
|
+
|
59
|
+
|
22
60
|
## Document
|
23
61
|
|
24
62
|
Here is original Restful API, It has the most detailed and authoritative explanation for every API.
|
25
63
|
|
26
64
|
+ [http://repo.aliyun.com/api-doc/index.html](http://repo.aliyun.com/api-doc/index.html)
|
27
65
|
|
28
|
-
Here is
|
66
|
+
Here is our RDoc Document, It's well format to help you find more detail about methods.
|
29
67
|
|
30
|
-
+ [RDoc Document]()
|
68
|
+
+ [RDoc Document](http://www.rubydoc.info/gems/aliyun-odps/0.1.0)
|
31
69
|
|
32
70
|
|
33
71
|
Here are some more guides for help you. Welcome to advice.
|
34
72
|
|
73
|
+
All document are under `./wiki`
|
74
|
+
|
35
75
|
+ [Installation](./wiki/installation.md)
|
36
76
|
+ [Getting Started](./wiki/get_start.md)
|
37
|
-
+ [
|
77
|
+
+ [Projects](./wiki/projects.md)
|
78
|
+
+ [Instances](./wiki/instances.md)
|
79
|
+
+ [Resources](./wiki/resources.md)
|
80
|
+
+ [Functions](./wiki/functions.md)
|
81
|
+
+ [Tables](./wiki/tables.md)
|
82
|
+
+ [Tunnels](./wiki/tunnels.md)
|
83
|
+
+ [Error Code](./wiki/error.md)
|
84
|
+
+ [SSL Connection](./wiki/ssl.md)
|
38
85
|
|
39
|
-
## Usage
|
40
|
-
|
41
|
-
### Quick Start
|
42
86
|
|
43
87
|
## Test
|
44
88
|
|
45
89
|
We use minitest for test and rubocop for Syntax checker, If you want to make contribute to this library. Confirm below Command is success:
|
46
90
|
|
47
|
-
|
48
|
-
bundle exec rake test
|
49
|
-
```
|
91
|
+
bundle exec rake test
|
50
92
|
|
51
93
|
|
52
94
|
## Authors && Contributors
|
53
95
|
|
54
|
-
- [Newell
|
96
|
+
- [Newell](https://github.com/zlx_star)
|
97
|
+
- [genewoo](https://github.com/genewoo)
|
55
98
|
|
56
99
|
|
57
100
|
## License
|
data/Rakefile
CHANGED
@@ -1,10 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
|
+
require 'rubocop/rake_task'
|
3
4
|
|
4
5
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
6
|
+
t.libs << 'test'
|
7
|
+
t.libs << 'lib'
|
7
8
|
t.test_files = FileList['test/**/*_test.rb']
|
8
9
|
end
|
9
10
|
|
10
|
-
task :
|
11
|
+
task default: :test
|
12
|
+
|
13
|
+
task :test do
|
14
|
+
Rake::Task['test'].invoke
|
15
|
+
Rake::Task['rubocop'].invoke
|
16
|
+
end
|
17
|
+
|
18
|
+
RuboCop::RakeTask.new do |task|
|
19
|
+
task.fail_on_error = false
|
20
|
+
end
|
data/aliyun-odps.gemspec
CHANGED
@@ -4,21 +4,32 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'aliyun/odps/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'aliyun-odps'
|
8
8
|
spec.version = Aliyun::Odps::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Newell Zhu']
|
10
|
+
spec.email = ['zlx.star@gmail.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
12
|
+
spec.summary = 'It is a full-featured Ruby Library for Aliyun ODPS API. Enjoy it!'
|
13
|
+
spec.description = 'It is a full-featured Ruby Library for Aliyun ODPS API. Enjoy it!'
|
14
|
+
spec.homepage = 'https://github.com/aliyun-beta'
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
-
spec.bindir =
|
17
|
+
spec.bindir = 'exe'
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
-
spec.require_paths = [
|
19
|
+
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.
|
22
|
-
spec.
|
23
|
-
spec.
|
21
|
+
spec.add_dependency 'httparty'
|
22
|
+
spec.add_dependency 'addressable'
|
23
|
+
spec.add_dependency 'activesupport'
|
24
|
+
spec.add_dependency 'gyoku'
|
25
|
+
spec.add_dependency 'odps_protobuf', '0.5.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler'
|
28
|
+
spec.add_development_dependency 'rake'
|
29
|
+
spec.add_development_dependency 'minitest'
|
30
|
+
spec.add_development_dependency 'mocha'
|
31
|
+
spec.add_development_dependency 'webmock'
|
32
|
+
spec.add_development_dependency 'timecop'
|
33
|
+
spec.add_development_dependency 'rubocop'
|
34
|
+
spec.add_development_dependency 'snappy'
|
24
35
|
end
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'aliyun/odps'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,12 @@ require "aliyun/odps/sdk"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
|
13
|
+
Aliyun::Odps.configure do |config|
|
14
|
+
config.access_key = ENV['ALIYUN_ACCESS_KEY'] || ''
|
15
|
+
config.secret_key = ENV['ALIYUN_SECRET_KEY'] || ''
|
16
|
+
config.endpoint = 'http://service.odps.aliyun.com/api'
|
17
|
+
config.project = ENV['ALIYUN_PROJECT'] || 'your-mock-project'
|
18
|
+
end
|
19
|
+
|
20
|
+
require 'irb'
|
14
21
|
IRB.start
|
data/lib/aliyun/odps.rb
CHANGED
@@ -1,7 +1,74 @@
|
|
1
|
-
require
|
1
|
+
require 'aliyun/odps/version'
|
2
|
+
require 'aliyun/odps/error'
|
3
|
+
require 'aliyun/odps/configuration'
|
4
|
+
require 'aliyun/odps/struct'
|
5
|
+
require 'aliyun/odps/modelable'
|
6
|
+
require 'aliyun/odps/project'
|
7
|
+
|
8
|
+
require 'aliyun/odps/authorization'
|
9
|
+
require 'aliyun/odps/client'
|
10
|
+
require 'aliyun/odps/utils'
|
11
|
+
require 'aliyun/odps/list'
|
12
|
+
|
13
|
+
# DEBUG
|
14
|
+
require 'pry'
|
2
15
|
|
3
16
|
module Aliyun
|
4
17
|
module Odps
|
5
|
-
|
18
|
+
class << self
|
19
|
+
attr_writer :configuration
|
20
|
+
|
21
|
+
# Config Odps
|
22
|
+
#
|
23
|
+
# @example
|
24
|
+
#
|
25
|
+
# Aliyun::Odps.configure do |config|
|
26
|
+
# config.access_key = 'your-access-key'
|
27
|
+
# config.secret_key = 'your-secret-key'
|
28
|
+
# config.endpoint = 'odps-api-endpoint' # 'http://service.odps.aliyun.com/api' or 'http://odps-ext.aliyun-inc.com/api'
|
29
|
+
# config.project = 'your-default-project-name'
|
30
|
+
# config.tunnel_endpoint = 'odps-tunnel-api-endpoint' # if you not config it, we will auto detect it
|
31
|
+
# end
|
32
|
+
def configure
|
33
|
+
@configuration ||= Configuration.new
|
34
|
+
yield @configuration if block_given?
|
35
|
+
@configuration
|
36
|
+
end
|
37
|
+
|
38
|
+
# return current configuration
|
39
|
+
#
|
40
|
+
# @return [Configuration]
|
41
|
+
def config
|
42
|
+
@configuration
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get project
|
46
|
+
#
|
47
|
+
# @param name [String] specify project name, default is project in config
|
48
|
+
#
|
49
|
+
# @return [Project]
|
50
|
+
def project(name = config.project)
|
51
|
+
fail MissingProjectConfigurationError unless name
|
52
|
+
client.projects.get(name)
|
53
|
+
end
|
54
|
+
alias_method :get_project, :project
|
55
|
+
|
56
|
+
# (see Projects#list)
|
57
|
+
def list_projects(options = {})
|
58
|
+
client.projects.list(options)
|
59
|
+
end
|
60
|
+
alias_method :projects, :list_projects
|
61
|
+
|
62
|
+
# (see Projects#update)
|
63
|
+
def update_project(name, options = {})
|
64
|
+
client.projects.update(name, options)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def client
|
70
|
+
@client ||= Aliyun::Odps::Client.new
|
71
|
+
end
|
72
|
+
end
|
6
73
|
end
|
7
74
|
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'openssl'
|
3
|
+
require 'digest'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
module Aliyun
|
7
|
+
module Odps
|
8
|
+
class Authorization
|
9
|
+
PROVIDER = 'ODPS'
|
10
|
+
|
11
|
+
class << self
|
12
|
+
# @private
|
13
|
+
#
|
14
|
+
# Get authorization key
|
15
|
+
#
|
16
|
+
# @param access_key [String] Access Key
|
17
|
+
# @param secret_key [String] Secret Key
|
18
|
+
# @param options [Hash] Options
|
19
|
+
# @option options [String] :verb VERB, request method
|
20
|
+
# @option options [String] :date Request Time in formate: '%a, %d %b %Y %H:%M:%S GMT'
|
21
|
+
# @option options [String] :path resource name
|
22
|
+
# @option options [Hash] :query Query key-value pair
|
23
|
+
# @option options [Hash] :headers Headers
|
24
|
+
#
|
25
|
+
# @return [String] the authorization string
|
26
|
+
def get_authorization(access_key, secret_key, options = {})
|
27
|
+
content_string = concat_content_string(options[:verb], options[:date], options)
|
28
|
+
signature_string = signature(secret_key, content_string)
|
29
|
+
"#{PROVIDER} #{access_key}:#{signature_string.strip}"
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def concat_content_string(verb, time, options = {})
|
35
|
+
headers = options.fetch(:headers, {})
|
36
|
+
|
37
|
+
conon_headers = get_cononicalized_odps_headers(headers)
|
38
|
+
conon_resource = get_cononicalized_resource(
|
39
|
+
*options.values_at(:path, :query)
|
40
|
+
)
|
41
|
+
|
42
|
+
join_values(verb, time, headers, conon_headers, conon_resource)
|
43
|
+
end
|
44
|
+
|
45
|
+
def join_values(verb, time, headers, conon_headers, conon_resource)
|
46
|
+
[
|
47
|
+
verb,
|
48
|
+
headers['Content-MD5'].to_s.strip,
|
49
|
+
headers['Content-Type'].to_s.strip,
|
50
|
+
time,
|
51
|
+
conon_headers
|
52
|
+
].join("\n") + conon_resource
|
53
|
+
end
|
54
|
+
|
55
|
+
def signature(secret_key, content_string)
|
56
|
+
utf8_string = content_string.force_encoding('utf-8')
|
57
|
+
Base64.encode64(
|
58
|
+
OpenSSL::HMAC.digest(
|
59
|
+
OpenSSL::Digest::SHA1.new,
|
60
|
+
secret_key,
|
61
|
+
utf8_string
|
62
|
+
)
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_cononicalized_odps_headers(headers)
|
67
|
+
odps_headers = (headers || {}).select do |key, _|
|
68
|
+
key.to_s.downcase.start_with?('x-odps-')
|
69
|
+
end
|
70
|
+
return if odps_headers.empty?
|
71
|
+
|
72
|
+
odps_headers.keys.sort.map do |key|
|
73
|
+
"#{key.downcase}:#{odps_headers[key]}"
|
74
|
+
end.join("\n") + "\n"
|
75
|
+
end
|
76
|
+
|
77
|
+
def get_cononicalized_resource(path, query)
|
78
|
+
conon_resource = path
|
79
|
+
return conon_resource if query.nil? || query.empty?
|
80
|
+
|
81
|
+
Utils.stringify_keys!(query)
|
82
|
+
|
83
|
+
query_str = query.keys.sort.map { |k| "#{k}=#{query[k]}" }.join('&')
|
84
|
+
|
85
|
+
query_str.empty? ? conon_resource : conon_resource + '?' + query_str
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'aliyun/odps/http'
|
2
|
+
require 'aliyun/odps/service_object'
|
3
|
+
require 'aliyun/odps/model/projects'
|
4
|
+
|
5
|
+
module Aliyun
|
6
|
+
module Odps
|
7
|
+
class Client < ServiceObject
|
8
|
+
extend Aliyun::Odps::Modelable
|
9
|
+
|
10
|
+
# @!method projects
|
11
|
+
# @return [Projects]
|
12
|
+
has_many :projects
|
13
|
+
|
14
|
+
attr_reader :config
|
15
|
+
|
16
|
+
# Initialize a object
|
17
|
+
#
|
18
|
+
# @param access_key [String] access_key obtained from aliyun
|
19
|
+
# @param secret_key [String] secret_key obtained from aliyun
|
20
|
+
# @option opts [String] :endpoint endpoint for API
|
21
|
+
#
|
22
|
+
# @return [Response]
|
23
|
+
def initialize(config = Aliyun::Odps.config)
|
24
|
+
@config = config
|
25
|
+
end
|
26
|
+
|
27
|
+
%w(get put post delete options head).each do |method|
|
28
|
+
define_method(method) do |*args|
|
29
|
+
http.send(method, *args)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def http
|
36
|
+
@http ||= Http.new(config)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|