org.sonatype.nexus.repository.types.HostedType Java Examples

The following examples show how to use org.sonatype.nexus.repository.types.HostedType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NpmRepairPackageRootComponentTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void onlyRepairNpmHostedRepositories() {
  when(repositoryManager.browse()).thenReturn(ImmutableList.of(npmHosted, npmProxy, npmGroup, nonNpmFormat));

  List<Repository> repairedRepositories = new ArrayList<>();

  NpmRepairPackageRootComponent repairComponent = new NpmRepairPackageRootComponent(repositoryManager,
      assetEntityAdapter, npmPackageParser, new HostedType(), new NpmFormat())
  {
    @Override
    protected void beforeRepair(final Repository repository) {
      repairedRepositories.add(repository);
    }
  };

  repairComponent.repair();

  assertThat(repairedRepositories, is(equalTo(ImmutableList.of(npmHosted))));
}
 
Example #2
Source File: AptApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new AptHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptHostedRepositoriesAttributes(repository),
          createAptSigningRepositoriesAttributes(repository));
    case ProxyType.NAME:
      return new AptProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createAptProxyRepositoriesAttributes(repository),
          getProxyAttributes(repository), getNegativeCacheAttributes(repository),
          getHttpClientAttributes(repository), getRoutingRuleName(repository));
  }
  return null;
}
 
Example #3
Source File: UploadManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private UploadHandler getUploadHandler(final Repository repository)
{
  if (!(repository.getType() instanceof HostedType)) {
    throw new ValidationErrorsException(
        format("Uploading components to a '%s' type repository is unsupported, must be '%s'",
            repository.getType().getValue(), HostedType.NAME));
  }

  String repositoryFormat = repository.getFormat().toString();
  UploadHandler uploadHandler = uploadHandlers.get(repositoryFormat);

  if (uploadHandler == null) {
    throw new ValidationErrorsException(
        format("Uploading components to '%s' repositories is unsupported", repositoryFormat));
  }

  return uploadHandler;
}
 
Example #4
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  when(handlerA.getDefinition()).thenReturn(uploadA);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerA.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(handlerB.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(validatingComponentUpload.getComponentUpload()).thenAnswer(i -> componentUploadCaptor.getValue());

  when(repository.getFormat()).thenReturn(new Format("a")
  {
  });
  when(repository.getType()).thenReturn(new HostedType());
  when(repository.getConfiguration()).thenReturn(configuration);
  when(configuration.isOnline()).thenReturn(true);

  Map<String, UploadHandler> handlers = new HashMap<>();
  handlers.put("a", handlerA);
  handlers.put("b", handlerB);

  underTest = new UploadManagerImpl(handlers, blobStoreAwareMultipartHelper,
      Collections.singleton(componentUploadExtension));
}
 
Example #5
Source File: MavenFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() throws Exception {
  underTest = Guice.createInjector(new TransactionModule(), new AbstractModule()
  {
    @Override
    protected void configure() {
      bind(EventManager.class).toInstance(eventManager);
      bind(MavenMetadataContentValidator.class).toInstance(mavenMetadataContentValidator);
      bind(MetadataRebuilder.class).toInstance(metadataRebuilder);
      bindConstant().annotatedWith(named("${nexus.maven.metadata.validation.enabled:-true}")).to(true);
      bind(new TypeLiteral<Map<String, MavenPathParser>>() { })
          .toInstance(ImmutableMap.of(Maven2Format.NAME, maven2MavenPathParser));
    }
  }).getInstance(MavenFacetImpl.class);

  underTest.attach(repository);
  when(repository.getType()).thenReturn(new HostedType());
  when(repository.facet(StorageFacet.class)).thenReturn(storageFacet);
  when(storageFacet.txSupplier()).thenReturn(() -> storageTx);

  UnitOfWork.begin(() -> storageTx);
}
 
Example #6
Source File: RResourceIT.java    From nexus-repository-r with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateHosted() throws Exception {
  repos.createRHosted(HOSTED_NAME);

  AbstractRepositoryApiRequest request = createHostedRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(HostedType.NAME, HOSTED_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(HOSTED_NAME);
}
 
Example #7
Source File: UploadManagerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private UploadHandler getUploadHandler(final Repository repository)
{
  if (!(repository.getType() instanceof HostedType)) {
    throw new ValidationErrorsException(
        format("Uploading components to a '%s' type repository is unsupported, must be '%s'",
            repository.getType().getValue(), HostedType.NAME));
  }

  String repositoryFormat = repository.getFormat().toString();
  UploadHandler uploadHandler = uploadHandlers.get(repositoryFormat);

  if (uploadHandler == null) {
    throw new ValidationErrorsException(
        format("Uploading components to '%s' repositories is unsupported", repositoryFormat));
  }

  return uploadHandler;
}
 
Example #8
Source File: SimpleApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String format = repository.getFormat().toString();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case GroupType.NAME:
      return new SimpleApiGroupRepository(name, format, url, online, getStorageAttributes(repository),
          getGroupAttributes(repository));
    case HostedType.NAME:
      return new SimpleApiHostedRepository(name, format, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository));
    case ProxyType.NAME:
      return new SimpleApiProxyRepository(name, format, url, online, getStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository),
          getRoutingRuleName(repository));
    default:
      return null;
  }
}
 
