mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-06 20:03:05 +08:00
✨ feat(mongodb): 支持无认证模式连接低版本 MongoDB 实例
- 连接表单:验证方式新增"无认证 (None)"选项,MongoDB 用户名改为非必填 - URI 构建:当 MongoAuthMechanism 为 NONE 时跳过 user/password/authSource/authMechanism - 兼容优化:无用户名时不再默认设置 authSource=admin,避免驱动对无密码实例发起认证 - 双版本同步:mongodb_impl.go 与 mongodb_impl_v1.go 同步修改 - refs #303
This commit is contained in:
@@ -2101,7 +2101,7 @@ const ConnectionModal: React.FC<{
|
||||
<Form.Item
|
||||
name="user"
|
||||
label="用户名"
|
||||
rules={[createUriAwareRequiredRule('请输入用户名')]}
|
||||
rules={dbType === 'mongodb' ? [] : [createUriAwareRequiredRule('请输入用户名')]}
|
||||
style={{ marginBottom: 0 }}
|
||||
>
|
||||
<Input />
|
||||
@@ -2115,6 +2115,7 @@ const ConnectionModal: React.FC<{
|
||||
allowClear
|
||||
placeholder="自动协商"
|
||||
options={[
|
||||
{ value: 'NONE', label: '无认证 (None)' },
|
||||
{ value: 'SCRAM-SHA-1', label: 'SCRAM-SHA-1' },
|
||||
{ value: 'SCRAM-SHA-256', label: 'SCRAM-SHA-256' },
|
||||
{ value: 'MONGODB-AWS', label: 'MONGODB-AWS' },
|
||||
|
||||
@@ -215,7 +215,9 @@ func (m *MongoDB) getURI(config connection.ConnectionConfig) string {
|
||||
hostText := strings.Join(seeds, ",")
|
||||
uri := fmt.Sprintf("%s://%s", scheme, hostText)
|
||||
|
||||
if config.User != "" {
|
||||
noAuth := strings.EqualFold(strings.TrimSpace(config.MongoAuthMechanism), "NONE")
|
||||
|
||||
if config.User != "" && !noAuth {
|
||||
var userinfo *url.Userinfo
|
||||
if config.Password != "" {
|
||||
userinfo = url.UserPassword(config.User, config.Password)
|
||||
@@ -236,11 +238,14 @@ func (m *MongoDB) getURI(config connection.ConnectionConfig) string {
|
||||
params.Set("connectTimeoutMS", strconv.Itoa(timeout*1000))
|
||||
params.Set("serverSelectionTimeoutMS", strconv.Itoa(timeout*1000))
|
||||
|
||||
authSource := strings.TrimSpace(config.AuthSource)
|
||||
if authSource == "" {
|
||||
authSource = "admin"
|
||||
// 仅在有用户名且非 NONE 认证时设置 authSource
|
||||
if config.User != "" && !noAuth {
|
||||
authSource := strings.TrimSpace(config.AuthSource)
|
||||
if authSource == "" {
|
||||
authSource = "admin"
|
||||
}
|
||||
params.Set("authSource", authSource)
|
||||
}
|
||||
params.Set("authSource", authSource)
|
||||
|
||||
if replicaSet := strings.TrimSpace(config.ReplicaSet); replicaSet != "" {
|
||||
params.Set("replicaSet", replicaSet)
|
||||
@@ -248,7 +253,8 @@ func (m *MongoDB) getURI(config connection.ConnectionConfig) string {
|
||||
if readPreference := strings.TrimSpace(config.ReadPreference); readPreference != "" {
|
||||
params.Set("readPreference", readPreference)
|
||||
}
|
||||
if authMechanism := strings.TrimSpace(config.MongoAuthMechanism); authMechanism != "" {
|
||||
// NONE 表示无认证,不设置 authMechanism
|
||||
if authMechanism := strings.TrimSpace(config.MongoAuthMechanism); authMechanism != "" && !noAuth {
|
||||
params.Set("authMechanism", authMechanism)
|
||||
}
|
||||
|
||||
|
||||
@@ -216,7 +216,9 @@ func (m *MongoDBV1) getURI(config connection.ConnectionConfig) string {
|
||||
hostText := strings.Join(seeds, ",")
|
||||
uri := fmt.Sprintf("%s://%s", scheme, hostText)
|
||||
|
||||
if config.User != "" {
|
||||
noAuth := strings.EqualFold(strings.TrimSpace(config.MongoAuthMechanism), "NONE")
|
||||
|
||||
if config.User != "" && !noAuth {
|
||||
var userinfo *url.Userinfo
|
||||
if config.Password != "" {
|
||||
userinfo = url.UserPassword(config.User, config.Password)
|
||||
@@ -237,11 +239,14 @@ func (m *MongoDBV1) getURI(config connection.ConnectionConfig) string {
|
||||
params.Set("connectTimeoutMS", strconv.Itoa(timeout*1000))
|
||||
params.Set("serverSelectionTimeoutMS", strconv.Itoa(timeout*1000))
|
||||
|
||||
authSource := strings.TrimSpace(config.AuthSource)
|
||||
if authSource == "" {
|
||||
authSource = "admin"
|
||||
// 仅在有用户名且非 NONE 认证时设置 authSource
|
||||
if config.User != "" && !noAuth {
|
||||
authSource := strings.TrimSpace(config.AuthSource)
|
||||
if authSource == "" {
|
||||
authSource = "admin"
|
||||
}
|
||||
params.Set("authSource", authSource)
|
||||
}
|
||||
params.Set("authSource", authSource)
|
||||
|
||||
if replicaSet := strings.TrimSpace(config.ReplicaSet); replicaSet != "" {
|
||||
params.Set("replicaSet", replicaSet)
|
||||
@@ -249,7 +254,8 @@ func (m *MongoDBV1) getURI(config connection.ConnectionConfig) string {
|
||||
if readPreference := strings.TrimSpace(config.ReadPreference); readPreference != "" {
|
||||
params.Set("readPreference", readPreference)
|
||||
}
|
||||
if authMechanism := strings.TrimSpace(config.MongoAuthMechanism); authMechanism != "" {
|
||||
// NONE 表示无认证,不设置 authMechanism
|
||||
if authMechanism := strings.TrimSpace(config.MongoAuthMechanism); authMechanism != "" && !noAuth {
|
||||
params.Set("authMechanism", authMechanism)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user