Last active
August 29, 2015 13:57
-
-
Save shun115/9526768 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'cgi' | |
require 'time' | |
require 'openssl' | |
require 'base64' | |
require 'net/http' | |
require 'net/https' | |
require 'pp' | |
# キー情報をコピペしてください。 | |
# アクセスキー | |
ACCESS_IDENTIFIER = '' | |
# シークレットキー | |
SECRET_IDENTIFIER = '' | |
# RDBのAPIアクセスポイント | |
ENDPOINT = 'rdb-api.jp-e1.cloudn-service.com' | |
ADDRESS = "http://#{ENDPOINT}" | |
if ARGV.size < 1 then | |
puts "usage :./kick_api.rb Action=... parameter=... parameter=..."; exit 1; | |
end | |
# シグネチャ生成用の変数 | |
params = { | |
'AWSAccessKeyId' => ACCESS_IDENTIFIER, | |
'SignatureMethod' => 'HmacSHA256', | |
'SignatureVersion' => 2, | |
'Version' => '2012-04-23', | |
'Timestamp' => Time.now.iso8601 | |
} | |
for i in ARGV | |
key, value = i.split("=") | |
params[key] = value | |
end | |
canonical_querystring = params.sort.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') | |
puts canonical_querystring | |
string_to_sign = "GET | |
#{ENDPOINT} | |
/ | |
#{canonical_querystring}" | |
ssl = OpenSSL::HMAC.new(SECRET_IDENTIFIER, 'sha256') | |
ssl.update(string_to_sign) | |
signature = Base64.encode64(ssl.digest).chomp # chomp is important! the base64 encoded version will have a newline at the end | |
params['Signature'] = signature | |
querystring = params.collect { |key, value| [CGI.escape(key.to_s), CGI.escape(value.to_s)].join('=') }.join('&') # order doesn't matter for the actual request | |
get = Net::HTTP::Get.new("/?#{querystring}") | |
https = Net::HTTP.new("#{ENDPOINT}", 443) | |
https.use_ssl = true | |
https.start { |w| | |
puts "=====" | |
response = w.request(get) | |
p response.header | |
puts response.body | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment