mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-05-18 17:05:21 +08:00
reafctor: 团队管理与授权凭证优化
This commit is contained in:
@@ -8,7 +8,6 @@ func InitIoc() {
|
||||
ioc.Register(new(machineAppImpl), ioc.WithComponentName("MachineApp"))
|
||||
ioc.Register(new(machineFileAppImpl), ioc.WithComponentName("MachineFileApp"))
|
||||
ioc.Register(new(machineScriptAppImpl), ioc.WithComponentName("MachineScriptApp"))
|
||||
ioc.Register(new(authCertAppImpl), ioc.WithComponentName("AuthCertApp"))
|
||||
ioc.Register(new(machineCronJobAppImpl), ioc.WithComponentName("MachineCronJobApp"))
|
||||
ioc.Register(new(machineTermOpAppImpl), ioc.WithComponentName("MachineTermOpApp"))
|
||||
}
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
package application
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/internal/machine/domain/entity"
|
||||
"mayfly-go/internal/machine/domain/repository"
|
||||
"mayfly-go/pkg/base"
|
||||
"mayfly-go/pkg/errorx"
|
||||
"mayfly-go/pkg/model"
|
||||
)
|
||||
|
||||
type AuthCert interface {
|
||||
base.App[*entity.AuthCert]
|
||||
|
||||
GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error)
|
||||
|
||||
Save(ctx context.Context, ac *entity.AuthCert) error
|
||||
|
||||
GetByIds(ids ...uint64) []*entity.AuthCert
|
||||
}
|
||||
|
||||
type authCertAppImpl struct {
|
||||
base.AppImpl[*entity.AuthCert, repository.AuthCert]
|
||||
}
|
||||
|
||||
// 注入AuthCertRepo
|
||||
func (a *authCertAppImpl) InjectAuthCertRepo(repo repository.AuthCert) {
|
||||
a.Repo = repo
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetPageList(condition *entity.AuthCertQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
|
||||
return a.GetRepo().GetPageList(condition, pageParam, toEntity)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) Save(ctx context.Context, ac *entity.AuthCert) error {
|
||||
oldAc := &entity.AuthCert{Name: ac.Name}
|
||||
err := a.GetBy(oldAc, "Id", "Name")
|
||||
|
||||
ac.PwdEncrypt()
|
||||
if ac.Id == 0 {
|
||||
if err == nil {
|
||||
return errorx.NewBiz("该凭证名已存在")
|
||||
}
|
||||
return a.Insert(ctx, ac)
|
||||
}
|
||||
|
||||
// 如果存在该库,则校验修改的库是否为该库
|
||||
if err == nil && oldAc.Id != ac.Id {
|
||||
return errorx.NewBiz("该凭证名已存在")
|
||||
}
|
||||
return a.UpdateById(ctx, ac)
|
||||
}
|
||||
|
||||
func (a *authCertAppImpl) GetByIds(ids ...uint64) []*entity.AuthCert {
|
||||
acs := new([]*entity.AuthCert)
|
||||
a.GetByIdIn(acs, ids)
|
||||
return *acs
|
||||
}
|
||||
@@ -18,8 +18,6 @@ import (
|
||||
"mayfly-go/pkg/model"
|
||||
"mayfly-go/pkg/scheduler"
|
||||
"time"
|
||||
|
||||
"github.com/may-fly/cast"
|
||||
)
|
||||
|
||||
type SaveMachineParam struct {
|
||||
@@ -164,6 +162,15 @@ func (m *machineAppImpl) SaveMachine(ctx context.Context, param *SaveMachinePara
|
||||
|
||||
func (m *machineAppImpl) TestConn(me *entity.Machine, authCert *tagentity.ResourceAuthCert) error {
|
||||
me.Id = 0
|
||||
|
||||
if authCert.CiphertextType == tagentity.AuthCertCiphertextTypePublic {
|
||||
publicAuthCert, err := m.resourceAuthCertApp.GetAuthCert(authCert.Ciphertext)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
authCert = publicAuthCert
|
||||
}
|
||||
|
||||
mi, err := m.toMi(me, authCert)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -338,7 +345,7 @@ func (m *machineAppImpl) toMi(me *entity.Machine, authCert *tagentity.ResourceAu
|
||||
|
||||
mi.Username = authCert.Username
|
||||
mi.Password = authCert.Ciphertext
|
||||
mi.Passphrase = cast.ToString(authCert.Extra["passphrase"])
|
||||
mi.Passphrase = authCert.GetExtraString(tagentity.ExtraKeyPassphrase)
|
||||
mi.AuthMethod = int8(authCert.CiphertextType)
|
||||
|
||||
// 使用了ssh隧道,则将隧道机器信息也附上
|
||||
|
||||
Reference in New Issue
Block a user