(currentNode *tview.TreeNode)
| 63 | } |
| 64 | |
| 65 | func exportADIDNSToFile(currentNode *tview.TreeNode) { |
| 66 | exportMap := make(map[string]any) |
| 67 | |
| 68 | currentNode.Walk(func(node, parent *tview.TreeNode) bool { |
| 69 | if node.GetReference() != nil { |
| 70 | objectDN := node.GetReference().(string) |
| 71 | |
| 72 | zone, zoneOk := zoneCache[objectDN] |
| 73 | node, nodeOk := nodeCache[objectDN] |
| 74 | |
| 75 | nodesMap := make(map[string]any, 0) |
| 76 | |
| 77 | if zoneOk { |
| 78 | zoneProps := make(map[string]any, 0) |
| 79 | for _, prop := range zone.Props { |
| 80 | propName := adidns.FindPropName(prop.Id) |
| 81 | zoneProps[propName] = prop.ExportFormat() |
| 82 | } |
| 83 | |
| 84 | exportMap[objectDN] = map[string]any{ |
| 85 | "Zone": map[string]any{ |
| 86 | "Name": zone.Name, |
| 87 | "DN": zone.DN, |
| 88 | "Props": zoneProps, |
| 89 | }, |
| 90 | "Nodes": nodesMap, |
| 91 | } |
| 92 | } else if nodeOk { |
| 93 | records := node.Records |
| 94 | |
| 95 | recordsObj := make([]any, 0) |
| 96 | for _, rec := range records { |
| 97 | recordType := rec.PrintType() |
| 98 | recordsObj = append(recordsObj, map[string]any{ |
| 99 | "Type": recordType, |
| 100 | "Value": rec, |
| 101 | "Data": rec.GetRecordData(), |
| 102 | }) |
| 103 | } |
| 104 | |
| 105 | parentZone, err := getParentZone(objectDN) |
| 106 | if err == nil { |
| 107 | // Since we're walking the tree it's safe to assume that |
| 108 | // zones will come before their child nodes, therefore |
| 109 | // all zone exports will fall in the alreadyExported branch |
| 110 | // The only way to get the other branch (alreadyExported) is if |
| 111 | // the user exports a node itself, in which case |
| 112 | // we must fetch the parent zone's properties |
| 113 | // to include in the export |
| 114 | _, alreadyExported := exportMap[parentZone.DN] |
| 115 | if !alreadyExported { |
| 116 | parentZoneProps := make(map[string]any, 0) |
| 117 | for _, prop := range parentZone.Props { |
| 118 | propName := adidns.FindPropName(prop.Id) |
| 119 | parentZoneProps[propName] = prop.ExportFormat() |
| 120 | } |
| 121 | |
| 122 | exportMap[parentZone.DN] = map[string]any{ |
no test coverage detected