Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Use include=secret to determine whether to return sensitive info like db password

天舟4fb9f4fcb3ea
diff --git a/backend/server/database.go b/backend/server/database.go
index 6df8296e1b..325ae996af 100644
--- a/backend/server/database.go
+++ b/backend/server/database.go
@@ -168,7 +168,7 @@ func (s *Server) ComposeDatabaseRelationship(ctx context.Context, database *api.
return err
}
- database.Instance, err = s.ComposeInstanceById(context.Background(), database.InstanceId, false /*includeSecret*/)
+ database.Instance, err = s.ComposeInstanceById(context.Background(), database.InstanceId, includeList)
if err != nil {
return err
}
diff --git a/backend/server/instance.go b/backend/server/instance.go
index f50ae888f8..77bac16270 100644
--- a/backend/server/instance.go
+++ b/backend/server/instance.go
@@ -29,7 +29,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to create instance").SetInternal(err)
}
- if err := s.ComposeInstanceRelationship(context.Background(), instance, true /*includeSecret*/); err != nil {
+ if err := s.ComposeInstanceRelationship(context.Background(), instance, c.Get(getIncludeKey()).([]string)); err != nil {
return err
}
@@ -55,7 +55,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
}
for _, instance := range list {
- if err := s.ComposeInstanceRelationship(context.Background(), instance, false /*includeSecret*/); err != nil {
+ if err := s.ComposeInstanceRelationship(context.Background(), instance, c.Get(getIncludeKey()).([]string)); err != nil {
return err
}
}
@@ -73,7 +73,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("ID is not a number: %s", c.Param("id"))).SetInternal(err)
}
- instance, err := s.ComposeInstanceById(context.Background(), id, true /*includeSecret*/)
+ instance, err := s.ComposeInstanceById(context.Background(), id, c.Get(getIncludeKey()).([]string))
if err != nil {
if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", id))
@@ -147,7 +147,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
}
}
- if err := s.ComposeInstanceRelationship(context.Background(), instance, true /*includeSecret*/); err != nil {
+ if err := s.ComposeInstanceRelationship(context.Background(), instance, c.Get(getIncludeKey()).([]string)); err != nil {
return err
}
@@ -159,7 +159,7 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
})
}
-func (s *Server) ComposeInstanceById(ctx context.Context, id int, includeSecret bool) (*api.Instance, error) {
+func (s *Server) ComposeInstanceById(ctx context.Context, id int, includeList []string) (*api.Instance, error) {
instanceFind := &api.InstanceFind{
ID: &id,
}
@@ -168,14 +168,14 @@ func (s *Server) ComposeInstanceById(ctx context.Context, id int, includeSecret
return nil, err
}
- if err := s.ComposeInstanceRelationship(ctx, instance, includeSecret); err != nil {
+ if err := s.ComposeInstanceRelationship(ctx, instance, includeList); err != nil {
return nil, err
}
return instance, nil
}
-func (s *Server) ComposeInstanceRelationship(ctx context.Context, instance *api.Instance, includeSecret bool) error {
+func (s *Server) ComposeInstanceRelationship(ctx context.Context, instance *api.Instance, includeList []string) error {
var err error
instance.Creator, err = s.ComposePrincipalById(context.Background(), instance.CreatorId, []string{})
@@ -193,7 +193,7 @@ func (s *Server) ComposeInstanceRelationship(ctx context.Context, instance *api.
return err
}
- if includeSecret {
+ if bytebase.FindString(includeList, SECRET_KEY) >= 0 {
dataSourceFind := &api.DataSourceFind{
InstanceId: &instance.ID,
}
diff --git a/backend/server/server.go b/backend/server/server.go
index 1f07540b05..ce0ff2b3ab 100644
--- a/backend/server/server.go
+++ b/backend/server/server.go
@@ -19,6 +19,10 @@ import (
scas "github.com/qiangmzsx/string-adapter/v2"
)
+const (
+ SECRET_KEY = "secret"
+)
+
type Server struct {
l *bytebase.Logger
TaskScheduler *TaskScheduler
diff --git a/backend/server/sql.go b/backend/server/sql.go
index 7847516046..71eecf65cc 100644
--- a/backend/server/sql.go
+++ b/backend/server/sql.go
@@ -48,7 +48,7 @@ func (s *Server) registerSqlRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted sql sync schema request").SetInternal(err)
}
- instance, err := s.ComposeInstanceById(context.Background(), sync.InstanceId, true /*includeSecret*/)
+ instance, err := s.ComposeInstanceById(context.Background(), sync.InstanceId, []string{SECRET_KEY})
if err != nil {
if bytebase.ErrorCode(err) == bytebase.ENOTFOUND {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Instance ID not found: %d", sync.InstanceId))
diff --git a/backend/util.go b/backend/util.go
index b74d7ff0d7..bc995b67af 100644
--- a/backend/util.go
+++ b/backend/util.go
@@ -2,11 +2,11 @@ package bytebase
import "sort"
-func FindString(strings []string, search string) string {
+func FindString(strings []string, search string) int {
sort.Strings(strings)
i := sort.SearchStrings(strings, search)
if i == len(strings) {
- return ""
+ return -1
}
- return strings[i]
+ return i
}
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 8e119421e7..2df1dffb91 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -124,8 +124,8 @@ const actions = {
{ commit, rootGetters }: any,
instanceId: InstanceId
) {
- // secret=true to return username/password when requesting the specific instance id
- const data = (await axios.get(`/api/instance/${instanceId}?secret=true`))
+ // include=secret to return username/password when requesting the specific instance id
+ const data = (await axios.get(`/api/instance/${instanceId}?include=secret`))
.data;
const instance = convert(data.data, data.included, rootGetters);
@@ -141,7 +141,7 @@ const actions = {
newInstance: InstanceCreate
) {
const data = (
- await axios.post(`/api/instance?secret=true`, {
+ await axios.post(`/api/instance?include=secret`, {
data: {
type: "InstanceCreate",
attributes: newInstance,