MCPcopy Create free account
hub / github.com/Macmod/godap / exportADIDNSToFile

Function exportADIDNSToFile

tui/dns.go:65–145  ·  view source on GitHub ↗
(currentNode *tview.TreeNode)

Source from the content-addressed store, hash-verified

63}
64
65func 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{

Callers 1

initADIDNSPageFunction · 0.85

Calls 6

FindPropNameFunction · 0.92
getParentZoneFunction · 0.85
writeDataExportFunction · 0.85
ExportFormatMethod · 0.80
PrintTypeMethod · 0.80
GetRecordDataMethod · 0.80

Tested by

no test coverage detected