mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-01 23:10:26 +08:00
Compare commits
2 Commits
dba19b1e66
...
4836a770c4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4836a770c4 | ||
|
|
e6c89fad1b |
@@ -1,6 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
es: {
|
es: {
|
||||||
keywordPlaceholder: 'host / name / code',
|
keywordPlaceholder: 'host / name / code',
|
||||||
|
protocol: 'Protocol',
|
||||||
port: 'Port',
|
port: 'Port',
|
||||||
size: 'size',
|
size: 'size',
|
||||||
docs: 'docs',
|
docs: 'docs',
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export default {
|
export default {
|
||||||
es: {
|
es: {
|
||||||
keywordPlaceholder: 'host / 名称 / 编号',
|
keywordPlaceholder: 'host / 名称 / 编号',
|
||||||
|
protocol: '协议',
|
||||||
port: '端口',
|
port: '端口',
|
||||||
size: '存储大小',
|
size: '存储大小',
|
||||||
docs: '文档数',
|
docs: '文档数',
|
||||||
|
|||||||
@@ -19,6 +19,13 @@
|
|||||||
<el-form-item prop="version" :label="t('common.version')">
|
<el-form-item prop="version" :label="t('common.version')">
|
||||||
<el-input v-model.trim="form.version" auto-complete="off" disabled></el-input>
|
<el-input v-model.trim="form.version" auto-complete="off" disabled></el-input>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
<!-- 增加协议下拉框 http和https,默认http-->
|
||||||
|
<el-form-item prop="protocol" :label="t('es.protocol')">
|
||||||
|
<el-select v-model="form.protocol" placeholder="http">
|
||||||
|
<el-option label="http" value="http"></el-option>
|
||||||
|
<el-option label="https" value="https"></el-option>
|
||||||
|
</el-select>
|
||||||
|
</el-form-item>
|
||||||
|
|
||||||
<el-form-item prop="host" label="Host" required>
|
<el-form-item prop="host" label="Host" required>
|
||||||
<el-col :span="18">
|
<el-col :span="18">
|
||||||
@@ -105,6 +112,7 @@ const DefaultForm = {
|
|||||||
id: null,
|
id: null,
|
||||||
code: '',
|
code: '',
|
||||||
name: null,
|
name: null,
|
||||||
|
protocol: 'http',
|
||||||
host: '',
|
host: '',
|
||||||
version: '',
|
version: '',
|
||||||
port: 9200,
|
port: 9200,
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
type InstanceForm struct {
|
type InstanceForm struct {
|
||||||
Id uint64 `json:"id"`
|
Id uint64 `json:"id"`
|
||||||
|
Protocol string `binding:"required" json:"protocol"`
|
||||||
Name string `binding:"required" json:"name"`
|
Name string `binding:"required" json:"name"`
|
||||||
Host string `binding:"required" json:"host"`
|
Host string `binding:"required" json:"host"`
|
||||||
Port int `binding:"required" json:"port"`
|
Port int `binding:"required" json:"port"`
|
||||||
|
|||||||
@@ -9,13 +9,14 @@ type InstanceListVO struct {
|
|||||||
tagentity.AuthCerts // 授权凭证信息
|
tagentity.AuthCerts // 授权凭证信息
|
||||||
tagentity.ResourceTags
|
tagentity.ResourceTags
|
||||||
|
|
||||||
Id *int64 `json:"id"`
|
Id *int64 `json:"id"`
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
Name *string `json:"name"`
|
Name *string `json:"name"`
|
||||||
Host *string `json:"host"`
|
Protocol *string `json:"protocol"`
|
||||||
Port *int `json:"port"`
|
Host *string `json:"host"`
|
||||||
Version *string `json:"version"`
|
Port *int `json:"port"`
|
||||||
Remark *string `json:"remark"`
|
Version *string `json:"version"`
|
||||||
|
Remark *string `json:"remark"`
|
||||||
|
|
||||||
CreateTime *time.Time `json:"createTime"`
|
CreateTime *time.Time `json:"createTime"`
|
||||||
Creator *string `json:"creator"`
|
Creator *string `json:"creator"`
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ type EsInstance struct {
|
|||||||
|
|
||||||
Code string `json:"code" gorm:"size:32;not null;"`
|
Code string `json:"code" gorm:"size:32;not null;"`
|
||||||
Name string `json:"name" gorm:"size:32;not null;"`
|
Name string `json:"name" gorm:"size:32;not null;"`
|
||||||
|
Protocol string `json:"protocol" gorm:"size:10;not null;"`
|
||||||
Host string `json:"host" gorm:"size:255;not null;"`
|
Host string `json:"host" gorm:"size:255;not null;"`
|
||||||
Port int `json:"port"`
|
Port int `json:"port"`
|
||||||
Network string `json:"network" gorm:"size:20;"`
|
Network string `json:"network" gorm:"size:20;"`
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package esi
|
package esi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"mayfly-go/internal/machine/mcm"
|
"mayfly-go/internal/machine/mcm"
|
||||||
"mayfly-go/pkg/logx"
|
"mayfly-go/pkg/logx"
|
||||||
@@ -52,6 +53,16 @@ func (d *EsConn) StartProxy() error {
|
|||||||
d.proxy = httputil.NewSingleHostReverseProxy(targetURL)
|
d.proxy = httputil.NewSingleHostReverseProxy(targetURL)
|
||||||
// 设置 proxy buffer pool
|
// 设置 proxy buffer pool
|
||||||
d.proxy.BufferPool = NewBufferPool()
|
d.proxy.BufferPool = NewBufferPool()
|
||||||
|
|
||||||
|
// Configure TLS to skip certificate verification for non-compliant certificates
|
||||||
|
if targetURL.Scheme == "https" {
|
||||||
|
d.proxy.Transport = &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type EsInfo struct {
|
|||||||
InstanceId uint64 // 实例id
|
InstanceId uint64 // 实例id
|
||||||
Name string
|
Name string
|
||||||
|
|
||||||
|
Protocol string // 协议,默认http
|
||||||
Host string
|
Host string
|
||||||
Port int
|
Port int
|
||||||
Network string
|
Network string
|
||||||
@@ -90,7 +91,14 @@ func (di *EsInfo) Ping() (map[string]any, error) {
|
|||||||
|
|
||||||
// ExecApi 执行api
|
// ExecApi 执行api
|
||||||
func (di *EsInfo) ExecApi(method, path string, data any, timeoutSecond ...int) (map[string]any, error) {
|
func (di *EsInfo) ExecApi(method, path string, data any, timeoutSecond ...int) (map[string]any, error) {
|
||||||
request := httpx.NewReq(di.baseUrl + path)
|
var request *httpx.Req
|
||||||
|
// Use insecure TLS client for HTTPS connections to handle non-compliant certificates
|
||||||
|
if di.Protocol == "https" {
|
||||||
|
request = httpx.NewReqWithInsecureTLS(di.baseUrl + path)
|
||||||
|
} else {
|
||||||
|
request = httpx.NewReq(di.baseUrl + path)
|
||||||
|
}
|
||||||
|
|
||||||
if di.authorization != "" {
|
if di.authorization != "" {
|
||||||
request.Header("Authorization", di.authorization)
|
request.Header("Authorization", di.authorization)
|
||||||
}
|
}
|
||||||
@@ -117,6 +125,11 @@ func (di *EsInfo) ExecApi(method, path string, data any, timeoutSecond ...int) (
|
|||||||
|
|
||||||
// 如果使用了ssh隧道,将其host port改变其本地映射host port
|
// 如果使用了ssh隧道,将其host port改变其本地映射host port
|
||||||
func (di *EsInfo) IfUseSshTunnelChangeIpPort(ctx context.Context) error {
|
func (di *EsInfo) IfUseSshTunnelChangeIpPort(ctx context.Context) error {
|
||||||
|
// 设置默认协议
|
||||||
|
if di.Protocol == "" {
|
||||||
|
di.Protocol = "http"
|
||||||
|
}
|
||||||
|
|
||||||
// 开启ssh隧道
|
// 开启ssh隧道
|
||||||
if di.SshTunnelMachineId > 0 {
|
if di.SshTunnelMachineId > 0 {
|
||||||
stm, err := GetSshTunnel(ctx, di.SshTunnelMachineId)
|
stm, err := GetSshTunnel(ctx, di.SshTunnelMachineId)
|
||||||
@@ -130,9 +143,9 @@ func (di *EsInfo) IfUseSshTunnelChangeIpPort(ctx context.Context) error {
|
|||||||
di.Host = exposedIp
|
di.Host = exposedIp
|
||||||
di.Port = exposedPort
|
di.Port = exposedPort
|
||||||
di.useSshTunnel = true
|
di.useSshTunnel = true
|
||||||
di.baseUrl = fmt.Sprintf("http://%s:%d", exposedIp, exposedPort)
|
di.baseUrl = fmt.Sprintf("%s://%s:%d", di.Protocol, exposedIp, exposedPort)
|
||||||
} else {
|
} else {
|
||||||
di.baseUrl = fmt.Sprintf("http://%s:%d", di.Host, di.Port)
|
di.baseUrl = fmt.Sprintf("%s://%s:%d", di.Protocol, di.Host, di.Port)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ func V1_10() []*gormigrate.Migration {
|
|||||||
migrations = append(migrations, V1_10_1()...)
|
migrations = append(migrations, V1_10_1()...)
|
||||||
migrations = append(migrations, V1_10_2()...)
|
migrations = append(migrations, V1_10_2()...)
|
||||||
migrations = append(migrations, V1_10_3()...)
|
migrations = append(migrations, V1_10_3()...)
|
||||||
|
migrations = append(migrations, V1_10_4()...)
|
||||||
return migrations
|
return migrations
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -326,3 +327,28 @@ func V1_10_3() []*gormigrate.Migration {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func V1_10_4() []*gormigrate.Migration {
|
||||||
|
return []*gormigrate.Migration{
|
||||||
|
{
|
||||||
|
ID: "20251023-v1.10.4",
|
||||||
|
Migrate: func(tx *gorm.DB) error {
|
||||||
|
// 给EsInstance表添加protocol列,默认值为http, 20251023,fudawei
|
||||||
|
if !tx.Migrator().HasColumn(&esentity.EsInstance{}, "protocol") {
|
||||||
|
// 先添加可为空的列
|
||||||
|
if err := tx.Exec("ALTER TABLE t_es_instance ADD COLUMN protocol VARCHAR(10) DEFAULT 'http'").Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
// 更新所有现有记录为默认值http
|
||||||
|
if err := tx.Exec("UPDATE t_es_instance SET protocol = 'http' WHERE protocol IS NULL OR protocol = ''").Error; err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
Rollback: func(tx *gorm.DB) error {
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package httpx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"crypto/tls"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -41,6 +42,16 @@ func NewReq(url string) *Req {
|
|||||||
return &Req{url: url, client: http.Client{}}
|
return &Req{url: url, client: http.Client{}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建一个请求(不验证TLS证书)
|
||||||
|
func NewReqWithInsecureTLS(url string) *Req {
|
||||||
|
transport := &http.Transport{
|
||||||
|
TLSClientConfig: &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return &Req{url: url, client: http.Client{Transport: transport}}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *Req) Url(url string) *Req {
|
func (r *Req) Url(url string) *Req {
|
||||||
r.url = url
|
r.url = url
|
||||||
return r
|
return r
|
||||||
|
|||||||
Reference in New Issue
Block a user