From 042bbccd1a43cacd85c2fdb7e159c5a31b4fbd3a Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Thu, 14 Jun 2018 19:43:18 -0500 Subject: [PATCH] s3: Fix get-object to allow signing. Add sorted-bucket to sort by time. --- extra/s3/s3.factor | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) diff --git a/extra/s3/s3.factor b/extra/s3/s3.factor index 6977fac032..153d638ca1 100644 --- a/extra/s3/s3.factor +++ b/extra/s3/s3.factor @@ -1,26 +1,9 @@ ! Copyright (C) 2009 Chris Double. All Rights Reserved. ! See http://factorcode.org/license.txt for BSD license. -USING: - accessors - assocs - base64 - calendar - calendar.format - checksums.hmac - checksums.sha - combinators - http - http.client - kernel - make - math.order - namespaces - sequences - sorting - strings - xml - xml.traversal -; +USING: accessors assocs base64 calendar calendar.format +calendar.parser checksums.hmac checksums.sha combinators http +http.client kernel make math.order namespaces sequences +sequences.extras sorting sorting.slots strings xml xml.traversal ; IN: s3 SYMBOL: key-id @@ -28,7 +11,7 @@ SYMBOL: secret-key headers ( hashtable -- seq ) [ @@ -100,6 +83,9 @@ PRIVATE> : buckets ( -- seq ) f "/" H{ } clone s3-get nip >string string>xml (buckets) ; +: sorted-buckets ( -- seq ) + buckets { { date>> rfc3339>timestamp <=> } } sort-by ; + nip >string string>xml (keys) ; : get-object ( bucket key -- response data ) - s3-request new - swap "/" prepend >>path - swap >>bucket - s3-url http-get ; + "/" prepend H{ } clone s3-get ; : create-bucket ( bucket -- ) "" swap "/" H{ } clone "PUT" @@ -151,3 +134,7 @@ PRIVATE> : delete-object ( bucket key -- ) "/" prepend H{ } clone "DELETE" dup s3-url sign-http-request http-request 2drop ; + +: bucket>alist ( bucket -- alist ) + dup keys + [ name>> get-object nip ] with map-zip ; \ No newline at end of file