Created
May 15, 2013 14:41
-
-
Save dankerrigan/5584488 to your computer and use it in GitHub Desktop.
Simple Python Script for retrieving Riak CS Status w/o external deps
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
import sys | |
import hashlib | |
import hmac | |
import base64 | |
import time | |
import urllib2 | |
content_type = 'application/json' | |
def get_url_request(host, path, access_key, secret_key): | |
header_date = time.strftime("%a, %d %b %Y %H:%M:%S +0000", time.gmtime()) | |
auth_string = str.format("GET\n\n{content_type}\n{header_date}\n/{path}", | |
content_type=content_type, header_date=header_date, path=path) | |
hash_code = base64.encodestring(hmac.new(secret_key, auth_string, hashlib.sha1).digest()).strip() | |
auth_header = str.format("AWS {access_key}:{hash_code}", access_key=access_key, hash_code=hash_code) | |
headers = {'Authorization': auth_header, | |
'Content-Type': content_type, | |
'Date': header_date} | |
return urllib2.Request(url=str.format("{host}/{path}", host=host, path=path), headers=headers) | |
def cs_get(host, path, access_key, secret_key): | |
request = get_url_request(host, path, access_key, secret_key) | |
return urllib2.urlopen(request).read() | |
if __name__ == '__main__': | |
host = 'http://127.0.0.1:8080' | |
path = 'riak-cs/stats' | |
access_key = 'GBBFFPCY8QBX6BLINXHH' | |
secret_key = '1OL3L6RNNNik9NN5Ok9QEcv36wqQorlaLASqAA==' | |
if len(sys.argv) == 5: | |
host = sys.argv[1] | |
path = sys.argv[2] | |
access_key = sys.argv[3] | |
secret_key = sys.argv[4] | |
print cs_get(host, path, access_key, secret_key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment