(dstRoot, srcRoot *yaml.Node, keyPath ...string)
| 1809 | } |
| 1810 | |
| 1811 | func pruneMappingToGeneratedKeys(dstRoot, srcRoot *yaml.Node, keyPath ...string) { |
| 1812 | if len(keyPath) == 0 || dstRoot == nil || srcRoot == nil { |
| 1813 | return |
| 1814 | } |
| 1815 | if len(keyPath) > 1 { |
| 1816 | dstParent := dstRoot |
| 1817 | srcParent := srcRoot |
| 1818 | for _, key := range keyPath[:len(keyPath)-1] { |
| 1819 | if key == "" || dstParent == nil || dstParent.Kind != yaml.MappingNode { |
| 1820 | return |
| 1821 | } |
| 1822 | dstIdx := findMapKeyIndex(dstParent, key) |
| 1823 | if dstIdx < 0 || dstIdx+1 >= len(dstParent.Content) { |
| 1824 | return |
| 1825 | } |
| 1826 | dstParent = dstParent.Content[dstIdx+1] |
| 1827 | |
| 1828 | if srcParent != nil && srcParent.Kind == yaml.MappingNode { |
| 1829 | srcIdx := findMapKeyIndex(srcParent, key) |
| 1830 | if srcIdx >= 0 && srcIdx+1 < len(srcParent.Content) { |
| 1831 | srcParent = srcParent.Content[srcIdx+1] |
| 1832 | } else { |
| 1833 | srcParent = nil |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | if srcParent == nil || srcParent.Kind != yaml.MappingNode { |
| 1838 | removeMapKey(dstParent, keyPath[len(keyPath)-1]) |
| 1839 | return |
| 1840 | } |
| 1841 | pruneMappingToGeneratedKeys(dstParent, srcParent, keyPath[len(keyPath)-1]) |
| 1842 | return |
| 1843 | } |
| 1844 | key := keyPath[0] |
| 1845 | if key == "" { |
| 1846 | return |
| 1847 | } |
| 1848 | if dstRoot.Kind != yaml.MappingNode || srcRoot.Kind != yaml.MappingNode { |
| 1849 | return |
| 1850 | } |
| 1851 | dstIdx := findMapKeyIndex(dstRoot, key) |
| 1852 | if dstIdx < 0 || dstIdx+1 >= len(dstRoot.Content) { |
| 1853 | return |
| 1854 | } |
| 1855 | srcIdx := findMapKeyIndex(srcRoot, key) |
| 1856 | if srcIdx < 0 { |
| 1857 | // Keep an explicit empty mapping for oauth-model-alias when it was previously present. |
| 1858 | // When users delete the last channel from oauth-model-alias via the management API, |
| 1859 | // we want that deletion to persist across hot reloads and restarts. |
| 1860 | if key == "oauth-model-alias" { |
| 1861 | dstRoot.Content[dstIdx+1] = &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"} |
| 1862 | return |
| 1863 | } |
| 1864 | removeMapKey(dstRoot, key) |
| 1865 | return |
| 1866 | } |
| 1867 | if srcIdx+1 >= len(srcRoot.Content) { |
| 1868 | return |
no test coverage detected