serialize: Upcase the first letter of any property name.
authorRicardo Wurmus <rekado@elephly.net>
Thu, 18 Mar 2021 13:30:37 +0000 (14:30 +0100)
committerRicardo Wurmus <rekado@elephly.net>
Thu, 18 Mar 2021 13:30:37 +0000 (14:30 +0100)
aws/serialize.scm
tests/serialize.scm

index e9a138279198c83bcede02c0f1504aa158b518e9..f6d12fd259c459a909f684b0acec5af216d98672 100644 (file)
 
 ;; See https://docs.aws.amazon.com/AWSEC2/latest/APIReference/Query-Requests.html
 (define* (serialize-aws-value thing)
+  ;; XXX: I don't know why this is necessary, but it seems to be
+  ;; required that the locationName begin with an uppercase letter.
+  ;; There is nothing in the specification that would hint at this,
+  ;; but testing against the AWS API have revealed this to be the
+  ;; case.  This is at least true for "Value" and "Key" of a "Tag"
+  ;; value, and for "ResourceType" of a "TagSpecification".
+  (define (up string)
+    (let ((s (format #false "~a" string)))
+      (string-set! s 0 (char-upcase (string-ref s 0)))
+      s))
   (define inner
     (lambda (path thing)
       (cond
@@ -63,7 +73,7 @@
 
        (else
         (format #false "~{~a~^.~}=~a"
-                (reverse (filter identity path))
+                (map up (reverse (filter identity path)))
                 thing)))))
   (define (flatten lst)
     (match lst
index ef851bab8bfbdb6d24ac441206eee5a4d78bdcc3..5867edb1924d0e4c69d844d1e288e2db59be3bef 100644 (file)
@@ -54,15 +54,15 @@ given by REPLACEMENT."
 
 (test-equal "simple query serialization with nested structures"
   '("ImageId=ami-72aa081b" "MaxCount=1" "MinCount=1"
-    "TagSpecification.1.resourceType=instance"
-    "TagSpecification.1.Tag.1.key=project"
-    "TagSpecification.1.Tag.1.value=pigx-web"
-    "TagSpecification.1.Tag.2.key=pigx-web:resource"
-    "TagSpecification.1.Tag.2.value=user-vm"
-    "TagSpecification.1.Tag.3.key=pigx-web:username"
-    "TagSpecification.1.Tag.3.value=username"
-    "TagSpecification.1.Tag.4.key=pigx-web:project"
-    "TagSpecification.1.Tag.4.value=project")
+    "TagSpecification.1.ResourceType=instance"
+    "TagSpecification.1.Tag.1.Key=project"
+    "TagSpecification.1.Tag.1.Value=pigx-web"
+    "TagSpecification.1.Tag.2.Key=pigx-web:resource"
+    "TagSpecification.1.Tag.2.Value=user-vm"
+    "TagSpecification.1.Tag.3.Key=pigx-web:username"
+    "TagSpecification.1.Tag.3.Value=username"
+    "TagSpecification.1.Tag.4.Key=pigx-web:project"
+    "TagSpecification.1.Tag.4.Value=project")
   (serialize-aws-value (RunInstancesRequest
                         #:ImageId "ami-72aa081b"
                         #:MinCount 1