Example #9
Source File: UploadManagerImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  when(handlerA.getDefinition()).thenReturn(uploadA);
  when(handlerB.getDefinition()).thenReturn(uploadB);
  when(handlerA.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(handlerB.getValidatingComponentUpload(componentUploadCaptor.capture())).thenReturn(validatingComponentUpload);
  when(validatingComponentUpload.getComponentUpload()).thenAnswer(i -> componentUploadCaptor.getValue());

  when(repository.getFormat()).thenReturn(new Format("a")
  {
  });
  when(repository.getType()).thenReturn(new HostedType());
  when(repository.getConfiguration()).thenReturn(configuration);
  when(configuration.isOnline()).thenReturn(true);

  Map<String, UploadHandler> handlers = new HashMap<>();
  handlers.put("a", handlerA);
  handlers.put("b", handlerB);

  underTest = new UploadManagerImpl(handlers, blobStoreAwareMultipartHelper);
}
 
Example #10
Source File: SimpleApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testAdapt_hostedRepository() throws Exception {
  Repository repository = createRepository(new HostedType());

  SimpleApiHostedRepository hostedRepository = (SimpleApiHostedRepository) underTest.adapt(repository);
  assertRepository(hostedRepository, "hosted", true);
  assertThat(hostedRepository.getStorage().getStrictContentTypeValidation(), is(true));
  assertThat(hostedRepository.getStorage().getWritePolicy(), is("ALLOW"));

  // set some values
  setStorageAttributes(repository, "default", /* non-default */ false, "DENY");
  hostedRepository = (SimpleApiHostedRepository) underTest.adapt(repository);

  assertThat(hostedRepository.getStorage().getBlobStoreName(), is("default"));
  assertThat(hostedRepository.getStorage().getStrictContentTypeValidation(), is(false));
  assertThat(hostedRepository.getStorage().getWritePolicy(), is("DENY"));
}
 
Example #11
Source File: MavenApiRepositoryAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public AbstractApiRepository adapt(final Repository repository) {
  boolean online = repository.getConfiguration().isOnline();
  String name = repository.getName();
  String url = repository.getUrl();

  switch (repository.getType().toString()) {
    case HostedType.NAME:
      return new MavenHostedApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), createMavenAttributes(repository));
    case ProxyType.NAME:
      return new MavenProxyApiRepository(name, url, online, getHostedStorageAttributes(repository),
          getCleanupPolicyAttributes(repository), getProxyAttributes(repository),
          getNegativeCacheAttributes(repository), getHttpClientAttributes(repository), getRoutingRuleName(repository),
          createMavenAttributes(repository));
    default:
      return super.adapt(repository);
  }
}
 
Example #12
Source File: HelmResourceIT.java    From nexus-repository-helm with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void updateHosted() throws Exception {
  repos.createHelmHosted(HOSTED_NAME);

  AbstractRepositoryApiRequest request = createHostedRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(HostedType.NAME, HOSTED_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(HOSTED_NAME);
}
 
Example #13
Source File: RepairMetadataComponentTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  type = new HostedType();
  format = new Format("value") { };

  repository = mock(Repository.class);
  when(repository.getFormat()).thenReturn(format);
  when(repository.getType()).thenReturn(type);
}
 
Example #14
Source File: PurgeUnusedSnapshotsFacetImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public PurgeUnusedSnapshotsFacetImpl(
    final ComponentEntityAdapter componentEntityAdapter,
    @Named(GroupType.NAME) final Type groupType,
    @Named(HostedType.NAME) final Type hostedType,
    @Named("${nexus.tasks.purgeUnusedSnapshots.findUnusedLimit:-50}") int findUnusedLimit)
{
  this.componentEntityAdapter = checkNotNull(componentEntityAdapter);
  this.groupType = checkNotNull(groupType);
  this.hostedType = checkNotNull(hostedType);
  this.findUnusedLimit = findUnusedLimit;
  checkArgument(findUnusedLimit >= 10 && findUnusedLimit <= 1000,
      "nexus.tasks.purgeUnusedSnapshots.findUnusedLimit must be between 10 and 1000");
}
 
