]> www.average.org Git - pdns-pipe-nmc.git/commitdiff
document dots in the keys in the map, drop empty elems
authorEugene Crosser <crosser@average.org>
Tue, 22 Apr 2014 21:27:59 +0000 (01:27 +0400)
committerEugene Crosser <crosser@average.org>
Tue, 22 Apr 2014 21:27:59 +0000 (01:27 +0400)
NmcTransform.hs
SPEC.md
d/extra1

index de6fc0f3e82172475c5b722968199e9ad5cb81c3..7138bf91bd954a29cfd271bc6ee1c022b02a6536 100644 (file)
@@ -117,7 +117,8 @@ splitSubdoms base =
           stow fqdn sdom acc = insertWith mergeNmcDom fqdn' sdom' acc
             where
               (fqdn', sdom') =
           stow fqdn sdom acc = insertWith mergeNmcDom fqdn' sdom' acc
             where
               (fqdn', sdom') =
-                nest (map unpack (splitOn (pack ".") (pack fqdn)), sdom)
+                nest (filter (/= "") (splitOnDots fqdn), sdom)
+              splitOnDots s = map unpack (splitOn (pack ".") (pack s))
               nest ([], v)   = (fqdn, v) -- can split result be empty?
               nest ([k], v)  = (k, v)
               nest (k:ks, v) =
               nest ([], v)   = (fqdn, v) -- can split result be empty?
               nest ([k], v)  = (k, v)
               nest (k:ks, v) =
diff --git a/SPEC.md b/SPEC.md
index 1c1292ce803bf65d6558f3bd641045cdbd72768c..b93a852a339847b29931c173766510d216908c45 100644 (file)
--- a/SPEC.md
+++ b/SPEC.md
@@ -307,9 +307,6 @@ the current domain object.
 
 #### map attribute
 
 
 #### map attribute
 
-FIXME - explain handling of the keys with dots.
-Also, add checks to the code to disallow empty elements.
-
 JSON Map object containing subdomain names as its keys and domain
 objects as values. Element of the map with empty key "" has special
 meaning: the value of this map element is merged into the current
 JSON Map object containing subdomain names as its keys and domain
 objects as values. Element of the map with empty key "" has special
 meaning: the value of this map element is merged into the current
@@ -322,11 +319,32 @@ the empty element of the `"map"` has been recursively merged into
 the current object.
 
 ```
 the current object.
 
 ```
-"map": { "www": { "alias" : "www.example.com." }
+"map": { "www": { "alias" : "www.example.com" }
        , "www2": { "delegate": "d/example" }
        }
 ```
 
        , "www2": { "delegate": "d/example" }
        }
 ```
 
+Note: When a key contains dots ".", it is converted to a nested
+map.  If empty element appears as a result of split, such as when
+a dot is at the beginning or at the end of the key, or there are
+consequitive dots, such elemets are ignored. For example,
+
+```
+"map": { "www.uk": { "alias" : "www.example.co.uk" }
+       , "www..us": { "alias" : "www.example.com" }
+       , "smtp.us.": { "alias" : "smtp.example.com" }
+```
+
+is equivalent to
+
+```
+"map": { "uk": { "map": { "www": { "alias" : "www.example.co.uk" }}}
+       , "us": { "map": { "www": { "alias" : "www.example.com" }
+                       , "smtp": { "alias" : "smtp.example.com" }}
+              }
+       }
+```
+
 #### fingerprint attribute
 
 Does not translate into any DNS RR. Contains a list of TLS
 #### fingerprint attribute
 
 Does not translate into any DNS RR. Contains a list of TLS
index 32ec73eb57649c40d1af3a5abef6d67358ab1df6..b1fc2138733c132c3242fdf5c4e7d744abb3e2d6 100644 (file)
--- a/d/extra1
+++ b/d/extra1
@@ -1 +1 @@
-{"service":[["smtp", "tcp", 0, 0, 25, "mail.host.com."]],"import":["d/extra2","d/extra3"],"ip":["1.2.3.4"],"alias":"extra1alias","map":{"mail":"1.1.1.1","www":"1.1.1.1","smtp.eu":{"ip6":"dead::0002"},"eu":{"map":{"smtp":{"ip6":["dead::0001"]}}}}}
+{"service":[["smtp", "tcp", 0, 0, 25, "mail.host.com."]],"import":["d/extra2","d/extra3"],"ip":["1.2.3.4"],"alias":"extra1alias","map":{"mail":"1.1.1.1","www":"1.1.1.1","smtp.eu":{"ip6":"dead::0002"},"smtp..eu.":{"ip6":"dead::0003"},"eu":{"map":{"smtp":{"ip6":["dead::0001"]}}}}}