101 lines
2.9 KiB
Go
101 lines
2.9 KiB
Go
package sandbox
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/httpdns/httpdnsutils"
|
|
"github.com/iwind/TeaGo/maps"
|
|
)
|
|
|
|
type IndexAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *IndexAction) Init() {
|
|
this.Nav("httpdns", "sandbox", "")
|
|
}
|
|
|
|
func (this *IndexAction) RunGet(params struct{}) {
|
|
httpdnsutils.AddLeftMenu(this.Parent())
|
|
|
|
clusterResp, err := this.RPC().HTTPDNSClusterRPC().FindAllHTTPDNSClusters(this.UserContext(), &pb.FindAllHTTPDNSClustersRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
clusters := make([]maps.Map, 0, len(clusterResp.GetClusters()))
|
|
for _, cluster := range clusterResp.GetClusters() {
|
|
serviceDomain := strings.TrimSpace(cluster.GetServiceDomain())
|
|
|
|
port := "443"
|
|
if rawTLS := cluster.GetTlsPolicyJSON(); len(rawTLS) > 0 {
|
|
var tlsConfig map[string]interface{}
|
|
if err := json.Unmarshal(rawTLS, &tlsConfig); err == nil {
|
|
if listenRaw, ok := tlsConfig["listen"]; ok && listenRaw != nil {
|
|
if data, err := json.Marshal(listenRaw); err == nil {
|
|
var listenAddresses []map[string]interface{}
|
|
if err := json.Unmarshal(data, &listenAddresses); err == nil {
|
|
if len(listenAddresses) > 0 {
|
|
if portRange, ok := listenAddresses[0]["portRange"].(string); ok && len(portRange) > 0 {
|
|
port = portRange
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
apiAddress := "https://" + serviceDomain + ":" + port
|
|
|
|
displayName := apiAddress
|
|
if len(serviceDomain) == 0 {
|
|
displayName = cluster.GetName()
|
|
}
|
|
clusters = append(clusters, maps.Map{
|
|
"id": cluster.GetId(),
|
|
"name": cluster.GetName(),
|
|
"serviceDomain": serviceDomain,
|
|
"displayName": displayName,
|
|
})
|
|
}
|
|
this.Data["clusters"] = clusters
|
|
|
|
appResp, err := this.RPC().HTTPDNSAppRPC().FindAllHTTPDNSApps(this.UserContext(), &pb.FindAllHTTPDNSAppsRequest{})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
apps := make([]maps.Map, 0, len(appResp.GetApps()))
|
|
for _, app := range appResp.GetApps() {
|
|
domainResp, err := this.RPC().HTTPDNSDomainRPC().ListHTTPDNSDomainsWithAppId(this.UserContext(), &pb.ListHTTPDNSDomainsWithAppIdRequest{
|
|
AppDbId: app.GetId(),
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
domains := make([]string, 0, len(domainResp.GetDomains()))
|
|
for _, domain := range domainResp.GetDomains() {
|
|
domains = append(domains, domain.GetDomain())
|
|
}
|
|
// 解析集群ID列表
|
|
var clusterIds []int64
|
|
if len(app.GetClusterIdsJSON()) > 0 {
|
|
_ = json.Unmarshal(app.GetClusterIdsJSON(), &clusterIds)
|
|
}
|
|
|
|
apps = append(apps, maps.Map{
|
|
"id": app.GetId(),
|
|
"name": app.GetName(),
|
|
"appId": app.GetAppId(),
|
|
"clusterIds": clusterIds,
|
|
"domains": domains,
|
|
})
|
|
}
|
|
this.Data["apps"] = apps
|
|
this.Show()
|
|
}
|