Example #15
Source File: MavenApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_hostedRepository() throws Exception {
  Repository repository = createRepository(new HostedType(), LayoutPolicy.STRICT, VersionPolicy.MIXED);

  MavenHostedApiRepository hostedRepository = (MavenHostedApiRepository) underTest.adapt(repository);
  assertRepository(hostedRepository, "hosted", true);
  assertThat(hostedRepository.getMaven().getLayoutPolicy(), is("STRICT"));
  assertThat(hostedRepository.getMaven().getVersionPolicy(), is("MIXED"));
  // Check fields are populated, actual values validated with SimpleApiRepositoryAdapterTest
  assertThat(hostedRepository.getCleanup(), nullValue());
  assertThat(hostedRepository.getStorage(), notNullValue());
}
 
Example #16
Source File: PurgeMavenUnusedSnapshotsTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public PurgeMavenUnusedSnapshotsTask(@Named(GroupType.NAME) final Type groupType,
                                     @Named(HostedType.NAME) final Type hostedType,
                                     @Named(Maven2Format.NAME) final Format maven2Format)
{
  this.groupType = checkNotNull(groupType);
  this.hostedType = checkNotNull(hostedType);
  this.maven2Format = checkNotNull(maven2Format);
}
 
Example #17
Source File: RebuildMaven2MetadataTask.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public RebuildMaven2MetadataTask(@Named(HostedType.NAME) final Type hostedType,
                                 @Named(Maven2Format.NAME) final Format maven2Format)
{
  this.hostedType = checkNotNull(hostedType);
  this.maven2Format = checkNotNull(maven2Format);
}
 
Example #18
Source File: AptHostedRecipe.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Inject
public AptHostedRecipe(final HighAvailabilitySupportChecker highAvailabilitySupportChecker,
                       @Named(HostedType.NAME) final Type type,
                       @Named(AptFormat.NAME) final Format format)
{
  super(highAvailabilitySupportChecker, type, format);
}
 
Example #19
Source File: AptApiRepositoryAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAdapt_hostedRepository() throws Exception {
  Repository repository = createRepository(new HostedType(), "bionic", "asdf", null, null);

  AptHostedApiRepository hostedRepository = (AptHostedApiRepository) underTest.adapt(repository);
  assertRepository(hostedRepository, "hosted", true);
  assertThat(hostedRepository.getApt().getDistribution(), is("bionic"));
  assertThat(hostedRepository.getAptSigning(), nullValue());

  // only include public key if it is encrypted
  repository.getConfiguration().attributes("apt").set("passphrase", "mypass");
  hostedRepository = (AptHostedApiRepository) underTest.adapt(repository);
  assertThat(hostedRepository.getAptSigning().getKeypair(), is("asdf"));
  assertThat(hostedRepository.getAptSigning().getPassphrase(), nullValue());
}
 
Example #20
Source File: HelmResourceIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void createHosted_noAuthc() throws Exception {
  setBadCredentials();
  AbstractRepositoryApiRequest request = createHostedRequest(true);
  Response response = post(getCreateRepositoryPathUrl(HostedType.NAME), request);
  assertEquals(Status.UNAUTHORIZED.getStatusCode(), response.getStatus());
}
 
Example #21
Source File: StorageFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  Config config = new Config();
  config.blobStoreName = BLOB_STORE_NAME;
  when(blobStore.getBlobStoreConfiguration()).thenReturn(blobStoreConfiguration);
  when(blobStoreConfiguration.getName()).thenReturn(BLOB_STORE_NAME);
  when(blobStoreConfiguration.getType()).thenReturn(FileBlobStore.TYPE);
  when(repository.facet(ConfigurationFacet.class)).thenReturn(configurationFacet);
  when(repository.getType()).thenReturn(new HostedType());
  when(configurationFacet
      .readSection(any(Configuration.class), eq(STORAGE), eq(StorageFacetImpl.Config.class)))
      .thenReturn(config);
  when(nodeAccess.getId()).thenReturn(NODE_ID);
  when(blob.getId()).thenReturn(blobId);
  when(blob.getMetrics()).thenReturn(blobMetrics);
  when(blobId.asUniqueString()).thenReturn(BLOB_ID);
  underTest = new StorageFacetImpl(
      nodeAccess,
      blobStoreManager,
      () -> databaseInstance,
      bucketEntityAdapter,
      componentEntityAdapter,
      assetEntityAdapter,
      clientInfoProvider,
      contentValidatorSelector,
      mimeRulesSourceSelector,
      storageFacetManager,
      componentFactory,
      violationFactory
  );
  underTest.attach(repository);
}
 
