| 43 | ) |
| 44 | |
| 45 | func (svc *Service) CreateAuditScope(ctx context.Context, req *orchestrator.CreateAuditScopeRequest) (res *orchestrator.AuditScope, err error) { |
| 46 | // Validate request |
| 47 | err = api.Validate(req) |
| 48 | if err != nil { |
| 49 | return nil, err |
| 50 | } |
| 51 | |
| 52 | // Check, if this request has access to the certification target according to our authorization strategy. |
| 53 | if !svc.authz.CheckAccess(ctx, service.AccessCreate, req) { |
| 54 | return nil, service.ErrPermissionDenied |
| 55 | } |
| 56 | |
| 57 | // Create the Audit Scope |
| 58 | err = svc.storage.Create(&req.AuditScope) |
| 59 | if err != nil && errors.Is(err, persistence.ErrConstraintFailed) { |
| 60 | return nil, status.Errorf(codes.InvalidArgument, "invalid catalog or certification target") |
| 61 | } |
| 62 | if err != nil { |
| 63 | return nil, status.Errorf(codes.Internal, "database error: %v", err) |
| 64 | } |
| 65 | |
| 66 | go svc.informToeHooks(ctx, &orchestrator.AuditScopeChangeEvent{Type: orchestrator.AuditScopeChangeEvent_TYPE_AUDIT_SCOPE_CREATED, AuditScope: req.AuditScope}, nil) |
| 67 | |
| 68 | res = req.AuditScope |
| 69 | |
| 70 | logging.LogRequest(log, logrus.DebugLevel, logging.Create, req, fmt.Sprintf("and Catalog '%s'", req.AuditScope.GetCatalogId())) |
| 71 | |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | // GetAuditScope implements method for getting a AuditScope, e.g. to show its state in the UI |
| 76 | func (svc *Service) GetAuditScope(ctx context.Context, req *orchestrator.GetAuditScopeRequest) (response *orchestrator.AuditScope, err error) { |