Search in sources :

Example 61 with Request

use of spark.Request in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddAuthInvalidSigned.

public void testRepoAddAuthInvalidSigned() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ApiService mockApiService = mock(ApiService.class);
    when(mockApiService.validateRequest("test", "test", "pub=test&reponame=test&repourl=test&repotype=test&repousername=test&repopassword=test&reposource=test&repobranch=test", ApiService.HmacType.SHA1)).thenReturn(false);
    ApiRouteService apiRouteService = new ApiRouteService(mockApiService, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = true;
    when(mockRequest.queryParams("reponame")).thenReturn("test");
    when(mockRequest.queryParams("repourl")).thenReturn("test");
    when(mockRequest.queryParams("repotype")).thenReturn("test");
    when(mockRequest.queryParams("repousername")).thenReturn("test");
    when(mockRequest.queryParams("repopassword")).thenReturn("test");
    when(mockRequest.queryParams("reposource")).thenReturn("test");
    when(mockRequest.queryParams("repobranch")).thenReturn("test");
    when(mockRequest.queryParams("pub")).thenReturn("test");
    when(mockRequest.queryParams("sig")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("invalid signed url");
    assertThat(apiResponse.isSucessful()).isFalse();
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 62 with Request

use of spark.Request in project searchcode-server by boyter.

the class ApiRouteServiceTest method testRepoAddMissingRepoSource.

public void testRepoAddMissingRepoSource() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo mockSQLiteRepo = mock(SQLiteRepo.class);
    ApiRouteService apiRouteService = new ApiRouteService(null, null, mockSQLiteRepo, null, null, null, new Helpers(), new LoggerWrapper());
    apiRouteService.apiEnabled = true;
    apiRouteService.apiAuth = false;
    when(mockRequest.queryParams("reponame")).thenReturn("test");
    when(mockRequest.queryParams("repourl")).thenReturn("test");
    when(mockRequest.queryParams("repotype")).thenReturn("test");
    when(mockRequest.queryParams("repousername")).thenReturn("test");
    when(mockRequest.queryParams("repopassword")).thenReturn("test");
    ApiResponse apiResponse = apiRouteService.repoAdd(mockRequest, null);
    assertThat(apiResponse.getMessage()).isEqualTo("reposource is a required parameter");
    assertThat(apiResponse.isSucessful()).isFalse();
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) ApiResponse(com.searchcode.app.dto.api.ApiResponse) RepoResultApiResponse(com.searchcode.app.dto.api.RepoResultApiResponse)

Example 63 with Request

use of spark.Request in project searchcode-server by boyter.

the class ApiRouteServiceTest method testGetIndexTime.

public void testGetIndexTime() {
    Request mockRequest = mock(Request.class);
    SQLiteRepo SQLiteRepoMock = mock(SQLiteRepo.class);
    when(mockRequest.queryParams("reponame")).thenReturn("somename");
    when(mockRequest.queryParams()).thenReturn((new HashMap<String, String>() {

        {
            put("reponame", "reponame");
        }
    }).keySet());
    when(SQLiteRepoMock.getRepoByName("somename")).thenReturn(Optional.of(new RepoResult().setRowId(0).setName("name").setScm("scm").setUrl("url").setUsername("username").setPassword("password").setSource("source").setBranch("branch").setData("{\"rowId\":1,\"name\":\"test\",\"scm\":\"git\",\"url\":\"/test/\",\"username\":\"\",\"password\":\"\",\"source\":\"\",\"branch\":\"master\",\"data\":{\"averageIndexTimeSeconds\":9,\"indexStatus\":\"success\",\"jobRunTime\":{\"seconds\":1496356541,\"nanos\":188000000}}}")));
    ApiRouteService apiRouteService = new ApiRouteService(null, null, SQLiteRepoMock, null, null, null, new Helpers(), new LoggerWrapper());
    String averageIndexTimeSeconds = apiRouteService.getIndexTime(mockRequest, null);
    assertThat(averageIndexTimeSeconds).contains("years ago");
}
Also used : ApiRouteService(com.searchcode.app.service.route.ApiRouteService) Helpers(com.searchcode.app.util.Helpers) LoggerWrapper(com.searchcode.app.util.LoggerWrapper) Request(spark.Request) SQLiteRepo(com.searchcode.app.dao.SQLiteRepo) Matchers.anyString(org.mockito.Matchers.anyString) RepoResult(com.searchcode.app.model.RepoResult)

Example 64 with Request

use of spark.Request in project waltz by khartec.

the class AttestationInstanceEndpoint method register.

@Override
public void register() {
    String attestInstancePath = mkPath(BASE_URL, "attest", ":id");
    String attestEntityForUserPath = mkPath(BASE_URL, "attest-entity");
    String findByEntityRefPath = mkPath(BASE_URL, "entity", ":kind", ":id");
    String findByRunIdPath = mkPath(BASE_URL, "run", ":id");
    String findUnattestedByUserPath = mkPath(BASE_URL, "unattested", "user");
    String findAllByUserPath = mkPath(BASE_URL, "all", "user");
    String findHistoricalForPendingByUserPath = mkPath(BASE_URL, "historical", "user");
    String findPersonsByInstancePath = mkPath(BASE_URL, ":id", "person");
    String findBySelectorPath = mkPath(BASE_URL, "selector");
    String findLatestMeasurableAttestationsPath = mkPath(BASE_URL, "latest", "measurable-category", "entity", ":kind", ":id");
    String findApplicationAttestationInstancesForKindAndSelectorPath = mkPath(BASE_URL, "applications", "attested-entity", ":kind", ":id");
    String findApplicationAttestationSummaryForSelectorPath = mkPath(BASE_URL, "app-summary");
    String cleanupOrphansPath = mkPath(BASE_URL, "cleanup-orphans");
    String reassignRecipientsPath = mkPath(BASE_URL, "reassign-recipients");
    String getCountsOfRecipientsToReassignPath = mkPath(BASE_URL, "reassign-counts");
    DatumRoute<Boolean> attestInstanceRoute = (req, res) -> attestationInstanceService.attestInstance(getId(req), getUsername(req));
    ListRoute<AttestationInstance> findByEntityRefRoute = (req, res) -> attestationInstanceService.findByEntityReference(getEntityReference(req));
    ListRoute<AttestationInstance> findUnattestedByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), true);
    ListRoute<AttestationInstance> findAllByRecipientRoute = (req, res) -> attestationInstanceService.findByRecipient(getUsername(req), false);
    ListRoute<AttestationInstance> findHistoricalForPendingByRecipientRoute = (req, res) -> attestationInstanceService.findHistoricalForPendingByUserId(getUsername(req));
    ListRoute<AttestationInstance> findByRunIdRoute = (req, res) -> attestationInstanceService.findByRunId(getId(req));
    ListRoute<Person> findPersonsByInstanceRoute = (request, response) -> {
        long id = Long.valueOf(request.params("id"));
        return attestationInstanceService.findPersonsByInstanceId(id);
    };
    ListRoute<AttestationInstance> findBySelectorRoute = ((request, response) -> attestationInstanceService.findByIdSelector(readIdSelectionOptionsFromBody(request)));
    ListRoute<LatestMeasurableAttestationInfo> findLatestMeasurableAttestationsRoute = ((request, response) -> attestationInstanceService.findLatestMeasurableAttestations(getEntityReference(request)));
    ListRoute<ApplicationAttestationInstanceSummary> findApplicationAttestationInstancesForKindAndSelectorRoute = ((request, response) -> {
        EntityKind attestedKind = getKind(request);
        Long attestedId = StringUtilities.parseLong(request.params("id"), null);
        ApplicationAttestationInstanceInfo applicationAttestationInstanceInfo = readBody(request, ApplicationAttestationInstanceInfo.class);
        return attestationInstanceService.findApplicationAttestationInstancesForKindAndSelector(attestedKind, attestedId, applicationAttestationInstanceInfo);
    });
    ListRoute<ApplicationAttestationSummaryCounts> findApplicationAttestationSummaryForSelectorRoute = ((request, response) -> attestationInstanceService.findAttestationInstanceSummaryForSelector(readBody(request, ApplicationAttestationInstanceInfo.class)));
    DatumRoute<Boolean> attestEntityForUserRoute = (req, res) -> attestationInstanceService.attestForEntity(getUsername(req), readCreateCommand(req));
    postForDatum(attestInstancePath, attestInstanceRoute);
    postForDatum(attestEntityForUserPath, attestEntityForUserRoute);
    getForList(findByEntityRefPath, findByEntityRefRoute);
    getForList(findUnattestedByUserPath, findUnattestedByRecipientRoute);
    getForList(findAllByUserPath, findAllByRecipientRoute);
    getForList(findHistoricalForPendingByUserPath, findHistoricalForPendingByRecipientRoute);
    getForList(findByRunIdPath, findByRunIdRoute);
    getForList(findPersonsByInstancePath, findPersonsByInstanceRoute);
    getForList(findLatestMeasurableAttestationsPath, findLatestMeasurableAttestationsRoute);
    postForList(findBySelectorPath, findBySelectorRoute);
    postForList(findApplicationAttestationInstancesForKindAndSelectorPath, findApplicationAttestationInstancesForKindAndSelectorRoute);
    postForList(findApplicationAttestationSummaryForSelectorPath, findApplicationAttestationSummaryForSelectorRoute);
    getForDatum(cleanupOrphansPath, this::cleanupOrphansRoute);
    postForDatum(reassignRecipientsPath, this::reassignRecipientsRoute);
    getForDatum(getCountsOfRecipientsToReassignPath, this::getCountsOfRecipientsToReassign);
}
Also used : ListRoute(org.finos.waltz.web.ListRoute) Logger(org.slf4j.Logger) Endpoint(org.finos.waltz.web.endpoints.Endpoint) EntityKind(org.finos.waltz.model.EntityKind) DatumRoute(org.finos.waltz.web.DatumRoute) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) IOException(java.io.IOException) Person(org.finos.waltz.model.person.Person) Checks.checkNotNull(org.finos.waltz.common.Checks.checkNotNull) UserRoleService(org.finos.waltz.service.user.UserRoleService) Service(org.springframework.stereotype.Service) Request(spark.Request) AttestationInstanceService(org.finos.waltz.service.attestation.AttestationInstanceService) WebUtilities(org.finos.waltz.web.WebUtilities) SystemRole(org.finos.waltz.model.user.SystemRole) Response(spark.Response) org.finos.waltz.model.attestation(org.finos.waltz.model.attestation) EndpointUtilities(org.finos.waltz.web.endpoints.EndpointUtilities) StringUtilities(org.finos.waltz.common.StringUtilities) Person(org.finos.waltz.model.person.Person) EntityKind(org.finos.waltz.model.EntityKind)

