feat(rdp): 新增 RDP 远程桌面/SMB/账单同步能力 + 清理编译产物
主要变更: - RDP 远程桌面:新增 backend/pkg/rdp(RDP 引擎 + credssp/display/rle/trace)、 backend/controller/rdp*(连接/凭证/文件/会话/实时)、frontend RDP 组件与 API - Windows SMB 文件传输:backend/pkg/winsmb - 云账单同步:backend/pkg/billingsync + billing_sync/aliyun_billing,前端账单详情 - Agent CLI Kubernetes 工具:kubernetes_action/get、pod_execute/logs - 服务器导入助手:server_import_helpers、ImportCredentialSettings - 国际化与组件重构(cloud/deploy/monitor/server/system 等多模块) - 清理编译产物二进制:移除 backend/server、backend/agent/bin/aiops-agent-* - .gitignore:新增 backend/agent/ 与 .cache/(避免 334MB go-build 缓存误入库) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
777d9e4e71
commit
76ec9387f0
202 files changed
+16555
-2543
No files matched your search
+43
-2
@@ -66,15 +66,56 @@ func (a *AliyunProvider) sign(params map[string]string) string {
|
||||
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||
}
|
||||
|
||||
// call 调用阿里云 RPC API
|
||||
// call 调用阿里云 ECS RPC API
|
||||
func (a *AliyunProvider) call(action string, extra map[string]string, endpoint string) ([]byte, error) {
|
||||
if endpoint == "" {
|
||||
endpoint = "https://ecs.aliyuncs.com/"
|
||||
}
|
||||
return a.callWithVersion(action, extra, endpoint, a.version)
|
||||
}
|
||||
|
||||
// aliyunBSSEndpoints BSS 国内站与国际站接入点(站点不匹配时需自动切换) // Logan.Li
|
||||
var aliyunBSSEndpoints = []string{
|
||||
"https://business.aliyuncs.com/", // 国内站 aliyun.com
|
||||
"https://business.ap-southeast-1.aliyuncs.com/", // 国际站 alibabacloud.com
|
||||
}
|
||||
|
||||
// callBSS 调用阿里云费用中心 BSS OpenAPI,自动适配国内/国际站 // Logan.Li
|
||||
func (a *AliyunProvider) callBSS(action string, extra map[string]string) ([]byte, error) {
|
||||
var lastErr error
|
||||
for _, endpoint := range aliyunBSSEndpoints {
|
||||
body, err := a.callWithVersion(action, extra, endpoint, "2017-12-14")
|
||||
if err == nil {
|
||||
return body, nil
|
||||
}
|
||||
if isAliyunBSSSiteMismatch(err) {
|
||||
lastErr = err
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
if lastErr != nil {
|
||||
return nil, fmt.Errorf("阿里云账单 API 站点不匹配(请确认 AK 属于国内站 aliyun.com 或国际站 alibabacloud.com): %w", lastErr)
|
||||
}
|
||||
return nil, fmt.Errorf("阿里云账单 API 调用失败")
|
||||
}
|
||||
|
||||
// isAliyunBSSSiteMismatch 判断是否为国内/国际站 endpoint 不匹配 // Logan.Li
|
||||
func isAliyunBSSSiteMismatch(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
msg := err.Error()
|
||||
return strings.Contains(msg, "NotApplicable") ||
|
||||
strings.Contains(msg, "caller site") ||
|
||||
strings.Contains(msg, "regionId")
|
||||
}
|
||||
|
||||
// callWithVersion 通用阿里云 RPC 签名请求
|
||||
func (a *AliyunProvider) callWithVersion(action string, extra map[string]string, endpoint, version string) ([]byte, error) {
|
||||
params := map[string]string{
|
||||
"Format": "JSON",
|
||||
"Version": a.version,
|
||||
"Version": version,
|
||||
"AccessKeyId": a.accessKey,
|
||||
"SignatureMethod": "HMAC-SHA1",
|
||||
"Timestamp": time.Now().UTC().Format("2006-01-02T15:04:05Z"),
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package cloud
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// FetchDailyBill 拉取指定日期的阿里云日账单(按产品+地域聚合) // Logan.Li
|
||||
func (a *AliyunProvider) FetchDailyBill(billingDate string) ([]CloudBillingRecord, error) {
|
||||
if len(billingDate) != 10 {
|
||||
return nil, fmt.Errorf("账单日期格式应为 YYYY-MM-DD")
|
||||
}
|
||||
billingCycle := billingDate[:7]
|
||||
|
||||
type aggKey struct {
|
||||
service string
|
||||
region string
|
||||
}
|
||||
agg := map[aggKey]float64{}
|
||||
currency := "CNY"
|
||||
|
||||
pageNum := 1
|
||||
pageSize := 300
|
||||
totalCount := -1
|
||||
|
||||
for {
|
||||
body, err := a.callBSS("QueryInstanceBill", map[string]string{
|
||||
"BillingCycle": billingCycle,
|
||||
"BillingDate": billingDate,
|
||||
"Granularity": "DAILY",
|
||||
"PageNum": strconv.Itoa(pageNum),
|
||||
"PageSize": strconv.Itoa(pageSize),
|
||||
"IsHideZeroCharge": "true",
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp aliyunInstanceBillResponse
|
||||
if err := json.Unmarshal(body, &resp); err != nil {
|
||||
return nil, fmt.Errorf("解析账单响应失败: %w", err)
|
||||
}
|
||||
if !resp.Success && resp.Code != "Success" {
|
||||
msg := resp.Message
|
||||
if msg == "" {
|
||||
msg = string(body)
|
||||
}
|
||||
return nil, fmt.Errorf("阿里云账单 API 错误: %s", msg)
|
||||
}
|
||||
|
||||
if totalCount < 0 {
|
||||
totalCount = resp.Data.TotalCount
|
||||
}
|
||||
|
||||
items := normalizeBillItems(resp.Data.Items.Item)
|
||||
for _, it := range items {
|
||||
amount := it.PretaxAmount
|
||||
if amount <= 0 {
|
||||
amount = it.PaymentAmount
|
||||
}
|
||||
if amount <= 0 {
|
||||
continue
|
||||
}
|
||||
service := strings.TrimSpace(it.ProductName)
|
||||
if service == "" {
|
||||
service = strings.TrimSpace(it.ProductCode)
|
||||
}
|
||||
if service == "" {
|
||||
service = "其他"
|
||||
}
|
||||
region := strings.TrimSpace(it.Region)
|
||||
if region == "" {
|
||||
region = "全局"
|
||||
}
|
||||
key := aggKey{service: service, region: region}
|
||||
agg[key] += amount
|
||||
if it.Currency != "" {
|
||||
currency = it.Currency
|
||||
}
|
||||
}
|
||||
|
||||
if len(items) == 0 || pageNum*pageSize >= totalCount {
|
||||
break
|
||||
}
|
||||
pageNum++
|
||||
}
|
||||
|
||||
records := make([]CloudBillingRecord, 0, len(agg))
|
||||
for key, cost := range agg {
|
||||
records = append(records, CloudBillingRecord{
|
||||
BillingDate: billingDate,
|
||||
Provider: "aliyun",
|
||||
Cost: math.Round(cost*100) / 100,
|
||||
Currency: currency,
|
||||
Service: key.service,
|
||||
Region: key.region,
|
||||
Description: "云API自动同步(阿里云 QueryInstanceBill)",
|
||||
})
|
||||
}
|
||||
return records, nil
|
||||
}
|
||||
|
||||
type aliyunInstanceBillResponse struct {
|
||||
Code string `json:"Code"`
|
||||
Message string `json:"Message"`
|
||||
Success bool `json:"Success"`
|
||||
Data struct {
|
||||
TotalCount int `json:"TotalCount"`
|
||||
Items struct {
|
||||
Item json.RawMessage `json:"Item"`
|
||||
} `json:"Items"`
|
||||
} `json:"Data"`
|
||||
}
|
||||
|
||||
type aliyunBillItem struct {
|
||||
ProductCode string `json:"ProductCode"`
|
||||
ProductName string `json:"ProductName"`
|
||||
Region string `json:"Region"`
|
||||
PretaxAmount float64 `json:"PretaxAmount"`
|
||||
PaymentAmount float64 `json:"PaymentAmount"`
|
||||
Currency string `json:"Currency"`
|
||||
}
|
||||
|
||||
// normalizeBillItems 兼容 Item 为对象或数组两种返回格式 // Logan.Li
|
||||
func normalizeBillItems(raw json.RawMessage) []aliyunBillItem {
|
||||
if len(raw) == 0 || string(raw) == "null" {
|
||||
return nil
|
||||
}
|
||||
var items []aliyunBillItem
|
||||
if err := json.Unmarshal(raw, &items); err == nil {
|
||||
return items
|
||||
}
|
||||
var one aliyunBillItem
|
||||
if err := json.Unmarshal(raw, &one); err == nil {
|
||||
return []aliyunBillItem{one}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cloud
|
||||
|
||||
// CloudBillingRecord 云账单同步记录(跨平台统一结构) // Logan.Li
|
||||
type CloudBillingRecord struct {
|
||||
BillingDate string `json:"billing_date"`
|
||||
Provider string `json:"provider"`
|
||||
Cost float64 `json:"cost"`
|
||||
Currency string `json:"currency"`
|
||||
Service string `json:"service"`
|
||||
Region string `json:"region"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
// BillingFetcher 云账单拉取接口
|
||||
type BillingFetcher interface {
|
||||
FetchDailyBill(billingDate string) ([]CloudBillingRecord, error)
|
||||
}
|
||||
|
||||
// NewBillingFetcher 根据云厂商创建账单拉取器
|
||||
func NewBillingFetcher(provider, accessKey, secretKey string) BillingFetcher {
|
||||
switch provider {
|
||||
case "aliyun":
|
||||
if p := NewAliyunProvider(accessKey, secretKey); p != nil {
|
||||
return p
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in new issue
Block a user