From 090186a692af5c6104f427718d906136a4a57e0b Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Mon, 20 May 2024 07:57:07 +0000 Subject: [PATCH 1/4] feat: use new list db account interface --- internal/dms/biz/cloudbeaver_ee.go | 43 +++++++++++++++++++----------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/internal/dms/biz/cloudbeaver_ee.go b/internal/dms/biz/cloudbeaver_ee.go index 7343cca1..8d7b105c 100644 --- a/internal/dms/biz/cloudbeaver_ee.go +++ b/internal/dms/biz/cloudbeaver_ee.go @@ -12,6 +12,8 @@ import ( "time" "github.com/99designs/gqlgen/graphql" + + v1 "github.com/actiontech/dms/api/dms/service/v1" "github.com/actiontech/dms/internal/dms/pkg/constant" pkgErr "github.com/actiontech/dms/internal/dms/pkg/errors" "github.com/actiontech/dms/internal/pkg/cloudbeaver" @@ -19,21 +21,23 @@ import ( base "github.com/actiontech/dms/pkg/dms-common/api/base/v1" pkgHttp "github.com/actiontech/dms/pkg/dms-common/pkg/http" pkgRand "github.com/actiontech/dms/pkg/rand" + "github.com/go-openapi/strfmt" "github.com/labstack/echo/v4" ) // A provision DBAccount type TempDBAccount struct { - // the dbaccount user - User string `json:"user"` - // the dbaccount password + DBAccountUid string `json:"db_account_uid"` + AccountInfo AccountInfo `json:"account_info"` + Explanation string `json:"explanation"` + ExpiredTime string `json:"expired_time"` + DbService v1.UidWithName `json:"db_service"` +} + +type AccountInfo struct { + User string `json:"user"` + Hostname string `json:"hostname"` Password string `json:"password"` - // the datasource's uid - DbServiceUid string `json:"db_service_uid"` - // the dbaccount relation auth purpose - AuthPurpose string `json:"auth_purpose"` - // the dbaccount relation auth used by sql workbench - UsedBySQLWorkbench bool `json:"used_by_workbench"` } type ListDBAccountReply struct { @@ -57,19 +61,26 @@ func (cu *CloudbeaverUsecase) ResetDbServiceByAuth(ctx context.Context, activeDB ret := make([]*DBService, 0) for _, dbaccount := range dbaccounts { - if !dbaccount.UsedBySQLWorkbench || dbaccount.AuthPurpose == "" { - continue + if dbaccount.ExpiredTime != "" { + expiredTime, err := time.Parse(strfmt.RFC3339Millis, dbaccount.ExpiredTime) + if err != nil { + cu.log.Errorf("failed to parse expired time %v: %v", dbaccount.ExpiredTime, err) + continue + } + if expiredTime.Unix() <= time.Now().Unix() { + continue + } } for _, activeDBService := range activeDBServices { if activeDBService.DBType != constant.DBTypeMySQL.String() { ret = append(ret, activeDBService) } else { - if dbaccount.DbServiceUid == activeDBService.UID { + if dbaccount.DbService.Uid == activeDBService.UID { db := *activeDBService - db.User = dbaccount.User - db.Password = dbaccount.Password - db.AccountPurpose = dbaccount.AuthPurpose + db.User = dbaccount.AccountInfo.User + db.Password = dbaccount.AccountInfo.Password + db.AccountPurpose = dbaccount.AccountInfo.User ret = append(ret, &db) break } @@ -87,7 +98,7 @@ func (cu *CloudbeaverUsecase) ListAuthDbAccount(ctx context.Context, url, userId reply := &ListDBAccountReply{} - if err := pkgHttp.Get(ctx, fmt.Sprintf("%v/provision/v1/auth/dbaccounts?used_by_sql_workbench=true&page_size=999&page_index=1&owner_user_id=%s", url, userId), header, nil, reply); err != nil { + if err := pkgHttp.Get(ctx, fmt.Sprintf("%v/provision/v1/auth/projects//db_accounts?page_size=999&page_index=1&filter_by_used_by_sql_workbench=true&filter_by_password_managed=true&filter_by_status=unlock&filter_by_user=%s", url, userId), header, nil, reply); err != nil { return nil, fmt.Errorf("failed to get db account from %v: %v", url, err) } if reply.Code != 0 { From e953a2c1a54bf5239a105704b06cd6edc42c9aab Mon Sep 17 00:00:00 2001 From: wanghucheng Date: Tue, 28 May 2024 13:45:57 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat=EF=BC=9Adel=20filter=20by=20used=20by?= =?UTF-8?q?=20sql=20workbench?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/dms/biz/cloudbeaver_ee.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/dms/biz/cloudbeaver_ee.go b/internal/dms/biz/cloudbeaver_ee.go index 8d7b105c..bbeb72bc 100644 --- a/internal/dms/biz/cloudbeaver_ee.go +++ b/internal/dms/biz/cloudbeaver_ee.go @@ -98,7 +98,7 @@ func (cu *CloudbeaverUsecase) ListAuthDbAccount(ctx context.Context, url, userId reply := &ListDBAccountReply{} - if err := pkgHttp.Get(ctx, fmt.Sprintf("%v/provision/v1/auth/projects//db_accounts?page_size=999&page_index=1&filter_by_used_by_sql_workbench=true&filter_by_password_managed=true&filter_by_status=unlock&filter_by_user=%s", url, userId), header, nil, reply); err != nil { + if err := pkgHttp.Get(ctx, fmt.Sprintf("%v/provision/v1/auth/projects//db_accounts?page_size=999&page_index=1&filter_by_password_managed=true&filter_by_status=unlock&filter_by_user=%s", url, userId), header, nil, reply); err != nil { return nil, fmt.Errorf("failed to get db account from %v: %v", url, err) } if reply.Code != 0 { From 6f6c159d6dd221a5698961052506f5779d3a3919 Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Tue, 28 May 2024 05:29:01 +0000 Subject: [PATCH 3/4] support connect CB with prov oracle db account --- internal/dms/biz/cloudbeaver_ee.go | 51 ++++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/internal/dms/biz/cloudbeaver_ee.go b/internal/dms/biz/cloudbeaver_ee.go index bbeb72bc..6c0207e3 100644 --- a/internal/dms/biz/cloudbeaver_ee.go +++ b/internal/dms/biz/cloudbeaver_ee.go @@ -15,6 +15,7 @@ import ( v1 "github.com/actiontech/dms/api/dms/service/v1" "github.com/actiontech/dms/internal/dms/pkg/constant" + pkgConst "github.com/actiontech/dms/internal/dms/pkg/constant" pkgErr "github.com/actiontech/dms/internal/dms/pkg/errors" "github.com/actiontech/dms/internal/pkg/cloudbeaver" "github.com/actiontech/dms/internal/pkg/cloudbeaver/model" @@ -46,6 +47,10 @@ type ListDBAccountReply struct { base.GenericResp } +func (cu *CloudbeaverUsecase) SupportDBType(dbType pkgConst.DBType) bool { + return dbType == constant.DBTypeMySQL || dbType == constant.DBTypeOracle +} + func (cu *CloudbeaverUsecase) ResetDbServiceByAuth(ctx context.Context, activeDBServices []*DBService, userId string) ([]*DBService, error) { proxyTarget, err := cu.proxyTargetRepo.GetProxyTargetByName(ctx, "provision") if errors.Is(err, pkgErr.ErrStorageNoData) { @@ -60,31 +65,35 @@ func (cu *CloudbeaverUsecase) ResetDbServiceByAuth(ctx context.Context, activeDB } ret := make([]*DBService, 0) - for _, dbaccount := range dbaccounts { - if dbaccount.ExpiredTime != "" { - expiredTime, err := time.Parse(strfmt.RFC3339Millis, dbaccount.ExpiredTime) - if err != nil { - cu.log.Errorf("failed to parse expired time %v: %v", dbaccount.ExpiredTime, err) - continue - } - if expiredTime.Unix() <= time.Now().Unix() { - continue - } + for _, activeDBService := range activeDBServices { + // prov不支持的数据库类型 使用管理员账号密码连接 + if !cu.SupportDBType(pkgConst.DBType(activeDBService.DBType)) { + ret = append(ret, activeDBService) + continue } - for _, activeDBService := range activeDBServices { - if activeDBService.DBType != constant.DBTypeMySQL.String() { - ret = append(ret, activeDBService) - } else { - if dbaccount.DbService.Uid == activeDBService.UID { - db := *activeDBService - db.User = dbaccount.AccountInfo.User - db.Password = dbaccount.AccountInfo.Password - db.AccountPurpose = dbaccount.AccountInfo.User - ret = append(ret, &db) - break + for _, dbaccount := range dbaccounts { + + if dbaccount.ExpiredTime != "" { + expiredTime, err := time.Parse(strfmt.RFC3339Millis, dbaccount.ExpiredTime) + if err != nil { + cu.log.Errorf("failed to parse expired time %v: %v", dbaccount.ExpiredTime, err) + continue + } + if expiredTime.Unix() <= time.Now().Unix() { + continue } } + + if dbaccount.DbService.Uid == activeDBService.UID { + db := *activeDBService + db.User = dbaccount.AccountInfo.User + db.Password = dbaccount.AccountInfo.Password + db.AccountPurpose = dbaccount.AccountInfo.User + ret = append(ret, &db) + break + } + } } From e5a7151538e7e2ec7ffe673037fd52e2a623b505 Mon Sep 17 00:00:00 2001 From: yangzhongjiao Date: Tue, 28 May 2024 08:44:34 +0000 Subject: [PATCH 4/4] update comment --- internal/dms/biz/cloudbeaver_ee.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/dms/biz/cloudbeaver_ee.go b/internal/dms/biz/cloudbeaver_ee.go index 6c0207e3..ccf1814d 100644 --- a/internal/dms/biz/cloudbeaver_ee.go +++ b/internal/dms/biz/cloudbeaver_ee.go @@ -66,7 +66,7 @@ func (cu *CloudbeaverUsecase) ResetDbServiceByAuth(ctx context.Context, activeDB ret := make([]*DBService, 0) for _, activeDBService := range activeDBServices { - // prov不支持的数据库类型 使用管理员账号密码连接 + // prov不支持的数据库类型 使用数据源账号密码连接 if !cu.SupportDBType(pkgConst.DBType(activeDBService.DBType)) { ret = append(ret, activeDBService) continue