Example 65 with Request

use of spark.Request in project gocd by gocd.

the class EnvironmentsControllerV3 method partialUpdate.

public String partialUpdate(Request request, Response response) {
    JsonReader jsonReader = GsonTransformer.getInstance().jsonReaderFrom(request.body());
    PatchEnvironmentRequest req = PatchEnvironmentRequestRepresenter.fromJSON(jsonReader);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    String environmentName = request.params("name");
    EnvironmentConfig environmentConfig = fetchEntityFromConfig(environmentName);
    Optional<EnvironmentVariableConfig> parsingErrors = req.getEnvironmentVariablesToAdd().stream().filter(envVar -> !envVar.errors().isEmpty()).findFirst();
    if (parsingErrors.isPresent()) {
        EnvironmentVariablesConfig configs = new EnvironmentVariablesConfig(req.getEnvironmentVariablesToAdd());
        response.status(422);
        return MessageJson.create("Error parsing patch request", writer -> toJSONArray(writer, "environment_variables", configs));
    }
    environmentConfigService.patchEnvironment(environmentConfig, req.getPipelineToAdd(), req.getPipelineToRemove(), req.getEnvironmentVariablesToAdd(), req.getEnvironmentVariablesToRemove(), currentUsername(), result);
    EnvironmentConfig updateConfigElement = fetchEntityFromConfig(environmentName);
    setEtagHeader(updateConfigElement, response);
    return handleCreateOrUpdateResponse(request, response, updateConfigElement, result);
}
Also used : CrudController(com.thoughtworks.go.api.CrudController) EntityType(com.thoughtworks.go.config.exceptions.EntityType) SupportedEntity(com.thoughtworks.go.config.policy.SupportedEntity) Autowired(org.springframework.beans.factory.annotation.Autowired) MessageJson(com.thoughtworks.go.api.util.MessageJson) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) EntityHashingService(com.thoughtworks.go.server.service.EntityHashingService) Collectors.toCollection(java.util.stream.Collectors.toCollection) JsonReader(com.thoughtworks.go.api.representers.JsonReader) EnvironmentConfigService(com.thoughtworks.go.server.service.EnvironmentConfigService) ConfigElementForEdit(com.thoughtworks.go.domain.ConfigElementForEdit) Request(spark.Request) SparkSpringController(com.thoughtworks.go.spark.spring.SparkSpringController) ApiVersion(com.thoughtworks.go.api.ApiVersion) Routes(com.thoughtworks.go.spark.Routes) EnvironmentsRepresenter.toJSON(com.thoughtworks.go.apiv3.environments.representers.EnvironmentsRepresenter.toJSON) Comparator.comparing(java.util.Comparator.comparing) ApiController(com.thoughtworks.go.api.ApiController) GsonTransformer(com.thoughtworks.go.api.util.GsonTransformer) Set(java.util.Set) HaltApiResponses(com.thoughtworks.go.api.util.HaltApiResponses) IOException(java.io.IOException) com.thoughtworks.go.config(com.thoughtworks.go.config) String.format(java.lang.String.format) ApiAuthenticationHelper(com.thoughtworks.go.api.spring.ApiAuthenticationHelper) Consumer(java.util.function.Consumer) OutputWriter(com.thoughtworks.go.api.base.OutputWriter) Component(org.springframework.stereotype.Component) PatchEnvironmentRequestRepresenter(com.thoughtworks.go.apiv3.environments.representers.PatchEnvironmentRequestRepresenter) PatchEnvironmentRequest(com.thoughtworks.go.apiv3.environments.model.PatchEnvironmentRequest) Response(spark.Response) Optional(java.util.Optional) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) EnvironmentVariableRepresenter.toJSONArray(com.thoughtworks.go.api.representers.EnvironmentVariableRepresenter.toJSONArray) EnvironmentRepresenter(com.thoughtworks.go.apiv3.environments.representers.EnvironmentRepresenter) Spark(spark.Spark) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PatchEnvironmentRequest(com.thoughtworks.go.apiv3.environments.model.PatchEnvironmentRequest) JsonReader(com.thoughtworks.go.api.representers.JsonReader)

Aggregations

Request (spark.Request)70 ApiRouteService (com.searchcode.app.service.route.ApiRouteService)35 RepoResultApiResponse (com.searchcode.app.dto.api.RepoResultApiResponse)33 Helpers (com.searchcode.app.util.Helpers)31 LoggerWrapper (com.searchcode.app.util.LoggerWrapper)31 SQLiteRepo (com.searchcode.app.dao.SQLiteRepo)28 ApiResponse (com.searchcode.app.dto.api.ApiResponse)28 Response (spark.Response)17 RepoResult (com.searchcode.app.model.RepoResult)11 AdminRouteService (com.searchcode.app.service.route.AdminRouteService)8 CodeRouteService (com.searchcode.app.service.route.CodeRouteService)7 Collectors (java.util.stream.Collectors)5 IndexService (com.searchcode.app.service.index.IndexService)4 IOException (java.io.IOException)4 Autowired (org.springframework.beans.factory.annotation.Autowired)4 Spark (spark.Spark)4 ValidatorResult (com.searchcode.app.model.ValidatorResult)3 ApiController (com.thoughtworks.go.api.ApiController)3 ApiVersion (com.thoughtworks.go.api.ApiVersion)3 JsonReader (com.thoughtworks.go.api.representers.JsonReader)3