(cmd *cobra.Command, domainLcuuid, domainName, resource string)
| 82 | } |
| 83 | |
| 84 | func getInfo(cmd *cobra.Command, domainLcuuid, domainName, resource string) { |
| 85 | if domainLcuuid == "" && domainName == "" { |
| 86 | fmt.Fprintf(os.Stderr, "must specify one of domain-lcuuid, domain-name.\nExample: %s\n", cmd.Example) |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | server := common.GetServerInfo(cmd) |
| 91 | lcuuid := domainLcuuid |
| 92 | if lcuuid == "" { |
| 93 | url := fmt.Sprintf("http://%s:%d/v2/domains/?name=%s", server.IP, server.Port, domainName) |
| 94 | resp, err := common.CURLResponseRawJson("GET", url, []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd)), common.WithORGID(common.GetORGID(cmd))}...) |
| 95 | if err != nil { |
| 96 | fmt.Println("get domain info by name failed.") |
| 97 | fmt.Fprintln(os.Stderr, err) |
| 98 | return |
| 99 | } |
| 100 | if len(resp.Get("DATA").MustArray()) == 0 { |
| 101 | fmt.Fprintln(os.Stderr, errors.New(fmt.Sprintf("domain name: %s not found", domainName))) |
| 102 | return |
| 103 | } |
| 104 | lcuuid = resp.Get("DATA").GetIndex(0).Get("LCUUID").MustString() |
| 105 | } |
| 106 | |
| 107 | podIP, err := common.ConvertControllerAddrToPodIP(server.IP, server.Port) |
| 108 | if err != nil { |
| 109 | fmt.Fprintln(os.Stderr, err) |
| 110 | return |
| 111 | } |
| 112 | |
| 113 | url := fmt.Sprintf("http://%s:%d/v1/info/%s/", podIP, server.SvcPort, lcuuid) |
| 114 | resp, err := common.CURLResponseRawJson("GET", url, []common.HTTPOption{common.WithTimeout(common.GetTimeout(cmd))}...) |
| 115 | if err != nil { |
| 116 | fmt.Fprintln(os.Stderr, err) |
| 117 | return |
| 118 | } |
| 119 | data := resp.Get("DATA") |
| 120 | if resource == "" { |
| 121 | common.PrettyPrint(data) |
| 122 | } else { |
| 123 | resources := strings.Split(resource, ",") |
| 124 | for _, r := range resources { |
| 125 | fmt.Println(r) |
| 126 | domainData := data.Get(r) |
| 127 | for i := range domainData.MustArray() { |
| 128 | common.PrettyPrint(domainData.GetIndex(i)) |
| 129 | } |
| 130 | subDomainResources := data.Get("SubDomainResources").MustMap() |
| 131 | for _, subDomainData := range subDomainResources { |
| 132 | rscData, ok := subDomainData.(map[string]interface{})[r] |
| 133 | if !ok || rscData == nil { |
| 134 | continue |
| 135 | } |
| 136 | for _, d := range rscData.([]interface{}) { |
| 137 | common.PrettyPrint(d) |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | } |
no test coverage detected