aliyun-rds 0.0.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: 4ae5e80e3e7bb4a709e1b0b89a2f17a2298db7bc
4
+ data.tar.gz: 10552e3fa515a974e0b1dc13a68f0dc9a20e19df
5
+ SHA512:
6
+ metadata.gz: 7110388cad40c1f8f97cd97c00cc89301d5ded63a2a9e30d8dc4077fdd3cad722edcb414ad48c341db69e5270542ee967eb4fd1a0915e26274bb6639380152a9
7
+ data.tar.gz: 6ce24779bda0d7932e3de7458ba77a9e41d545ca3bb9e664f1cc04a668eda82a9e1c4d6dae31c364fc3d9ea314845842842beb09a552cf01940ed901eba753b6
@@ -0,0 +1,22 @@
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
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify gem's dependencies in aliyun.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Liu Lantao
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.
@@ -0,0 +1,49 @@
1
+ # Aliyun RDS
2
+
3
+ Ruby wrapper of Aliyun RDS API for system adminstrator.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'aliyun-rds'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install aliyun-rds
18
+
19
+ ## Usage
20
+
21
+ Example:
22
+
23
+ require 'rubygems'
24
+ require 'aliyun-rds'
25
+
26
+ options = {
27
+ :access_key_id => "_YOUR_API_KEY_",
28
+ :access_key_secret => "_YOUR_API_SECRET_",
29
+ :endpoint_url => "https://rds.aliyuncs.com/"
30
+ }
31
+
32
+ service = Aliyun::RDS::Service.new options
33
+ parameters = {}
34
+
35
+ puts service.DescribeRegions parameters
36
+
37
+ You can create/fetch `access key`/`secret` at [https://i.aliyun.com/access_key](https://i.aliyun.com/access_key)
38
+
39
+ ## Contributing
40
+
41
+ 1. Fork it ( https://github.com/Lax/aliyun-rds/fork )
42
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
43
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
44
+ 4. Push to the branch (`git push origin my-new-feature`)
45
+ 5. Create a new Pull Request
46
+
47
+ ## Author
48
+
49
+ * [Liu Lantao](https://github.com/Lax)
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'aliyun/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "aliyun-rds"
8
+ spec.version = Aliyun::VERSION
9
+ spec.authors = ["Liu Lantao"]
10
+ spec.email = ["liulantao@gmail.com"]
11
+ spec.summary = %q{Ruby wrapper of Aliyun RDS API for system administrator}
12
+ spec.description = %q{Ruby wrapper of Aliyun RDS API for system administrator.
13
+ Current for aliyun RDS API version 2013-05-28
14
+ }
15
+ spec.homepage = "https://github.com/Lax/aliyun-rds"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.6"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_dependency "ruby-hmac"
26
+ end
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'aliyun'
3
+
4
+ $DEBUG=false
5
+
6
+ options = {:access_key_id => "xxxxxx",
7
+ :access_key_secret => "yyyyy",
8
+ :endpoint_url => "https://rds.aliyuncs.com/"}
9
+
10
+ service = Aliyun::RDS::Service.new options
11
+
12
+ parameters = {}
13
+
14
+ puts service.DescribeDBInstances parameters
@@ -0,0 +1,3 @@
1
+ require "aliyun/version"
2
+ require "aliyun/base"
3
+ require "aliyun/rds"
@@ -0,0 +1,19 @@
1
+ module Aliyun
2
+ ALIYUN_API_ENDPOINT='https://rds.aliyuncs.com/'
3
+ SEPARATOR = "&"
4
+ HTTP_METHOD = "GET"
5
+
6
+ $ENDPOINT_URL = nil
7
+ $ACCESS_KEY_ID = nil
8
+ $ACCESS_KEY_SECRET = nil
9
+
10
+ DEFAULT_PARAMETERS = {
11
+ :Format=>"JSON",
12
+ :Version=>"2013-05-28",
13
+ :SignatureMethod=>"HMAC-SHA1",
14
+ :SignatureVersion=>"1.0"
15
+ }
16
+
17
+ class AliyunAPIException < RuntimeError
18
+ end
19
+ end
@@ -0,0 +1,123 @@
1
+ require 'net/http'
2
+ require 'time'
3
+ require 'securerandom'
4
+ require 'uri'
5
+ require 'base64'
6
+ require 'hmac-sha1'
7
+ require 'json'
8
+
9
+ module Aliyun
10
+ module RDS
11
+ class Service
12
+ attr_accessor :access_key_id, :access_key_secret
13
+ attr_accessor :options
14
+ attr_accessor :endpoint_url
15
+
16
+ def initialize(options={})
17
+ self.access_key_id = options[:access_key_id] || $ACCESS_KEY_ID || ""
18
+ self.access_key_secret = options[:access_key_secret] || $ACCESS_KEY_SECRET || ""
19
+ self.endpoint_url = options[:endpoint_url] || $ENDPOINT_URL || ALIYUN_API_ENDPOINT
20
+ self.options = {:AccessKeyId => self.access_key_id}
21
+ end
22
+
23
+ def method_missing(method, *args)
24
+ if $DEBUG
25
+ puts "Not Found Method: #{method}"
26
+ end
27
+
28
+ if args[0].nil?
29
+ raise AliyunAPIException.new "Method missing: #{method}!"
30
+ end
31
+
32
+ call_aliyun_with_parameter(method, args[0])
33
+ end
34
+
35
+ #Dispatch the request with parameter
36
+ private
37
+ def call_aliyun_with_parameter(method, params)
38
+ params = gen_request_parameters method, params
39
+ uri = URI(endpoint_url)
40
+
41
+ uri.query = URI.encode_www_form(params)
42
+
43
+ http = Net::HTTP.new(uri.host, uri.port)
44
+ http.use_ssl = (uri.scheme == "https")
45
+
46
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
47
+ if $DEBUG
48
+ puts "Request URI: #{uri.request_uri}"
49
+ end
50
+
51
+ request = Net::HTTP::Get.new(uri.request_uri)
52
+ response = http.request(request)
53
+
54
+ case response
55
+ when Net::HTTPSuccess
56
+ return JSON.parse(response.body)
57
+ else
58
+ raise AliyunAPIException.new "Response code: #{response.code}, message: #{response.body}"
59
+ end
60
+ end
61
+
62
+ #generate the parameters
63
+ def gen_request_parameters method, params
64
+ #add common parameters
65
+ params.merge! DEFAULT_PARAMETERS
66
+
67
+ params.merge! self.options
68
+
69
+ params[:Action] = method.to_s
70
+ params[:TimeStamp] = Time.now.utc.iso8601
71
+ params[:SignatureNonce] = SecureRandom.uuid
72
+ params[:Signature] = compute_signature params
73
+
74
+ params
75
+ end
76
+
77
+ #compute the signature of the parameters String
78
+ def compute_signature params
79
+ if $DEBUG
80
+ puts "keys before sorted: #{params.keys}"
81
+ end
82
+
83
+ sorted_keys = params.keys.sort
84
+
85
+ if $DEBUG
86
+ puts "keys after sorted: #{sorted_keys}"
87
+ end
88
+
89
+ canonicalized_query_string = ""
90
+
91
+ canonicalized_query_string = sorted_keys.map {|key|
92
+ "%s=%s" % [safe_encode(key.to_s), safe_encode(params[key])]
93
+ }.join(SEPARATOR)
94
+
95
+ length = canonicalized_query_string.length
96
+
97
+ string_to_sign = HTTP_METHOD + SEPARATOR + safe_encode('/') + SEPARATOR + safe_encode(canonicalized_query_string)
98
+
99
+ if $DEBUG
100
+ puts "string_to_sign is #{string_to_sign}"
101
+ end
102
+
103
+ signature = calculate_signature access_key_secret+"&", string_to_sign
104
+ end
105
+
106
+ #calculate the signature
107
+ def calculate_signature key, string_to_sign
108
+ hmac = HMAC::SHA1.new(key)
109
+ hmac.update(string_to_sign)
110
+ signature = Base64.encode64(hmac.digest).gsub("\n", '')
111
+ if $DEBUG
112
+ puts "Signature #{signature}"
113
+ end
114
+ signature
115
+ end
116
+
117
+ #encode the value to aliyun's requirement
118
+ def safe_encode value
119
+ value = URI.encode_www_form_component(value).gsub(/\+/,'%20').gsub(/\*/,'%2A').gsub(/%7E/,'~')
120
+ end
121
+ end
122
+ end
123
+ end
@@ -0,0 +1,3 @@
1
+ module Aliyun
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aliyun-rds
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Liu Lantao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruby-hmac
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: "Ruby wrapper of Aliyun RDS API for system administrator.\n Current
56
+ for aliyun RDS API version 2013-05-28\n "
57
+ email:
58
+ - liulantao@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - aliyun-rds.gemspec
69
+ - examples/describe_regions.rb
70
+ - lib/aliyun-rds.rb
71
+ - lib/aliyun/base.rb
72
+ - lib/aliyun/rds.rb
73
+ - lib/aliyun/version.rb
74
+ homepage: https://github.com/Lax/aliyun-rds
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.2.2
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Ruby wrapper of Aliyun RDS API for system administrator
98
+ test_files: []