Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly resolve zone endpoints #10

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject org.martinklepsch/s3-beam "0.3.0"
(defproject org.martinklepsch/s3-beam "0.3.0-SNAPSHOT"
:author "Martin Klepsch <http://www.martinklepsch.org>"
:description "CORS Upload to S3 via Clojure(script)"
:url "http://github.com/martinklepsch/s3-beam"
Expand Down
16 changes: 15 additions & 1 deletion src/clj/s3_beam/handler.clj
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,24 @@
(.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]}]
(assert (zone->endpoint aws-zone) "No endpoint found for given AWS Zone")
(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
Expand Down