github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/api/container/containerv2/nlbdns.go (about) 1 package containerv2 2 3 import ( 4 "encoding/json" 5 "fmt" 6 7 "github.com/IBM-Cloud/bluemix-go/client" 8 ) 9 10 type nlbdns struct { 11 client *client.Client 12 } 13 14 //Clusters interface 15 type Nlbdns interface { 16 GetNLBDNSList(clusterNameOrID string) ([]NlbVPCListConfig, error) 17 GetLocationNLBDNSList(location string) ([]NlbVPCListConfig, error) 18 } 19 type NlbVPCListConfig struct { 20 // ExtendedNlbVPCConfig is the response body for the get v2 vpc apis. 21 Nlb ExtendedNlbVPCConfig `json:"Nlb,omitempty"` 22 23 SecretName string `json:"secretName,omitempty"` 24 25 SecretStatus string `json:"secretStatus,omitempty"` 26 } 27 type ExtendedNlbVPCConfig struct { 28 Cluster string `json:"cluster,omitempty"` 29 30 DnsType string `json:"dnsType,omitempty"` 31 32 LbHostname string `json:"lbHostname,omitempty"` 33 34 NlbIPArray []interface{} `json:"nlbIPArray,omitempty"` 35 36 NlbSubdomain string `json:"nlbSubdomain,omitempty"` 37 38 SecretNamespace string `json:"secretNamespace,omitempty"` 39 NlbMonitorState string `json:"nlbMonitorState,omitempty"` 40 41 Type string `json:"type,omitempty"` 42 } 43 44 func newNlbdnsAPI(c *client.Client) Nlbdns { 45 return &nlbdns{ 46 client: c, 47 } 48 } 49 50 // GetNLBDNSList returns the list of NLBDNS available for cluster 51 func (r *nlbdns) GetNLBDNSList(clusterNameOrID string) ([]NlbVPCListConfig, error) { 52 var success []NlbVPCListConfig 53 var successV []interface{} 54 rawURL := fmt.Sprintf("/v2/nlb-dns/getNlbDNSList?cluster=%s", clusterNameOrID) 55 _, err := r.client.Get(rawURL, &successV) 56 if err != nil { 57 return success, err 58 } 59 if len(successV) > 0 { 60 if _, isVpc := successV[0].(map[string]interface{})["Nlb"]; isVpc { 61 bodyBytes, _ := json.Marshal(successV) 62 json.Unmarshal(bodyBytes, &success) 63 } else { 64 nlb := NlbVPCListConfig{} 65 for _, s := range successV { 66 b := s.(map[string]interface{}) 67 nlb.SecretName = b["nlbSslSecretName"].(string) 68 nlb.SecretStatus = b["nlbSslSecretStatus"].(string) 69 nlb.Nlb.Cluster = b["clusterID"].(string) 70 nlb.Nlb.Type = b["nlbType"].(string) 71 nlb.Nlb.DnsType = b["nlbDnsType"].(string) 72 nlb.Nlb.NlbSubdomain = b["nlbHost"].(string) 73 nlb.Nlb.SecretNamespace = b["secretNamespace"].(string) 74 nlb.Nlb.NlbIPArray = b["nlbIPArray"].([]interface{}) 75 nlb.Nlb.NlbMonitorState = b["nlbMonitorState"].(string) 76 success = append(success, nlb) 77 } 78 } 79 } 80 return success, err 81 } 82 func (r *nlbdns) GetLocationNLBDNSList(location string) ([]NlbVPCListConfig, error) { 83 var success []NlbVPCListConfig 84 var successV []interface{} 85 rawURL := fmt.Sprintf("/v2/nlb-dns/getSatLocationSubdomains?controller=%s", location) 86 _, err := r.client.Get(rawURL, &successV) 87 if err != nil { 88 return success, err 89 } 90 if len(successV) > 0 { 91 if _, isVpc := successV[0].(map[string]interface{})["Nlb"]; isVpc { 92 bodyBytes, _ := json.Marshal(successV) 93 json.Unmarshal(bodyBytes, &success) 94 } else { 95 nlb := NlbVPCListConfig{} 96 for _, s := range successV { 97 b := s.(map[string]interface{}) 98 nlb.SecretName = b["nlbSslSecretName"].(string) 99 nlb.SecretStatus = b["nlbSslSecretStatus"].(string) 100 nlb.Nlb.Cluster = b["clusterID"].(string) 101 nlb.Nlb.Type = b["nlbType"].(string) 102 nlb.Nlb.DnsType = b["nlbDnsType"].(string) 103 nlb.Nlb.NlbSubdomain = b["nlbHost"].(string) 104 nlb.Nlb.SecretNamespace = b["secretNamespace"].(string) 105 nlb.Nlb.NlbIPArray = b["nlbIPArray"].([]interface{}) 106 nlb.Nlb.NlbMonitorState = b["nlbMonitorState"].(string) 107 success = append(success, nlb) 108 } 109 } 110 } 111 return success, err 112 }