GetReviewConfigForDatabase will get the review config for a database.
(ctx context.Context, workspaceID string, database *DatabaseMessage)
| 281 | |
| 282 | // GetReviewConfigForDatabase will get the review config for a database. |
| 283 | func (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 | |
| 311 | func (s *Store) getReviewConfigByResource(ctx context.Context, workspaceID string, resourceType storepb.Policy_Resource, resource string) (*storepb.ReviewConfigPayload, error) { |
| 312 | policy, err := s.GetPolicy(ctx, &FindPolicyMessage{ |
no test coverage detected