aliyun-slb 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: b561f6beb8c57903dac4c3343f1da46917d2f6c9
4
+ data.tar.gz: 8e81c94e33ab9c3dd1815a423f2524e206a37da2
5
+ SHA512:
6
+ metadata.gz: f9afb31d4817d4ffaf89fd8e72898ff269cbaf23434ef1f8338e72a083ab91358928976ab7ca01c272f6d807bc47d3a5698645709a65eb41612a2d26521d7fa4
7
+ data.tar.gz: 9cb3e38fde8f42204e175ee633647a33dd9425820a0bfb0a848f235817adc97795e8db9549b557a4df1f150c8ad8dadb944bda8559b705c4b93ac726ac0f9314
@@ -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,51 @@
1
+ # Aliyun SLB
2
+
3
+ Ruby wrapper of Aliyun SLB API for system adminstrator.
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/aliyun-slb.svg)](http://badge.fury.io/rb/aliyun-slb)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'aliyun-slb'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install aliyun-slb
20
+
21
+ ## Usage
22
+
23
+ Example:
24
+
25
+ require 'rubygems'
26
+ require 'aliyun-slb'
27
+
28
+ options = {
29
+ :access_key_id => "_YOUR_API_KEY_",
30
+ :access_key_secret => "_YOUR_API_SECRET_",
31
+ :endpoint_url => "https://slb.aliyuncs.com/"
32
+ }
33
+
34
+ service = Aliyun::SLB::Service.new options
35
+ parameters = {}
36
+
37
+ puts service.DescribeRegions parameters
38
+
39
+ You can create/fetch `access key`/`secret` at [https://i.aliyun.com/access_key](https://i.aliyun.com/access_key)
40
+
41
+ ## Contributing
42
+
43
+ 1. Fork it ( https://github.com/Lax/aliyun-slb/fork )
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 a new Pull Request
48
+
49
+ ## Author
50
+
51
+ * [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-slb"
8
+ spec.version = Aliyun::VERSION
9
+ spec.authors = ["Liu Lantao"]
10
+ spec.email = ["liulantao@gmail.com"]
11
+ spec.summary = %q{Ruby wrapper of Aliyun SLB API for system administrator}
12
+ spec.description = %q{Ruby wrapper of Aliyun SLB API for system administrator.
13
+ Current for aliyun SLB API version 2014-05-15
14
+ }
15
+ spec.homepage = "https://github.com/Lax/aliyun-slb"
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-slb'
3
+
4
+ $DEBUG=false
5
+
6
+ options = {:access_key_id => "xxxxxx",
7
+ :access_key_secret => "yyyyy",
8
+ :endpoint_url => "https://slb.aliyuncs.com/"}
9
+
10
+ service = Aliyun::SLB::Service.new options
11
+
12
+ parameters = {}
13
+
14
+ puts service.DescribeRegions parameters
@@ -0,0 +1,3 @@
1
+ require "aliyun/version"
2
+ require "aliyun/base"
3
+ require "aliyun/slb"
@@ -0,0 +1,19 @@
1
+ module Aliyun
2
+ ALIYUN_API_ENDPOINT='https://slb.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=>"2014-05-15",
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 SLB
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-slb
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: 2015-01-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 SLB API for system administrator.\n Current
56
+ for aliyun SLB API version 2014-05-15\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-slb.gemspec
69
+ - examples/describe_regions.rb
70
+ - lib/aliyun-slb.rb
71
+ - lib/aliyun/base.rb
72
+ - lib/aliyun/slb.rb
73
+ - lib/aliyun/version.rb
74
+ homepage: https://github.com/Lax/aliyun-slb
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 SLB API for system administrator
98
+ test_files: []