summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2021-03-02 22:54:55 +0100
committerRicardo Wurmus <rekado@elephly.net>2021-03-02 22:54:55 +0100
commitde5f76a0cf4c5d122761320eb934d1dc89db22a7 (patch)
treefd7d7d57fd42ad5a4b4b3ab81cec2c4e7f1d9cd7
parentf47201d72e9144f9070e916d1cafa745509f31c4 (diff)
aws/request: Add parameterize-request-uri.
* aws/request.scm (parameterize-request-uri): New procedure. (make-operation->request)[canonical-uri]: Use it.
-rw-r--r--aws/request.scm27
1 files changed, 23 insertions, 4 deletions
diff --git a/aws/request.scm b/aws/request.scm
index 9b36d5d..95dcfd1 100644
--- a/aws/request.scm
+++ b/aws/request.scm
@@ -168,6 +168,24 @@ operation name."
already mentioned in the request headers."
(scm->json-string (input-arguments->scm input)))
+(define (parameterize-request-uri request-format-string input)
+ "Process the format string URL in REQUEST-FORMAT-STRING and replace
+all placeholders (strings surrounded by curly braces) with their
+corresponding value in INPUT."
+ (let ((arguments (pk 'args (input-arguments->scm input)))
+ (parts (pk 'parts (string-split request-format-string (char-set #\{ #\})))))
+ ;; Every second item corresponds to a placeholder.
+ (string-join (map (lambda (part index)
+ (if (odd? index)
+ (or (assoc-ref arguments part)
+ (error (format #false
+ "Cannot parameterize URL `~a'; missing value `~a'~%"
+ request-format-string part)))
+ part))
+ parts
+ (iota (length parts)))
+ "")))
+
(define* (make-operation->request api-metadata)
"Return a procedure that accepts an operation and returns an HTTP request."
(define endpoint-prefix
@@ -231,10 +249,11 @@ already mentioned in the request headers."
;; https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html
-
- ;; TODO: Create canonical URI--the part of the URI from domain to query
- ;; string (use '/' if no path)
- (define canonical-uri "/")
+ (define canonical-uri
+ (or (and=> (assoc-ref http "requestUri")
+ (lambda (format-string)
+ (parameterize-request-uri format-string input)))
+ "/"))
(define headers
(filter cdr `((content-type . ,content-type)