diff --git a/API/controllers/entity.go b/API/controllers/entity.go index 7c6f6a81..accdb8f4 100644 --- a/API/controllers/entity.go +++ b/API/controllers/entity.go @@ -267,31 +267,32 @@ func getBulkDomainsRecursively(parent string, listDomains []map[string]interface domainsToCreate = append(domainsToCreate, domainObj) // Add children domain, if any - if children, ok := domain["domains"].([]interface{}); ok { - if len(children) > 0 { - // Convert from interface to map - dChildren := listAnyTolistMap(children) - - // Set parentId for children - var parentId string - if parent == "" { - parentId = domain["name"].(string) - } else { - parentId = parent + "." + domain["name"].(string) - } + if children, ok := domain["domains"].([]interface{}); ok && len(children) > 0 { + // Convert from interface to map + dChildren := listAnyTolistMap(children) - // Add children - childDomains, e := getBulkDomainsRecursively(parentId, dChildren) - if e != nil { - return nil, e - } - domainsToCreate = append(domainsToCreate, childDomains...) + parentId := setParentId(parent, domain) + + // Add children + childDomains, e := getBulkDomainsRecursively(parentId, dChildren) + if e != nil { + return nil, e } + domainsToCreate = append(domainsToCreate, childDomains...) } } return domainsToCreate, nil } +// Set parentId from parent & domain name +func setParentId(parent string, domain map[string]interface{}) string { + if parent == "" { + return domain["name"].(string) + } else { + return parent + "." + domain["name"].(string) + } +} + func setDomainAttributes(parent string, domain map[string]any) (map[string]any, error) { domainObj := map[string]any{} // Name is the only required attribute