Skip to content

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

chore: clean up raw objects in server package (#1252)

Yilong Lif0adf4d5c284
diff --git a/server/instance.go b/server/instance.go
index 15d78cacb8..a9634464da 100644
--- a/server/instance.go
+++ b/server/instance.go
@@ -408,22 +408,6 @@ func (s *Server) registerInstanceRoutes(g *echo.Group) {
})
}
-func (s *Server) findInstanceAdminPasswordByID(ctx context.Context, instanceID int) (string, error) {
- dataSourceFind := &api.DataSourceFind{
- InstanceID: &instanceID,
- }
- dataSourceRawList, err := s.store.FindDataSource(ctx, dataSourceFind)
- if err != nil {
- return "", err
- }
- for _, dataSourceRaw := range dataSourceRawList {
- if dataSourceRaw.Type == api.Admin {
- return dataSourceRaw.Password, nil
- }
- }
- return "", &common.Error{Code: common.NotFound, Err: fmt.Errorf("missing admin password for instance with ID %d", instanceID)}
-}
-
// instanceCountGuard is a feature guard for instance count.
// We only count instances with NORMAL status since users cannot make any operations for ARCHIVED one.
func (s *Server) instanceCountGuard(ctx context.Context) error {
diff --git a/server/label.go b/server/label.go
index 653e782bd8..c1228de142 100644
--- a/server/label.go
+++ b/server/label.go
@@ -24,13 +24,13 @@ func (s *Server) registerLabelRoutes(g *echo.Group) {
}
// Add reserved environment key.
- envRawList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{RowStatus: &rowStatus})
+ envList, err := s.store.FindEnvironment(ctx, &api.EnvironmentFind{RowStatus: &rowStatus})
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to fetch environments").SetInternal(err)
}
envKey := &api.LabelKey{Key: api.EnvironmentKeyName}
- for _, envRaw := range envRawList {
- envKey.ValueList = append(envKey.ValueList, envRaw.Name)
+ for _, env := range envList {
+ envKey.ValueList = append(envKey.ValueList, env.Name)
}
labelKeyList = append(labelKeyList, envKey)
diff --git a/server/sql.go b/server/sql.go
index 2b086ca4cb..80f879bfaf 100644
--- a/server/sql.go
+++ b/server/sql.go
@@ -36,7 +36,7 @@ func (s *Server) registerSQLRoutes(g *echo.Group) {
// 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 {
- adminPassword, err := s.findInstanceAdminPasswordByID(ctx, *connectionInfo.InstanceID)
+ adminPassword, err := s.store.GetInstanceAdminPasswordByID(ctx, *connectionInfo.InstanceID)
if err != nil {
return echo.NewHTTPError(http.StatusInternalServerError, fmt.Sprintf("Failed to retrieve admin password for instance: %d", connectionInfo.InstanceID)).SetInternal(err)
}
diff --git a/server/vcs.go b/server/vcs.go
index 3417161672..894d9b459e 100644
--- a/server/vcs.go
+++ b/server/vcs.go
@@ -162,7 +162,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
return echo.NewHTTPError(http.StatusNotFound, fmt.Sprintf("Failed to find VCS, ID: %v", id))
}
- externalRepoListRaw, err := vcs.Get(vcsFound.Type, vcs.ProviderConfig{Logger: s.l}).FetchRepositoryList(
+ repoList, err := vcs.Get(vcsFound.Type, vcs.ProviderConfig{Logger: s.l}).FetchRepositoryList(
ctx,
common.OauthContext{
ClientID: vcsFound.ApplicationID,
@@ -178,7 +178,7 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
}
var externalRepoList []*api.ExternalRepository
- for _, repo := range externalRepoListRaw {
+ for _, repo := range repoList {
externalRepoList = append(externalRepoList, &api.ExternalRepository{
ID: repo.ID,
FullPath: repo.FullPath,
diff --git a/store/instance.go b/store/instance.go
index c520c09b40..6d5deca73a 100644
--- a/store/instance.go
+++ b/store/instance.go
@@ -152,6 +152,23 @@ func (s *Store) CountInstance(ctx context.Context, find *api.InstanceFind) (int,
return count, nil
}
+// GetInstanceAdminPasswordByID gets admin password of instance
+func (s *Store) GetInstanceAdminPasswordByID(ctx context.Context, instanceID int) (string, error) {
+ dataSourceFind := &api.DataSourceFind{
+ InstanceID: &instanceID,
+ }
+ dataSourceRawList, err := s.FindDataSource(ctx, dataSourceFind)
+ if err != nil {
+ return "", err
+ }
+ for _, dataSourceRaw := range dataSourceRawList {
+ if dataSourceRaw.Type == api.Admin {
+ return dataSourceRaw.Password, nil
+ }
+ }
+ return "", &common.Error{Code: common.NotFound, Err: fmt.Errorf("missing admin password for instance with ID %d", instanceID)}
+}
+
//
// private function
//