From 419d06258d71978c934398633a644c5842e83b92 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Wed, 23 Apr 2014 01:27:59 +0400 Subject: [PATCH] document dots in the keys in the map, drop empty elems --- NmcTransform.hs | 3 ++- SPEC.md | 26 ++++++++++++++++++++++---- d/extra1 | 2 +- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/NmcTransform.hs b/NmcTransform.hs index de6fc0f..7138bf9 100644 --- a/NmcTransform.hs +++ b/NmcTransform.hs @@ -117,7 +117,8 @@ splitSubdoms base = 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) = diff --git a/SPEC.md b/SPEC.md index 1c1292c..b93a852 100644 --- a/SPEC.md +++ b/SPEC.md @@ -307,9 +307,6 @@ the current domain object. #### 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 @@ -322,11 +319,32 @@ the empty element of the `"map"` has been recursively merged into the current object. ``` -"map": { "www": { "alias" : "www.example.com." } +"map": { "www": { "alias" : "www.example.com" } , "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 diff --git a/d/extra1 b/d/extra1 index 32ec73e..b1fc213 100644 --- 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"]}}}}} -- 2.39.2