2025-03-09 12:06:14 +08:00
|
|
|
|
package secret
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/infraboard/mcube/v2/http/request"
|
|
|
|
|
"github.com/infraboard/mcube/v2/ioc"
|
|
|
|
|
"github.com/infraboard/mcube/v2/tools/pretty"
|
|
|
|
|
"github.com/infraboard/mcube/v2/types"
|
2025-03-09 18:14:54 +08:00
|
|
|
|
"gitlab.com/go-course-project/go17/devcloud-mini/cmdb/apps/resource"
|
2025-03-09 12:06:14 +08:00
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
AppName = "secret"
|
|
|
|
|
SECRET_KEY = "23gs6gxHrz1kNEvshRmunkXbwIiaEcYfh+EMu+e9ewA="
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func GetService() Service {
|
|
|
|
|
return ioc.Controller().Get(AppName).(Service)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type Service interface {
|
|
|
|
|
// 用于Secret的管理(后台管理员配置)
|
|
|
|
|
// 创建secret
|
|
|
|
|
CreateSecret(context.Context, *CreateSecretRequest) (*Secret, error)
|
|
|
|
|
// 查询secret
|
|
|
|
|
QuerySecret(context.Context, *QuerySecretRequest) (*types.Set[*Secret], error)
|
2025-03-09 14:46:41 +08:00
|
|
|
|
// 查询详情, 已解密, API层需要脱敏
|
2025-03-09 12:06:14 +08:00
|
|
|
|
DescribeSecret(context.Context, *DescribeSecretRequeset) (*Secret, error)
|
|
|
|
|
|
2025-03-09 14:46:41 +08:00
|
|
|
|
// 基于云商凭证来同步资源
|
2025-03-09 12:06:14 +08:00
|
|
|
|
// 怎么API怎么设计
|
|
|
|
|
// 同步阿里云所有资源, 10分钟,30分钟 ...
|
|
|
|
|
// 这个接口调用持续30分钟...
|
|
|
|
|
// Req ---> <---- Resp: 能快速响应的同步调用
|
2025-03-09 14:46:41 +08:00
|
|
|
|
// SyncResource(Req) Resp
|
2025-03-09 12:06:14 +08:00
|
|
|
|
|
2025-03-16 09:44:04 +08:00
|
|
|
|
// Stream API, websocket --> UI 当前资源同步的进度
|
2025-03-09 12:06:14 +08:00
|
|
|
|
SyncResource(context.Context, *SyncResourceRequest, SyncResourceHandleFunc) error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SyncResourceHandleFunc func(ResourceResponse)
|
|
|
|
|
|
|
|
|
|
type ResourceResponse struct {
|
|
|
|
|
Success bool
|
2025-03-09 18:14:54 +08:00
|
|
|
|
InstanceId string `json:"instance_id"`
|
|
|
|
|
Resource *resource.Resource `json:"resource"`
|
|
|
|
|
Message string `json:"message"`
|
2025-03-09 12:06:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (t ResourceResponse) String() string {
|
|
|
|
|
return pretty.ToJSON(t)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewQuerySecretRequest() *QuerySecretRequest {
|
|
|
|
|
return &QuerySecretRequest{
|
|
|
|
|
PageRequest: request.NewDefaultPageRequest(),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type QuerySecretRequest struct {
|
|
|
|
|
// 分页请求
|
|
|
|
|
*request.PageRequest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewDescribeSecretRequeset(id string) *DescribeSecretRequeset {
|
|
|
|
|
return &DescribeSecretRequeset{
|
|
|
|
|
Id: id,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type DescribeSecretRequeset struct {
|
|
|
|
|
Id string `json:"id"`
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-16 09:44:04 +08:00
|
|
|
|
func NewSyncResourceRequest(id string) *SyncResourceRequest {
|
|
|
|
|
return &SyncResourceRequest{
|
|
|
|
|
Id: id,
|
|
|
|
|
}
|
2025-03-09 12:06:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type SyncResourceRequest struct {
|
|
|
|
|
Id string `json:"id"`
|
|
|
|
|
}
|