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

Method getReviewConfigByResource

backend/store/policy.go:311–354  ·  view source on GitHub ↗
(ctx context.Context, workspaceID string, resourceType storepb.Policy_Resource, resource string)

Source from the content-addressed store, hash-verified

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{
313 Workspace: workspaceID,
314 ResourceType: &resourceType,
315 Resource: &resource,
316 Type: new(storepb.Policy_TAG),
317 })
318 if err != nil {
319 return nil, err
320 }
321 if policy == nil {
322 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("tag policy for resource %v/%s not found", resourceType, resource)}
323 }
324 if !policy.Enforce {
325 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("tag policy is not enforced for resource %v/%s", resourceType, resource)}
326 }
327
328 payload := &storepb.TagPolicy{}
329 if err := common.ProtojsonUnmarshaler.Unmarshal([]byte(policy.Payload), payload); err != nil {
330 return nil, errors.Wrapf(err, "failed to unmarshal tag policy payload")
331 }
332
333 reviewConfigName, ok := payload.Tags[common.ReservedTagReviewConfig]
334 if !ok {
335 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("review config tag for resource %v/%s not found", resourceType, resource)}
336 }
337 reviewConfigID, err := common.GetReviewConfigID(reviewConfigName)
338 if err != nil {
339 return nil, errors.Wrapf(err, "failed to extract review config %s", reviewConfigName)
340 }
341
342 reviewConfig, err := s.GetReviewConfig(ctx, workspaceID, reviewConfigID)
343 if err != nil {
344 return nil, err
345 }
346 if reviewConfig == nil {
347 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("review config for resource %v/%s not found", resourceType, resource)}
348 }
349 if !reviewConfig.Enforce {
350 return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("review config is not enforced for resource %v/%s", resourceType, resource)}
351 }
352
353 return reviewConfig.Payload, nil
354}
355
356// GetMaskingRulePolicy will get the masking rule policy.
357func (s *Store) GetMaskingRulePolicy(ctx context.Context, workspaceID string) (*storepb.MaskingRulePolicy, error) {

Callers 1

Calls 5

GetPolicyMethod · 0.95
GetReviewConfigMethod · 0.95
GetReviewConfigIDFunction · 0.92
ErrorfMethod · 0.80
UnmarshalMethod · 0.80

Tested by

no test coverage detected