Example #22
Source File: HostedRepositoryApiRequest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@JsonCreator
public HostedRepositoryApiRequest(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final HostedStorageAttributes storage,
    @JsonProperty("cleanup") final CleanupPolicyAttributes cleanup)
{
  super(name, format, HostedType.NAME, online);
  this.storage = storage;
  this.cleanup = cleanup;
}
 
Example #23
Source File: SimpleApiHostedRepository.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@JsonCreator
public SimpleApiHostedRepository(
    @JsonProperty("name") final String name,
    @JsonProperty("format") final String format,
    @JsonProperty("url") final String url,
    @JsonProperty("online") final Boolean online,
    @JsonProperty("storage") final HostedStorageAttributes storage,
    @JsonProperty("cleanup") final CleanupPolicyAttributes cleanup)
{
  super(name, format, HostedType.NAME, url, online);
  this.storage = storage;
  this.cleanup = cleanup;
}
 
Example #24
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void rebuildIndexShouldThrowExceptionIfInsufficientPermissions() throws Exception {
  when(repository.getType()).thenReturn(new HostedType());
  doThrow(new AuthorizationException("User is not permitted."))
      .when(repositoryPermissionChecker)
      .ensureUserCanAdmin(any(), any());
  expectedException.expect(AuthorizationException.class);

  authorizingRepositoryManager.rebuildSearchIndex("repository");

  verify(repositoryManager).get(eq("repository"));
  verify(repositoryPermissionChecker).ensureUserCanAdmin(eq(EDIT), eq(repository));
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, taskScheduler);
}
 
Example #25
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void rebuildIndexShouldTriggerTask() throws Exception {
  TaskConfiguration taskConfiguration = mock(TaskConfiguration.class);
  when(taskScheduler.createTaskConfigurationInstance(any())).thenReturn(taskConfiguration);
  when(repository.getType()).thenReturn(new HostedType());

  authorizingRepositoryManager.rebuildSearchIndex("repository");

  verify(repositoryManager).get(eq("repository"));
  verify(repositoryPermissionChecker).ensureUserCanAdmin(eq(EDIT), eq(repository));
  verify(taskScheduler).createTaskConfigurationInstance(RebuildIndexTaskDescriptor.TYPE_ID);
  verify(taskScheduler).submit(any());
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, taskScheduler);
}
 
Example #26
Source File: AuthorizingRepositoryManagerTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void invalidateCacheShouldThrowExceptionIfRepositoryTypeIsNotProxyOrGroup() throws Exception {
  when(repository.getType()).thenReturn(new HostedType());
  expectedException.expect(IncompatibleRepositoryException.class);

  authorizingRepositoryManager.invalidateCache("repository");

  verify(repositoryManager).get(eq("repository"));
  verifyNoMoreInteractions(repositoryManager, repositoryPermissionChecker, taskScheduler);
}
 
Example #27
Source File: ConanHostedRecipeTest.java    From nexus-repository-conan with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void hostedEnabledNexusConanHostedEnabledIsTrueHaSupportIsTrue() {
  System.setProperty(HOSTED_ENABLED_PROPERTY, "true");
  when(highAvailabilitySupportChecker.isSupported(ConanFormat.NAME)).thenReturn(true);
  ConanHostedRecipe conanHostedRecipe = new ConanHostedRecipe(new HostedType(), new ConanFormat(), null);
  conanHostedRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  assertThat(conanHostedRecipe.isFeatureEnabled(), is(true));
}
 
Example #28
Source File: HelmRecipeTest.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
  when(helmFormat.getValue()).thenReturn(HelmFormat.NAME);
  helmProxyRecipe = new HelmProxyRecipe(new ProxyType(), helmFormat);
  helmHostedRecipe = new HelmHostedRecipe(new HostedType(), helmFormat);
  helmProxyRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  helmHostedRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
}
 
Example #29
Source File: HelmResourceIT.java    From nexus-repository-helm with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void updateHosted_noAuthz() throws Exception {
  repos.createHelmHosted(HOSTED_NAME);

  setUnauthorizedUser();
  AbstractRepositoryApiRequest request = createHostedRequest(false);

  Response response = put(getUpdateRepositoryPathUrl(HostedType.NAME, HOSTED_NAME), request);
  assertEquals(Status.FORBIDDEN.getStatusCode(), response.getStatus());
}
 
Example #30
Source File: RRecipeTest.java    From nexus-repository-r with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
  when(rFormat.getValue()).thenReturn(R_FORMAT);
  rHostedRecipe = new RHostedRecipe(new HostedType(), rFormat);
  rProxyRecipe = new RProxyRecipe(new ProxyType(), rFormat);
  rGroupRecipe = new RGroupRecipe(new GroupType(), rFormat);
  rHostedRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  rProxyRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
  rGroupRecipe.setHighAvailabilitySupportChecker(highAvailabilitySupportChecker);
}