refactor(weknoracloud): update credential handling and configuration
- Replaced references to Docreader credentials with WeKnoraCloud credentials across multiple services and handlers. - Introduced a new CredentialsConfig structure to manage third-party provider credentials, specifically for WeKnoraCloud. - Updated database schema to include a credentials column for storing WeKnoraCloud AppID and AppSecret. - Enhanced methods for retrieving and utilizing WeKnoraCloud credentials, ensuring proper encryption and decryption during storage and retrieval. This update improves the management of WeKnoraCloud credentials, streamlining the integration and enhancing security measures.
This commit is contained in:
@@ -1515,9 +1515,9 @@ func (h *InitializationHandler) CheckRemoteModel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
if creds := tenantInfo.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
appID = creds.AppID
|
||||
appSecret = creds.AppSecret
|
||||
}
|
||||
|
||||
// 创建模型配置进行测试
|
||||
@@ -1612,9 +1612,9 @@ func (h *InitializationHandler) TestEmbeddingModel(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
if creds := tenantInfo.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
appID = creds.AppID
|
||||
appSecret = creds.AppSecret
|
||||
}
|
||||
|
||||
// 构造 embedder 配置
|
||||
@@ -1740,9 +1740,9 @@ func (h *InitializationHandler) checkRerankModelConnection(ctx context.Context,
|
||||
return false, "租户信息未找到"
|
||||
}
|
||||
var appID, appSecret string
|
||||
if tenantInfo.ParserEngineConfig != nil {
|
||||
appID = tenantInfo.ParserEngineConfig.DocreaderAppID
|
||||
appSecret = tenantInfo.ParserEngineConfig.DocreaderAPIKey
|
||||
if creds := tenantInfo.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
appID = creds.AppID
|
||||
appSecret = creds.AppSecret
|
||||
}
|
||||
config.AppID = appID
|
||||
config.AppSecret = appSecret
|
||||
|
||||
@@ -142,8 +142,16 @@ func (h *SystemHandler) getDocReaderConnInfo() (addr, transport string) {
|
||||
func (h *SystemHandler) ListParserEngines(c *gin.Context) {
|
||||
var overrides map[string]string
|
||||
if v, exists := c.Get(types.TenantInfoContextKey.String()); exists {
|
||||
if tenant, ok := v.(*types.Tenant); ok && tenant != nil && tenant.ParserEngineConfig != nil {
|
||||
overrides = tenant.ParserEngineConfig.ToOverridesMap()
|
||||
if tenant, ok := v.(*types.Tenant); ok && tenant != nil {
|
||||
if tenant.ParserEngineConfig != nil {
|
||||
overrides = tenant.ParserEngineConfig.ToOverridesMap()
|
||||
}
|
||||
if creds := tenant.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
if overrides == nil {
|
||||
overrides = make(map[string]string)
|
||||
}
|
||||
overrides["weknoracloud_app_id"] = creds.AppID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,8 +204,16 @@ func (h *SystemHandler) ReconnectDocReader(c *gin.Context) {
|
||||
|
||||
var overrides map[string]string
|
||||
if v, exists := c.Get(types.TenantInfoContextKey.String()); exists {
|
||||
if tenant, ok := v.(*types.Tenant); ok && tenant != nil && tenant.ParserEngineConfig != nil {
|
||||
overrides = tenant.ParserEngineConfig.ToOverridesMap()
|
||||
if tenant, ok := v.(*types.Tenant); ok && tenant != nil {
|
||||
if tenant.ParserEngineConfig != nil {
|
||||
overrides = tenant.ParserEngineConfig.ToOverridesMap()
|
||||
}
|
||||
if creds := tenant.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
if overrides == nil {
|
||||
overrides = make(map[string]string)
|
||||
}
|
||||
overrides["weknoracloud_app_id"] = creds.AppID
|
||||
}
|
||||
}
|
||||
}
|
||||
remoteEngines := h.fetchRemoteEngines(c.Request.Context(), h.documentReader, overrides)
|
||||
@@ -223,6 +239,16 @@ func (h *SystemHandler) CheckParserEngines(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
overrides := body.ToOverridesMap()
|
||||
if v, exists := c.Get(types.TenantInfoContextKey.String()); exists {
|
||||
if tenant, ok := v.(*types.Tenant); ok && tenant != nil {
|
||||
if creds := tenant.Credentials.GetWeKnoraCloud(); creds != nil {
|
||||
if overrides == nil {
|
||||
overrides = make(map[string]string)
|
||||
}
|
||||
overrides["weknoracloud_app_id"] = creds.AppID
|
||||
}
|
||||
}
|
||||
}
|
||||
reader, docreaderAddr, docreaderTransport := h.resolveDocReader(c.Request.Context(), overrides)
|
||||
connected := reader != nil && reader.IsConnected()
|
||||
remoteEngines := h.fetchRemoteEngines(c.Request.Context(), reader, overrides)
|
||||
@@ -1034,11 +1060,11 @@ func (h *SystemHandler) ResolveDocumentReader(ctx context.Context, addr string)
|
||||
}
|
||||
|
||||
if service.IsWeKnoraCloudDocReaderAddr(addr) {
|
||||
creds := h.tenantSvc.GetDocreaderCredentials(ctx)
|
||||
creds := h.tenantSvc.GetWeKnoraCloudCredentials(ctx)
|
||||
if creds == nil {
|
||||
return nil
|
||||
}
|
||||
reader, err := docparser.NewWeKnoraCloudSignedDocumentReader(creds.AppID, creds.APIKey)
|
||||
reader, err := docparser.NewWeKnoraCloudSignedDocumentReader(creds.AppID, creds.AppSecret)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user