From de5f76a0cf4c5d122761320eb934d1dc89db22a7 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 2 Mar 2021 22:54:55 +0100 Subject: aws/request: Add parameterize-request-uri. * aws/request.scm (parameterize-request-uri): New procedure. (make-operation->request)[canonical-uri]: Use it. --- aws/request.scm | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'aws/request.scm') 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) -- cgit v1.2.3