-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support get app info Signed-off-by: ysicing <[email protected]>
- Loading branch information
Showing
6 changed files
with
146 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright (c) 2021-2022 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved. | ||
// Use of this source code is covered by the following dual licenses: | ||
// (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2) | ||
// (2) Affero General Public License 3.0 (AGPL 3.0) | ||
// license that can be found in the LICENSE file. | ||
|
||
package debug | ||
|
||
type APP struct{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
// Copyright (c) 2021-2022 北京渠成软件有限公司(Beijing Qucheng Software Co., Ltd. www.qucheng.com) All rights reserved. | ||
// Use of this source code is covered by the following dual licenses: | ||
// (1) Z PUBLIC LICENSE 1.2 (ZPL 1.2) | ||
// (2) Affero General Public License 3.0 (AGPL 3.0) | ||
// license that can be found in the LICENSE file. | ||
|
||
package debug | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/easysoft/qcadmin/common" | ||
"github.com/easysoft/qcadmin/internal/app/config" | ||
"github.com/easysoft/qcadmin/internal/pkg/k8s" | ||
"github.com/ergoapi/util/exnet" | ||
"github.com/imroc/req/v3" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
type Result struct { | ||
Code int `json:"code"` | ||
Message string `json:"message"` | ||
Data AppData `json:"data"` | ||
} | ||
|
||
type AppData struct { | ||
ID string `json:"id"` | ||
Space string `json:"space"` | ||
Name string `json:"name"` | ||
AppID string `json:"appID"` | ||
AppName string `json:"appName"` | ||
AppVersion string `json:"appVersion"` | ||
Chart string `json:"chart"` | ||
Logo string `json:"logo"` | ||
Version string `json:"version"` | ||
Source string `json:"source"` | ||
K8Name string `json:"k8name"` | ||
Status string `json:"status"` | ||
Domain string `json:"domain"` | ||
CreatedBy string `json:"createdBy"` | ||
CreatedAt string `json:"createdAt"` | ||
Deleted string `json:"deleted"` | ||
} | ||
|
||
func GetNameByURL(url string) (*AppData, error) { | ||
// 获取ID | ||
k := strings.Split(url, "-") | ||
key := strings.Trim(k[len(k)-1], ".html") | ||
|
||
cfg, _ := config.LoadConfig() | ||
if cfg.Token == "" { | ||
k8sClient, err := k8s.NewSimpleClient() | ||
if err != nil { | ||
return nil, err | ||
} | ||
cneapiDeploy, err := k8sClient.GetDeployment(context.Background(), common.DefaultSystem, "qucheng", metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
for _, e := range cneapiDeploy.Spec.Template.Spec.Containers[0].Env { | ||
if e.Name == "CNE_API_TOKEN" { | ||
cfg.APIToken = e.Value | ||
break | ||
} | ||
} | ||
cfg.SaveConfig() | ||
} | ||
|
||
if cfg.Domain == "" { | ||
cfg.Domain = fmt.Sprintf("%s:32379", exnet.LocalIPs()[0]) | ||
} | ||
|
||
client := req.C() | ||
client = client.DevMode().EnableDumpAll() | ||
var result Result | ||
resp, err := client.R(). | ||
SetHeader("accept", "application/json"). | ||
SetHeader("TOKEN", cfg.APIToken). | ||
Get(fmt.Sprintf("http://%s//instance-apidetail-%s.html", cfg.Domain, key)) | ||
if err != nil { | ||
return nil, fmt.Errorf("update password failed, reason: %v", err) | ||
} | ||
if !resp.IsSuccess() { | ||
return nil, fmt.Errorf("update password failed, reason: bad response status %v", resp.Status) | ||
} | ||
json.Unmarshal([]byte(resp.String()), &result) | ||
return &result.Data, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters