From eec41f9ce08627540d1aa4d2cdf4ee5c7575994c Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Sun, 14 Jun 2015 10:27:23 +0200 Subject: [PATCH 1/3] bump to SNAPSHOT --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index 7dc5c67..d8686f9 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject org.martinklepsch/s3-beam "0.3.0" +(defproject org.martinklepsch/s3-beam "0.3.0-SNAPSHOT" :author "Martin Klepsch " :description "CORS Upload to S3 via Clojure(script)" :url "http://github.com/martinklepsch/s3-beam" From 2e6c05599c6a50037b67bff4342cc70e259ef3c8 Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Sun, 14 Jun 2015 10:28:16 +0200 Subject: [PATCH 2/3] resolve S3 endpoint correctly --- src/clj/s3_beam/handler.clj | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/clj/s3_beam/handler.clj b/src/clj/s3_beam/handler.clj index 7472bfd..9f5db42 100644 --- a/src/clj/s3_beam/handler.clj +++ b/src/clj/s3_beam/handler.clj @@ -34,10 +34,23 @@ (.init (javax.crypto.spec.SecretKeySpec. (.getBytes key) "HmacSHA1"))) (.getBytes string "UTF-8")))) +(def zone->endpoint + "Mapping of AWS zones to S3 endpoints as documented here: + http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region" + {"us-east-1" "s3" + "us-west-1" "s3-us-west-1" + "us-west-2" "s3-us-west-2" + "eu-west-1" "s3-eu-west-1" + "eu-central-1" "s3-eu-central-1" + "ap-southeast-1" "s3-ap-southeast-1" + "ap-southeast-2" "s3-ap-southeast-2" + "ap-northeast-1" "s3-ap-northeast-1" + "sa-east-1" "s3-sa-east-1"}) + (defn sign-upload [{:keys [file-name mime-type]} {:keys [bucket aws-zone aws-access-key aws-secret-key]}] (let [p (policy bucket file-name mime-type)] - {:action (str "https://" bucket "." aws-zone ".amazonaws.com/") + {:action (str "https://" bucket "." (zone->endpoint aws-zone) ".amazonaws.com/") :key file-name :Content-Type mime-type :policy p From 4aa23127c8344bec6e30cc2b7b9bea5eed876ca8 Mon Sep 17 00:00:00 2001 From: Martin Klepsch Date: Mon, 15 Jun 2015 17:21:58 +0200 Subject: [PATCH 3/3] add assertion if zone cannot be mapped to endpoint --- src/clj/s3_beam/handler.clj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/clj/s3_beam/handler.clj b/src/clj/s3_beam/handler.clj index 9f5db42..534af3f 100644 --- a/src/clj/s3_beam/handler.clj +++ b/src/clj/s3_beam/handler.clj @@ -49,6 +49,7 @@ (defn sign-upload [{:keys [file-name mime-type]} {:keys [bucket aws-zone aws-access-key aws-secret-key]}] + (assert (zone->endpoint aws-zone) "No endpoint found for given AWS Zone") (let [p (policy bucket file-name mime-type)] {:action (str "https://" bucket "." (zone->endpoint aws-zone) ".amazonaws.com/") :key file-name