Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: deprecate unused legacy api (#6286)
Danny Xub66f39aff69b
diff --git a/backend/legacyapi/sql.go b/backend/legacyapi/sql.goindex a6cd507439..167083c7c3 100644--- a/backend/legacyapi/sql.go+++ b/backend/legacyapi/sql.go@@ -1,40 +1,9 @@package apiimport (- "context"-"github.com/bytebase/bytebase/backend/plugin/advisor"- "github.com/bytebase/bytebase/backend/plugin/db")-// ConnectionInfo is the API message for connection infos.-type ConnectionInfo struct {- Engine db.Type `jsonapi:"attr,engine"`- Host string `jsonapi:"attr,host"`- Port string `jsonapi:"attr,port"`- Username string `jsonapi:"attr,username"`- Password string `jsonapi:"attr,password"`- UseEmptyPassword bool `jsonapi:"attr,useEmptyPassword"`- Database string `jsonapi:"attr,database"`- InstanceID *int `jsonapi:"attr,instanceId"`- SslCa *string `jsonapi:"attr,sslCa"`- SslCert *string `jsonapi:"attr,sslCert"`- SslKey *string `jsonapi:"attr,sslKey"`- // SRV is used for MongoDB only.- SRV bool `jsonapi:"attr,srv"`- // AuthenticationDatabase is used for MongoDB only.- AuthenticationDatabase string `json:"authenticationDatabase" jsonapi:"attr,authenticationDatabase"`- SID string `json:"sid" jsonapi:"attr,sid"`- ServiceName string `json:"serviceName" jsonapi:"attr,serviceName"`- // SSH configuration.- UseSSHConfig bool `jsonapi:"attr,useSSHConfig"`- SSHHost string `json:"sshHost" jsonapi:"attr,sshHost"`- SSHPort string `json:"sshPort" jsonapi:"attr,sshPort"`- SSHUser string `json:"sshUser" jsonapi:"attr,sshUser"`- SSHPassword string `json:"sshPassword" jsonapi:"attr,sshPassword"`- SSHPrivateKey string `json:"sshPrivateKey" jsonapi:"attr,sshPrivateKey"`-}-// SQLSyncSchema is the API message for sync schemas.type SQLSyncSchema struct {InstanceID *int `jsonapi:"attr,instanceId"`@@ -75,8 +44,3 @@ type SQLResultSet struct {// A list of SQL check advice.AdviceList []advisor.Advice `jsonapi:"attr,adviceList"`}--// SQLService is the service for SQL.-type SQLService interface {- Ping(ctx context.Context, config *ConnectionInfo) (*SQLResultSet, error)-}diff --git a/backend/server/acl_casbin_policy_owner.csv b/backend/server/acl_casbin_policy_owner.csvindex bd843bd130..ddae14e221 100644--- a/backend/server/acl_casbin_policy_owner.csv+++ b/backend/server/acl_casbin_policy_owner.csv@@ -53,7 +53,6 @@ p, OWNER, /instance/{instanceID}/role/{roleName}, GETp, OWNER, /instance/{instanceID}/role/{roleName}, PATCHp, OWNER, /instance/{instanceID}/role/{roleName}, DELETEp, OWNER, /instances/{instanceName}/databases/{database}, PATCH-p, OWNER, /instance/sample-pg, GETp, OWNER, /database, GETp, OWNER, /database/{databaseID}, GETp, OWNER, /database/{databaseID}, PATCHdiff --git a/backend/server/instance.go b/backend/server/instance.goindex 521ac10b9b..2bdbe04b04 100644--- a/backend/server/instance.go+++ b/backend/server/instance.go@@ -7,25 +7,15 @@ import ("github.com/google/jsonapi""github.com/labstack/echo/v4"- "github.com/pkg/errors"- "github.com/bytebase/bytebase/backend/common"api "github.com/bytebase/bytebase/backend/legacyapi""github.com/bytebase/bytebase/backend/plugin/db"parser "github.com/bytebase/bytebase/backend/plugin/parser/sql""github.com/bytebase/bytebase/backend/plugin/parser/sql/transform"- "github.com/bytebase/bytebase/backend/resources/postgres""github.com/bytebase/bytebase/backend/store")-// pgConnectionInfo represents the embedded postgres instance connection info.-type pgConnectionInfo struct {- Host string `json:"host"`- Port int `json:"port"`- Username string `json:"username"`-}-func (s *Server) registerInstanceRoutes(g *echo.Group) {g.GET("/instance", func(c echo.Context) error {ctx := c.Request().Context()@@ -331,23 +321,4 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {}return nil})-- // Returns the sample embedded postgres instance connection info.- g.GET("/instance/sample-pg", func(c echo.Context) error {- return c.JSON(http.StatusOK, pgConnectionInfo{- Host: common.GetPostgresSocketDir(),- Port: s.profile.SampleDatabasePort,- Username: postgres.SampleUser,- })- })-}--// disallowBytebaseStore prevents users adding Bytebase's own Postgres database.-// Otherwise, users can take control of the database which is a security issue.-func (s *Server) disallowBytebaseStore(engine db.Type, host, port string) error {- // Even when Postgres opens Unix domain socket only for connection, it still requires a port as socket file extension to differentiate different Postgres instances.- if engine == db.Postgres && port == fmt.Sprintf("%v", s.profile.DatastorePort) && host == common.GetPostgresSocketDir() {- return errors.Errorf("instance doesn't exist for host %q and port %q", host, port)- }- return nil}diff --git a/backend/server/sql.go b/backend/server/sql.goindex 071b04b36b..c1077a5880 100644--- a/backend/server/sql.go+++ b/backend/server/sql.go@@ -35,137 +35,6 @@ import ()func (s *Server) registerSQLRoutes(g *echo.Group) {- g.POST("/sql/ping", func(c echo.Context) error {- ctx := c.Request().Context()- connectionInfo := &api.ConnectionInfo{}- if err := jsonapi.UnmarshalPayload(c.Request().Body, connectionInfo); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, "Malformed sql ping request").SetInternal(err)- }- if err := s.disallowBytebaseStore(connectionInfo.Engine, connectionInfo.Host, connectionInfo.Port); err != nil {- return echo.NewHTTPError(http.StatusBadRequest, err.Error()).SetInternal(err)- }-- password := connectionInfo.Password- // Instance detail page has a Test Connection button, if user doesn't input new password and doesn't specify- // to use empty password, we want the connection to use the existing password to test the connection, however,- // we do not transfer the password back to client, thus the client will pass the instanceID to let server- // retrieve the password.- if password == "" && !connectionInfo.UseEmptyPassword && connectionInfo.InstanceID != nil {- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: connectionInfo.InstanceID})- if err != nil {- return err- }- if instance == nil {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("instance %d not found", *connectionInfo.InstanceID))- }- for _, ds := range instance.DataSources {- if ds.Type == api.Admin {- password, err = common.Unobfuscate(ds.ObfuscatedPassword, s.secret)- if err != nil {- return err- }- break- }- }- }-- var sshConfig db.SSHConfig- if connectionInfo.SSHHost != "" {- sshConfig.Host = connectionInfo.SSHHost- sshConfig.Port = connectionInfo.SSHPort- sshConfig.User = connectionInfo.SSHUser- sshConfig.Password = connectionInfo.SSHPassword- sshConfig.PrivateKey = connectionInfo.SSHPrivateKey- }-- var tlsConfig db.TLSConfig- supportTLS := connectionInfo.Engine == db.ClickHouse || connectionInfo.Engine == db.MySQL || connectionInfo.Engine == db.TiDB || connectionInfo.Engine == db.MariaDB || connectionInfo.Engine == db.OceanBase- if supportTLS {- if connectionInfo.SslCa == nil && connectionInfo.SslCert == nil && connectionInfo.SslKey == nil && connectionInfo.InstanceID != nil {- // Frontend will not pass ssl related field if user don't modify ssl suite, we need get ssl suite from database for this case.- instance, err := s.store.GetInstanceV2(ctx, &store.FindInstanceMessage{UID: connectionInfo.InstanceID})- if err != nil {- return err- }- if instance == nil {- return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("instance %d not found", *connectionInfo.InstanceID))- }- for _, ds := range instance.DataSources {- if ds.ObfuscatedSslCa != "" || ds.ObfuscatedSslCert != "" || ds.ObfuscatedSslKey != "" {- sslCa, err := common.Unobfuscate(ds.ObfuscatedSslCa, s.secret)- if err != nil {- return err- }- sslKey, err := common.Unobfuscate(ds.ObfuscatedSslKey, s.secret)- if err != nil {- return err- }- sslCert, err := common.Unobfuscate(ds.ObfuscatedSslCert, s.secret)- if err != nil {- return err- }- tlsConfig = db.TLSConfig{- SslCA: sslCa,- SslKey: sslKey,- SslCert: sslCert,- }- break- }- }- } else if connectionInfo.SslCa != nil && connectionInfo.SslCert != nil && connectionInfo.SslKey != nil {- // Users may add instance and click test connection button now, we need get ssl suite from request for this case.- tlsConfig = db.TLSConfig{- SslCA: *connectionInfo.SslCa,- SslCert: *connectionInfo.SslCert,- SslKey: *connectionInfo.SslKey,- }- } else {- // Unexpected case- return echo.NewHTTPError(http.StatusBadRequest, "TLS/SSL suite must all be set or not be set")- }- }-- db, err := db.Open(- ctx,- connectionInfo.Engine,- db.DriverConfig{},- db.ConnectionConfig{- Username: connectionInfo.Username,- Password: password,- Host: connectionInfo.Host,- Port: connectionInfo.Port,- Database: connectionInfo.Database,- TLSConfig: tlsConfig,- SRV: connectionInfo.SRV,- AuthenticationDatabase: connectionInfo.AuthenticationDatabase,- SID: connectionInfo.SID,- ServiceName: connectionInfo.ServiceName,- SSHConfig: sshConfig,- },- db.ConnectionContext{},- )-- resultSet := &api.SQLResultSet{}- if err != nil {- hostPort := connectionInfo.Host- if connectionInfo.Port != "" {- hostPort += ":" + connectionInfo.Port- }- resultSet.Error = errors.Wrapf(err, "failed to connect %q for user %q", hostPort, connectionInfo.Username).Error()- } else {- defer db.Close(ctx)- if err := db.Ping(ctx); err != nil {- resultSet.Error = err.Error()- }- }-- c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJSONCharsetUTF8)- if err := jsonapi.MarshalPayload(c.Response().Writer, resultSet); err != nil {- return echo.NewHTTPError(http.StatusInternalServerError, "Failed to marshal sql result set response").SetInternal(err)- }- return nil- })-g.POST("/sql/sync-schema", func(c echo.Context) error {ctx := c.Request().Context()sync := &api.SQLSyncSchema{}diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.tsindex 0ed2ddcee5..b800dfa125 100644--- a/frontend/src/store/modules/instance.ts+++ b/frontend/src/store/modules/instance.ts@@ -455,17 +455,6 @@ export const useInstanceStore = defineStore("instance", {return historyList;},- async getSamplePostgresInstance() {- const data = (- await axios.get<{- host: string;- port: number;- username: string;- }>("/api/instance/sample-pg")- ).data;-- return data;- },},});diff --git a/frontend/src/store/modules/sql.ts b/frontend/src/store/modules/sql.tsindex cd21ce41af..65441ad899 100644--- a/frontend/src/store/modules/sql.ts+++ b/frontend/src/store/modules/sql.ts@@ -1,7 +1,6 @@import { defineStore } from "pinia";import axios from "axios";import {- ConnectionInfo,DatabaseId,InstanceId,INSTANCE_OPERATION_TIMEOUT,@@ -54,18 +53,6 @@ export const useSQLStore = defineStore("sql", {return convert(resultSet);},- async ping(connectionInfo: ConnectionInfo) {- const res = (- await axios.post(`/api/sql/ping`, {- data: {- type: "connectionInfo",- attributes: connectionInfo,- },- })- ).data;-- return convert(res.data);- },async syncSchema(instanceId: InstanceId) {const res = (await axios.post(diff --git a/frontend/src/types/sql.ts b/frontend/src/types/sql.tsindex 51725b7148..2550b79fb2 100644--- a/frontend/src/types/sql.ts+++ b/frontend/src/types/sql.ts@@ -1,37 +1,6 @@-import { EngineType } from "./instance";import { InstanceId } from "./id";import { Advice } from "./sqlAdvice";-export type ConnectionInfo = {- engine: EngineType;- host: string;- port?: string;- // In mysql, username can be empty which means anonymous user- username?: string;- password?: string;- useEmptyPassword: boolean;- database?: string;- // Instance detail page has a Test Connection button, if user doesn't input new password, we- // want the connection to use the existing password to test the connection, however, we do- // not transfer the password back to client, thus we here pass the instanceId so the server- // can fetch the corresponding password.- instanceId?: InstanceId;- sslCa?: string;- sslCert?: string;- sslKey?: string;- srv: boolean;- authenticationDatabase: string;- // sid and serviceName are used for Oracle database. Required one of them.- sid: string;- serviceName: string;- // Connection over SSH.- sshHost: string;- sshPort: string;- sshUser: string;- sshPassword: string;- sshPrivateKey: string;-};-export type QueryInfo = {instanceId: InstanceId;databaseName?: string;