mirror of
				https://gitee.com/dromara/mayfly-go
				synced 2025-11-04 08:20:25 +08:00 
			
		
		
		
	feat: 新增机器授权凭证管理与其他优化
This commit is contained in:
		@@ -3,8 +3,7 @@ package form
 | 
			
		||||
type Mongo struct {
 | 
			
		||||
	Id                 uint64
 | 
			
		||||
	Uri                string `binding:"required" json:"uri"`
 | 
			
		||||
	EnableSshTunnel    int8   `json:"enableSshTunnel"`    // 是否启用ssh隧道
 | 
			
		||||
	SshTunnelMachineId uint64 `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
			
		||||
	SshTunnelMachineId int    `json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
			
		||||
	Name               string `binding:"required" json:"name"`
 | 
			
		||||
	TagId              uint64 `binding:"required" json:"tagId"`
 | 
			
		||||
	TagPath            string `json:"tagPath"`
 | 
			
		||||
 
 | 
			
		||||
@@ -108,7 +108,7 @@ var mongoCliCache = cache.NewTimedCache(constant.MongoConnExpireTime, 5*time.Sec
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	machine.AddCheckSshTunnelMachineUseFunc(func(machineId uint64) bool {
 | 
			
		||||
	machine.AddCheckSshTunnelMachineUseFunc(func(machineId int) bool {
 | 
			
		||||
		// 遍历所有mongo连接实例,若存在redis实例使用该ssh隧道机器,则返回true,表示还在使用中...
 | 
			
		||||
		items := mongoCliCache.Items()
 | 
			
		||||
		for _, v := range items {
 | 
			
		||||
@@ -144,7 +144,7 @@ type MongoInfo struct {
 | 
			
		||||
	Id                 uint64
 | 
			
		||||
	Name               string
 | 
			
		||||
	TagPath            string
 | 
			
		||||
	SshTunnelMachineId uint64 // ssh隧道机器id
 | 
			
		||||
	SshTunnelMachineId int // ssh隧道机器id
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (m *MongoInfo) GetLogDesc() string {
 | 
			
		||||
@@ -177,7 +177,7 @@ func connect(me *entity.Mongo) (*MongoInstance, error) {
 | 
			
		||||
	mongoOptions := options.Client().ApplyURI(me.Uri).
 | 
			
		||||
		SetMaxPoolSize(1)
 | 
			
		||||
	// 启用ssh隧道则连接隧道机器
 | 
			
		||||
	if me.EnableSshTunnel == 1 {
 | 
			
		||||
	if me.SshTunnelMachineId > 0 {
 | 
			
		||||
		mongoOptions.SetDialer(&MongoSshDialer{machineId: me.SshTunnelMachineId})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -206,7 +206,7 @@ func toMongiInfo(me *entity.Mongo) *MongoInfo {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type MongoSshDialer struct {
 | 
			
		||||
	machineId uint64
 | 
			
		||||
	machineId int
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (sd *MongoSshDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
 | 
			
		||||
 
 | 
			
		||||
@@ -7,8 +7,7 @@ type Mongo struct {
 | 
			
		||||
 | 
			
		||||
	Name               string `orm:"column(name)" json:"name"`
 | 
			
		||||
	Uri                string `orm:"column(uri)" json:"uri"`
 | 
			
		||||
	EnableSshTunnel    int8   `orm:"column(enable_ssh_tunnel)" json:"enableSshTunnel"`        // 是否启用ssh隧道
 | 
			
		||||
	SshTunnelMachineId uint64 `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
			
		||||
	SshTunnelMachineId int    `orm:"column(ssh_tunnel_machine_id)" json:"sshTunnelMachineId"` // ssh隧道机器id
 | 
			
		||||
	TagId              uint64 `json:"tagId"`
 | 
			
		||||
	TagPath            string `json:"tagPath"`
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,7 +7,6 @@ type MongoQuery struct {
 | 
			
		||||
 | 
			
		||||
	Name               string
 | 
			
		||||
	Uri                string
 | 
			
		||||
	EnableSshTunnel    int8   // 是否启用ssh隧道
 | 
			
		||||
	SshTunnelMachineId uint64 // ssh隧道机器id
 | 
			
		||||
	TagId              uint64 `json:"tagId"`
 | 
			
		||||
	TagPath            string `json:"tagPath"`
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user