MCPcopy Create free account
hub / github.com/bytebase/bytebase / GetReviewConfigForDatabase

Method GetReviewConfigForDatabase

backend/store/policy.go:283–309  ·  view source on GitHub ↗

GetReviewConfigForDatabase will get the review config for a database.

(ctx context.Context, workspaceID string, database *DatabaseMessage)

Source from the content-addressed store, hash-verified

281
282// GetReviewConfigForDatabase will get the review config for a database.
283func (s *Store) GetReviewConfigForDatabase(ctx context.Context, workspaceID string, database *DatabaseMessage) (*storepb.ReviewConfigPayload, error) {
284 resources := []*reviewConfigResource{}
285 if database.EffectiveEnvironmentID != nil {
286 resources = append(resources, &reviewConfigResource{
287 resourceType: storepb.Policy_ENVIRONMENT,
288 resource: common.FormatEnvironment(*database.EffectiveEnvironmentID),
289 })
290 }
291 resources = append(resources, &reviewConfigResource{
292 resourceType: storepb.Policy_PROJECT,
293 resource: common.FormatProject(database.ProjectID),
294 })
295 for _, v := range resources {
296 reviewConfig, err := s.getReviewConfigByResource(ctx, workspaceID, v.resourceType, v.resource)
297 if err != nil {
298 slog.Debug("failed to get review config", slog.String("resource_type", v.resourceType.String()), slog.String("database", database.DatabaseName), log.BBError(err))
299 continue
300 }
301 if reviewConfig == nil {
302 slog.Debug("review config is empty", slog.String("resource_type", v.resourceType.String()), slog.String("database", database.DatabaseName), log.BBError(err))
303 continue
304 }
305 return reviewConfig, nil
306 }
307
308 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("SQL review policy for database %s not found", database.DatabaseName)}
309}
310
311func (s *Store) getReviewConfigByResource(ctx context.Context, workspaceID string, resourceType storepb.Policy_Resource, resource string) (*storepb.ReviewConfigPayload, error) {
312 policy, err := s.GetPolicy(ctx, &FindPolicyMessage{

Callers 2

runReviewMethod · 0.80

Calls 7

FormatEnvironmentFunction · 0.92
FormatProjectFunction · 0.92
BBErrorFunction · 0.92
DebugMethod · 0.80
ErrorfMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected