Search in sources :

Example 1 with Repository

use of org.sonatype.nexus.repository.Repository in project nexus-repository-r by sonatype-nexus-community.

the class RRestoreBlobStrategy method canAttemptRestore.

@Override
protected boolean canAttemptRestore(@Nonnull final RRestoreBlobData rRestoreBlobData) {
    Repository repository = getRepository(rRestoreBlobData);
    Optional<RRestoreFacet> rRestoreFacetFacet = repository.optionalFacet(RRestoreFacet.class);
    if (!rRestoreFacetFacet.isPresent()) {
        log.warn("Skipping as R Restore Facet not found on repository: {}", repository.getName());
        return false;
    }
    return true;
}
Also used : Repository(org.sonatype.nexus.repository.Repository) RRestoreFacet(org.sonatype.nexus.repository.r.RRestoreFacet)

Example 2 with Repository

use of org.sonatype.nexus.repository.Repository in project nexus-repository-r by sonatype-nexus-community.

the class RResourceIT method updateProxy.

@Test
public void updateProxy() throws Exception {
    repos.createRProxy(PROXY_NAME, REMOTE_URL);
    AbstractRepositoryApiRequest request = createProxyRequest(false);
    Response response = put(getUpdateRepositoryPathUrl(ProxyType.NAME, PROXY_NAME), request);
    assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
    Repository repository = repositoryManager.get(request.getName());
    assertNotNull(repository);
    assertThat(repository.getConfiguration().attributes("storage").get("strictContentTypeValidation"), is(false));
    repositoryManager.delete(PROXY_NAME);
}
Also used : Response(javax.ws.rs.core.Response) Repository(org.sonatype.nexus.repository.Repository) AbstractRepositoryApiRequest(org.sonatype.nexus.repository.rest.api.model.AbstractRepositoryApiRequest) Test(org.junit.Test)

Example 3 with Repository

use of org.sonatype.nexus.repository.Repository in project nexus-repository-r by sonatype-nexus-community.

the class RResourceIT method createHosted.

@Test
public void createHosted() throws Exception {
    AbstractRepositoryApiRequest request = createHostedRequest(true);
    Response response = post(getCreateRepositoryPathUrl(HostedType.NAME), request);
    assertEquals(Status.CREATED.getStatusCode(), response.getStatus());
    Repository repository = repositoryManager.get(request.getName());
    assertNotNull(repository);
    assertEquals(RFormat.NAME, repository.getFormat().getValue());
    assertEquals(HostedType.NAME, repository.getType().getValue());
    repositoryManager.delete(request.getName());
}
Also used : Response(javax.ws.rs.core.Response) Repository(org.sonatype.nexus.repository.Repository) AbstractRepositoryApiRequest(org.sonatype.nexus.repository.rest.api.model.AbstractRepositoryApiRequest) Test(org.junit.Test)

Example 4 with Repository

use of org.sonatype.nexus.repository.Repository in project nexus-repository-r by sonatype-nexus-community.

the class RRoutingRuleIT method testBlockedRoutingRule.

@Test
public void testBlockedRoutingRule() throws Exception {
    String packageFileName = "agricolae_1.0-1.tar.gz";
    String allowedPackagePath = "bin/macosx/el-capitan/contrib/1.0/agricolae_1.0-1.tar.gz";
    String blockedPackagePath = "bin/macosx/el-capitan/contrib/1.1/agricolae_1.0-1.tar.gz";
    configureProxyBehaviour(allowedPackagePath, packageFileName);
    configureProxyBehaviour(blockedPackagePath, packageFileName);
    EntityId routingRuleId = createBlockedRoutingRule("r-blocking-rule", ".*/1.1/.*");
    Repository proxyRepo = repos.createRProxy("test-r-blocking-proxy", proxyServer.getUrl().toString());
    RClient client = rClient(proxyRepo);
    attachRuleToRepository(proxyRepo, routingRuleId);
    assertGetResponseStatus(client, proxyRepo, blockedPackagePath, 403);
    assertGetResponseStatus(client, proxyRepo, allowedPackagePath, 200);
    assertNoRequests(blockedPackagePath);
}
Also used : EntityId(org.sonatype.nexus.common.entity.EntityId) Repository(org.sonatype.nexus.repository.Repository) Test(org.junit.Test)

Example 5 with Repository

use of org.sonatype.nexus.repository.Repository in project nexus-repository-r by sonatype-nexus-community.

the class PackagesGroupHandler method doGet.

@Override
protected Response doGet(@Nonnull final Context context, @Nonnull final GroupHandler.DispatchedRepositories dispatched) throws Exception {
    GroupFacet groupFacet = context.getRepository().facet(GroupFacet.class);
    Map<Repository, Response> responses = getAll(context, groupFacet.members(), dispatched);
    List<Response> successfulResponses = responses.values().stream().filter(response -> response.getStatus().getCode() == HttpStatus.OK && response.getPayload() != null).collect(Collectors.toList());
    if (successfulResponses.isEmpty()) {
        return notFoundResponse(context);
    }
    if (successfulResponses.size() == 1) {
        return successfulResponses.get(0);
    }
    List<List<Map<String, String>>> parts = successfulResponses.stream().map(this::parseResponse).collect(Collectors.toList());
    List<Map<String, String>> merged = RPackagesUtils.merge(parts);
    return HttpResponses.ok(RPackagesUtils.buildPackages(merged));
}
Also used : Response(org.sonatype.nexus.repository.view.Response) CompressorException(org.apache.commons.compress.compressors.CompressorException) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Context(org.sonatype.nexus.repository.view.Context) HttpStatus(org.sonatype.nexus.repository.http.HttpStatus) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) HttpResponses(org.sonatype.nexus.repository.http.HttpResponses) CompressorStreamFactory(org.apache.commons.compress.compressors.CompressorStreamFactory) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) GZIP(org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP) List(java.util.List) Repository(org.sonatype.nexus.repository.Repository) GroupHandler(org.sonatype.nexus.repository.group.GroupHandler) Map(java.util.Map) Payload(org.sonatype.nexus.repository.view.Payload) Named(javax.inject.Named) Response(org.sonatype.nexus.repository.view.Response) Nonnull(javax.annotation.Nonnull) InputStream(java.io.InputStream) GroupFacet(org.sonatype.nexus.repository.group.GroupFacet) Repository(org.sonatype.nexus.repository.Repository) List(java.util.List) Map(java.util.Map)

Aggregations

Repository (org.sonatype.nexus.repository.Repository)8 Test (org.junit.Test)5 Response (javax.ws.rs.core.Response)4 AbstractRepositoryApiRequest (org.sonatype.nexus.repository.rest.api.model.AbstractRepositoryApiRequest)4 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Nonnull (javax.annotation.Nonnull)2 Named (javax.inject.Named)2 Singleton (javax.inject.Singleton)2 CompressorException (org.apache.commons.compress.compressors.CompressorException)2 CompressorStreamFactory (org.apache.commons.compress.compressors.CompressorStreamFactory)2 GZIP (org.apache.commons.compress.compressors.CompressorStreamFactory.GZIP)2 GroupFacet (org.sonatype.nexus.repository.group.GroupFacet)2 GroupHandler (org.sonatype.nexus.repository.group.GroupHandler)2 HttpResponses (org.sonatype.nexus.repository.http.HttpResponses)2 HttpStatus (org.sonatype.nexus.repository.http.HttpStatus)2