caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* OCaml S3 Library?
@ 2010-05-12 22:26 Daniel Patterson
  2010-05-13 13:31 ` [Caml-list] " Jerome Vouillon
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Patterson @ 2010-05-12 22:26 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1905 bytes --]

Has anyone written a library to interact with amazon web services
(specifically, S3)?

I started writing one, but something about the authentication is not working
properly, and I thought I'd check to see if anyone had already done this
before I try to figure out what is going wrong. Sample code follows, as if
there does not already exist a library, I'd be curious if anyone else sees
what is wrong with the authentication signature (what I assume is not
working), as now it 403's every time.

open Netencoding.Base64
open Cryptokit
open Cryptokit.MAC
open Http_client

let id = "___PUT_YOUR_ID_HERE____"
let key = "__PUT_YOUR_SECRET_KEY_HERE____"

let sign verb content_type date bucket url =
  let hash = hmac_sha1 key in
  let str_to_sign = verb ^ "\n\n" ^ content_type ^ "\n" ^  date ^ "\n" ^
 "/" ^ bucket ^ url  in
    begin
      Printf.printf "---------\n%s\n---------\n" str_to_sign;
      "AWS " ^ id ^ ":" ^ encode (hash_string hash str_to_sign)
    end

let date () = Netdate.mk_mail_date (Unix.time ())

let text_put_s3 bucket url contents =
  let uri = "http://" ^ bucket ^ ".s3.amazonaws.com" ^ url in
  let req = new put uri contents in
  let head = req#request_header `Base in
  let content_type = "text/plain" in
  let now = date () in
  let pipeline = new pipeline in
    begin
      pipeline#set_options {pipeline#get_options with verbose_status=true;
verbose_request_header=true; verbose_response_header=true;
                                      verbose_request_contents=true;
verbose_response_contents=true; verbose_connection=true};
      head#set_fields [("Date", now); ("Content-Type", content_type);
("Authentication", sign "PUT" content_type now bucket url)];
      req#set_request_header head;
      pipeline#add req;
      pipeline#run ();
      (req#response_status_code, req#response_status_text)
    end

let _ = text_put_s3 "__BUCKET_NAME__" "/test" "This is a Test."

[-- Attachment #2: Type: text/html, Size: 2595 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] OCaml S3 Library?
  2010-05-12 22:26 OCaml S3 Library? Daniel Patterson
@ 2010-05-13 13:31 ` Jerome Vouillon
  0 siblings, 0 replies; 2+ messages in thread
From: Jerome Vouillon @ 2010-05-13 13:31 UTC (permalink / raw)
  To: Daniel Patterson; +Cc: caml-list

On Wed, May 12, 2010 at 06:26:39PM -0400, Daniel Patterson wrote:
> Has anyone written a library to interact with amazon web services
> (specifically, S3)?

I have started writing a library for S3.  A large part of the API is
implemented.  What is missing is mostly dealing with metadata and
error handling.

You can find the current sources here:

   http://www.pps.jussieu.fr/~vouillon/S3.tar.gz

If anyone is interested to contribute, please contact me.  I will then
set up a shared repository.

-- Jerome


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-05-13 13:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-05-12 22:26 OCaml S3 Library? Daniel Patterson
2010-05-13 13:31 ` [Caml-list] " Jerome Vouillon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).