buildNestedMap converts a flat map with dot-delimited keys into a nested map, e.g. {"okta.oauth2.issuer": "x"} -> {"okta": {"oauth2": {"issuer": "x"}}}.
(flat map[string]string)
| 1606 | // buildNestedMap converts a flat map with dot-delimited keys into a nested map, |
| 1607 | // e.g. {"okta.oauth2.issuer": "x"} -> {"okta": {"oauth2": {"issuer": "x"}}}. |
| 1608 | func buildNestedMap(flat map[string]string) map[string]interface{} { |
| 1609 | result := make(map[string]interface{}) |
| 1610 | for key, value := range flat { |
| 1611 | parts := strings.Split(key, ".") |
| 1612 | current := result |
| 1613 | for i, part := range parts { |
| 1614 | if i == len(parts)-1 { |
| 1615 | if _, alreadyMap := current[part].(map[string]interface{}); !alreadyMap { |
| 1616 | current[part] = value |
| 1617 | } |
| 1618 | } else { |
| 1619 | next, ok := current[part].(map[string]interface{}) |
| 1620 | if !ok { |
| 1621 | next = make(map[string]interface{}) |
| 1622 | current[part] = next |
| 1623 | } |
| 1624 | current = next |
| 1625 | } |
| 1626 | } |
| 1627 | } |
| 1628 | return result |
| 1629 | } |
| 1630 | |
| 1631 | // xmlEscape replaces XML/HTML special characters with their entity equivalents |
| 1632 | // so that generated XML config files are well-formed even when values contain |
no outgoing calls