caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Daniel Patterson <dbpatt@gmail.com>
To: caml-list@yquem.inria.fr
Subject: OCaml S3 Library?
Date: Wed, 12 May 2010 18:26:39 -0400	[thread overview]
Message-ID: <AANLkTikhDLKWyWiPnLO2eP7h3cAl-L9GFFRg2IIPri8L@mail.gmail.com> (raw)

[-- 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 --]

             reply	other threads:[~2010-05-12 22:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-12 22:26 Daniel Patterson [this message]
2010-05-13 13:31 ` [Caml-list] " Jerome Vouillon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AANLkTikhDLKWyWiPnLO2eP7h3cAl-L9GFFRg2IIPri8L@mail.gmail.com \
    --to=dbpatt@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).