示例#1
0
        internal IResponseWriter TryExecute(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user)
        {
            _workspaceGuid = EnsureWorkspaceIdValid(workspaceId);
            _serializer    = new Dev2JsonSerializer();

            PrepareDataObject(webRequest, serviceName, headers, user, _workspaceGuid, out _resource);
            var isTestCoverage = _dataObject.ReturnType == EmitionTypes.Cover || _dataObject.ReturnType == EmitionTypes.CoverJson;
            var isTestRun      = (_dataObject.ReturnType == EmitionTypes.TEST ||
                                  _dataObject.ReturnType == EmitionTypes.TRX) && _dataObject.TestName == "*";

            if (isTestRun)
            {
                if (_serviceTestExecutor == null)
                {
                    _serviceTestExecutor = new ServiceTestExecutor();
                }
                return(ExecuteAsTest(user));
            }

            if (isTestCoverage)
            {
                return(ExecuteAsCoverage(webRequest, serviceName, _resource));
            }

            if (_resource is null)
            {
                var msg = string.Format(Warewolf.Resource.Errors.ErrorResource.ServiceNotFound, serviceName);
                _dataObject.Environment.AddError(msg);
                _dataObject.ExecutionException = new Exception(msg);
                _executionDataListId           = GlobalConstants.NullDataListID;
                return(null);
            }

            var workflowCanBeExecutedByGroup = _dataObject.CanExecuteCurrentResource(_resource, _authorizationService);

            _canExecute = workflowCanBeExecutedByGroup;

            _executionDataListId = GlobalConstants.NullDataListID;
            if (!_canExecute)
            {
                var message = webRequest.IsUrlWithTokenPrefix
                        ? Warewolf.Resource.Errors.ErrorResource.TokenNotAuthorizedToExecuteOuterWorkflowException
                        : Warewolf.Resource.Errors.ErrorResource.UserNotAuthorizedToExecuteOuterWorkflowException;

                var errorMessage = string.Format(message, _dataObject.ExecutingUser?.Identity.Name, _dataObject.ServiceName);
                _dataObject.Environment.AddError(errorMessage);
                _dataObject.ExecutionException = new AccessDeniedException(errorMessage);
            }
            else
            {
                if (_dataObject.ReturnType != EmitionTypes.OPENAPI)
                {
                    Thread.CurrentPrincipal = user;
                    _executionDataListId    = DoExecution(webRequest, serviceName, _workspaceGuid, _dataObject, user);
                }
            }

            return(null);
        }
示例#2
0
            internal IResponseWriter TryExecute(WebRequestTO webRequest, string serviceName, string workspaceId, NameValueCollection headers, IPrincipal user)
            {
                _executePayload = "";
                _workspaceGuid  = EnsureWorkspaceIdValid(workspaceId);
                _serializer     = new Dev2JsonSerializer();

                PrepareDataObject(webRequest, serviceName, headers, user, _workspaceGuid, out _resource);
                if (_resource is null)
                {
                    var msg = string.Format(Warewolf.Resource.Errors.ErrorResource.ServiceNotFound, serviceName);
                    _dataObject.Environment.AddError(msg);
                    _dataObject.ExecutionException = new Exception(msg);
                    _executionDlid = GlobalConstants.NullDataListID;
                    return(null);
                }
                _canExecute = _dataObject.CanExecuteCurrentResource(_resource, _authorizationService);
                if (!_canExecute)
                {
                    var errorMessage = string.Format(Warewolf.Resource.Errors.ErrorResource.UserNotAuthorizedToExecuteOuterWorkflowException, _dataObject.ExecutingUser.Identity.Name, _dataObject.ServiceName);
                    _dataObject.Environment.AddError(errorMessage);
                    _dataObject.ExecutionException = new Exception(errorMessage);
                }

                _executionDlid = GlobalConstants.NullDataListID;

                if (_canExecute && _dataObject.ReturnType != EmitionTypes.SWAGGER)
                {
                    Thread.CurrentPrincipal = user;
                    var userPrinciple = user;
                    if ((_dataObject.ReturnType == EmitionTypes.TEST || _dataObject.ReturnType == EmitionTypes.TRX) && _dataObject.TestName == "*")
                    {
                        return(ExecuteAsTest(serviceName, _executePayload, _workspaceGuid, _dataObject, _serializer, userPrinciple));
                    }

                    _executionDlid = DoExecution(webRequest, serviceName, _workspaceGuid, _dataObject, userPrinciple);
                }
                return(null);
            }