RemoveAuditScope implements method for removing a AuditScope
(ctx context.Context, req *orchestrator.RemoveAuditScopeRequest)
| 159 | |
| 160 | // RemoveAuditScope implements method for removing a AuditScope |
| 161 | func (svc *Service) RemoveAuditScope(ctx context.Context, req *orchestrator.RemoveAuditScopeRequest) (response *emptypb.Empty, err error) { |
| 162 | // Validate request |
| 163 | err = api.Validate(req) |
| 164 | if err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | |
| 168 | // Check, if this request has access to the certification target according to our authorization strategy. |
| 169 | if !svc.authz.CheckAccess(ctx, service.AccessDelete, req) { |
| 170 | return nil, service.ErrPermissionDenied |
| 171 | } |
| 172 | |
| 173 | err = svc.storage.Delete(&orchestrator.AuditScope{}, "certification_target_id = ? AND catalog_id = ?", req.CertificationTargetId, req.CatalogId) |
| 174 | if errors.Is(err, persistence.ErrRecordNotFound) { |
| 175 | return nil, status.Errorf(codes.NotFound, "Audit Scope not found") |
| 176 | } else if err != nil { |
| 177 | return nil, status.Errorf(codes.Internal, "database error: %v", err) |
| 178 | } |
| 179 | |
| 180 | // Since we don't have a AuditScope object, we create one to be able to inform the hook about the deleted AuditScope. |
| 181 | auditScope := &orchestrator.AuditScope{ |
| 182 | CertificationTargetId: req.GetCertificationTargetId(), |
| 183 | CatalogId: req.GetCatalogId(), |
| 184 | } |
| 185 | go svc.informToeHooks(ctx, &orchestrator.AuditScopeChangeEvent{Type: orchestrator.AuditScopeChangeEvent_TYPE_AUDIT_SCOPE_REMOVED, AuditScope: auditScope}, nil) |
| 186 | |
| 187 | logging.LogRequest(log, logrus.DebugLevel, logging.Remove, req, fmt.Sprintf("and Catalog '%s'", req.GetCatalogId())) |
| 188 | |
| 189 | return &emptypb.Empty{}, nil |
| 190 | } |
| 191 | |
| 192 | // informToeHooks informs the registered hook function either of a event change for the Audit Scope or Control Monitoring Status |
| 193 | func (s *Service) informToeHooks(ctx context.Context, event *orchestrator.AuditScopeChangeEvent, err error) { |