Skip to content

Instantly share code, notes, and snippets.

@Micka33
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Micka33/9511727 to your computer and use it in GitHub Desktop.
Save Micka33/9511727 to your computer and use it in GitHub Desktop.
Test riak-cs

Substitute riak-cs by netcat to vatch the sent request

$> nc  -l 127.0.0.1 8080
PUT /53208b5294da268379000001?AWSAccessKeyId=O_5H9U1UTJNVB5MDNM0O&Expires=1394677746&Signature=IjMEUg%2BH%2FP7SP5nx4KW7gXJ6h8g%3D HTTP/1.1
Host: 52aed41a94da26d8fa000001.data.riak.dev
Content-Length: 2831
x-amz-acl: public-read
...

Generate signature using what we got in the previous sent request And check that it's the same

s3_key = '53208b5294da268379000001'
bucket = '52aed41a94da26d8fa000001'
expiration_date = '1394677746'
content_type = ''
method = 'PUT'
string_to_sign = "#{method}\n\n#{content_type}\n1394677746\nx-amz-acl:public-read\n/#{bucket}/#{s3_key}".encode("UTF-8")
me = User.list.reject{|u| u.email.split('@').first!='test'}[0]
signature = CGI.escape( Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'),me.key_secret, string_to_sign)).gsub("\n","") )

Uploading with curl using the url we got through netcat and check that it works, if it doesn't, then, the signature is wrong

curl -s -v -T ~/Pictures/paysage-nourriture-aliment-01.jpg -H 'x-amz-acl:public-read' -X PUT http://52aed41a94da26d8fa000001.data.riak.dev/53208b5294da268379000001\?AWSAccessKeyId\=O_5H9U1UTJNVB5MDNM0O\&Expires\=1394677746\&Signature\=IjMEUg%2BH%2FP7SP5nx4KW7gXJ6h8g%3D

Check if the user is created in riak-cs

Fog::Storage.new RiakCS::BucketManager.get_credentials(me.key_id, me.key_secret).directories[0].files.count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment