go-duck-cli 1.1.32 → 1.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/generators/devops.js +11 -0
- package/generators/kratos.js +15 -2
- package/generators/multitenancy.js +15 -2
- package/package.json +1 -1
package/generators/devops.js
CHANGED
|
@@ -363,6 +363,17 @@ jobs:
|
|
|
363
363
|
"publicClient": false,
|
|
364
364
|
"protocol": "openid-connect",
|
|
365
365
|
"fullScopeAllowed": true
|
|
366
|
+
},
|
|
367
|
+
{
|
|
368
|
+
"clientId": "go-client",
|
|
369
|
+
"enabled": true,
|
|
370
|
+
"publicClient": true,
|
|
371
|
+
"standardFlowEnabled": true,
|
|
372
|
+
"directAccessGrantsEnabled": true,
|
|
373
|
+
"protocol": "openid-connect",
|
|
374
|
+
"redirectUris": ["*"],
|
|
375
|
+
"webOrigins": ["*"],
|
|
376
|
+
"fullScopeAllowed": true
|
|
366
377
|
}
|
|
367
378
|
],
|
|
368
379
|
"users": [
|
package/generators/kratos.js
CHANGED
|
@@ -302,7 +302,11 @@ func TenantServerInterceptor(conf *config.Config, db *gorm.DB) middleware.Middle
|
|
|
302
302
|
|
|
303
303
|
var mappings []models.TenantRole
|
|
304
304
|
if requestedTenant != "" {
|
|
305
|
-
|
|
305
|
+
if isAdmin {
|
|
306
|
+
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE tenant_id = ?", requestedTenant).Scan(&mappings)
|
|
307
|
+
} else {
|
|
308
|
+
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE LOWER(role_name) IN ? AND tenant_id = ?", lowerRoles, requestedTenant).Scan(&mappings)
|
|
309
|
+
}
|
|
306
310
|
} else {
|
|
307
311
|
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE LOWER(role_name) IN ?", lowerRoles).Scan(&mappings)
|
|
308
312
|
}
|
|
@@ -310,6 +314,16 @@ func TenantServerInterceptor(conf *config.Config, db *gorm.DB) middleware.Middle
|
|
|
310
314
|
siloConnections := make(map[string]*gorm.DB)
|
|
311
315
|
mongoConnections := make(map[string]*mongo.Database)
|
|
312
316
|
|
|
317
|
+
// Filter out unauthorized mappings (e.g. admin_db for non-admins)
|
|
318
|
+
var authorizedMappings []models.TenantRole
|
|
319
|
+
for _, m := range mappings {
|
|
320
|
+
if m.DBName == "admin_db" && !isAdmin {
|
|
321
|
+
continue
|
|
322
|
+
}
|
|
323
|
+
authorizedMappings = append(authorizedMappings, m)
|
|
324
|
+
}
|
|
325
|
+
mappings = authorizedMappings
|
|
326
|
+
|
|
313
327
|
if len(mappings) == 0 {
|
|
314
328
|
conn, _ := mgr.GetDB(fallbackDB)
|
|
315
329
|
siloConnections["fallback"] = conn
|
|
@@ -343,7 +357,6 @@ func TenantServerInterceptor(conf *config.Config, db *gorm.DB) middleware.Middle
|
|
|
343
357
|
})
|
|
344
358
|
|
|
345
359
|
for _, m := range mappings {
|
|
346
|
-
if m.DBName == "admin_db" && !isAdmin { continue }
|
|
347
360
|
if conn, err := mgr.GetDB(m.DBName); err == nil {
|
|
348
361
|
siloConnections[m.RoleName] = conn
|
|
349
362
|
}
|
|
@@ -173,11 +173,25 @@ func TenantMiddleware(db *gorm.DB, cfg *config.Config) gin.HandlerFunc {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
if len(requestedTenants) > 0 {
|
|
176
|
-
|
|
176
|
+
if isAdmin {
|
|
177
|
+
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE tenant_id IN ?", requestedTenants).Scan(&mappings)
|
|
178
|
+
} else {
|
|
179
|
+
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE LOWER(role_name) IN ? AND tenant_id IN ?", lowerRoles, requestedTenants).Scan(&mappings)
|
|
180
|
+
}
|
|
177
181
|
} else {
|
|
178
182
|
db.Raw("SELECT role_name, db_name, is_primary FROM tenant_roles WHERE LOWER(role_name) IN ?", lowerRoles).Scan(&mappings)
|
|
179
183
|
}
|
|
180
184
|
|
|
185
|
+
// Filter out unauthorized mappings (e.g. admin_db for non-admins)
|
|
186
|
+
var authorizedMappings []models.TenantRole
|
|
187
|
+
for _, m := range mappings {
|
|
188
|
+
if m.DBName == "admin_db" && !isAdmin {
|
|
189
|
+
continue
|
|
190
|
+
}
|
|
191
|
+
authorizedMappings = append(authorizedMappings, m)
|
|
192
|
+
}
|
|
193
|
+
mappings = authorizedMappings
|
|
194
|
+
|
|
181
195
|
if len(mappings) == 0 {
|
|
182
196
|
conn, err := mgr.GetDB(fallbackDB)
|
|
183
197
|
if err != nil || conn == nil {
|
|
@@ -221,7 +235,6 @@ func TenantMiddleware(db *gorm.DB, cfg *config.Config) gin.HandlerFunc {
|
|
|
221
235
|
})
|
|
222
236
|
|
|
223
237
|
for _, m := range mappings {
|
|
224
|
-
if m.DBName == "admin_db" && !isAdmin { continue }
|
|
225
238
|
conn, err := mgr.GetDB(m.DBName)
|
|
226
239
|
if err == nil {
|
|
227
240
|
siloConnections[m.RoleName] = conn
|