Skip to content
This repository has been archived by the owner on Sep 18, 2020. It is now read-only.

Commit

Permalink
Merge pull request #32 from N4rm0/initial-index-yaml-for-hosted
Browse files Browse the repository at this point in the history
Create initial index.yaml file for hosted repository

verified index.yml is created when requested by add repos to helm client config. e.g.
```
helm repo add helm-proxy http://localhost:8081/repository/helm-proxy/
helm repo add helm-hosted http://localhost:8081/repository/helm-hosted/
```
both work fine (no 404 errors), and afterwards, an empty `index.yml` exists for both proxy and hosted repos.

Also verified using helm client to install a chart triggers a fetch of a fully populated 'index.yml' from the remote, and the helm client install succeeds.

Nicely done @N4rm0 ! Thanks for the contribution!

(Not sure if this fixes #20, as that one might be a 'sub-directory' issue)

Fixes #23, #26
  • Loading branch information
bhamail authored Jul 24, 2019
2 parents d40cef5 + d7f194b commit 7c41668
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.sonatype.nexus.common.stateguard.Guarded;
import org.sonatype.nexus.repository.FacetSupport;
import org.sonatype.nexus.repository.Repository;
import org.sonatype.nexus.repository.manager.RepositoryCreatedEvent;
import org.sonatype.nexus.repository.storage.Asset;
import org.sonatype.nexus.repository.storage.AssetCreatedEvent;
import org.sonatype.nexus.repository.storage.AssetDeletedEvent;
Expand Down Expand Up @@ -107,6 +108,15 @@ public void on(final AssetUpdatedEvent updated) {
maybeInvalidateIndex(updated);
}

@Subscribe
@Guarded(by = STARTED)
@AllowConcurrentEvents
public void on(RepositoryCreatedEvent createdEvent) {
// at repository creation time, create index.yaml with empty entries
log.debug("Initializing index.yaml for hosted repository {}", getRepository().getName());
invalidateIndex();
}

private void maybeInvalidateIndex(final AssetEvent event) {
if(matchesRepository(event) && isEventRelevant(event)) {
invalidateIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,9 @@ public TempBlob buildIndexYaml(final Repository repository) {
parseAssetIntoChartEntry(index, asset);
}

if (index.getEntries().size() == 0) {
return null;
}
else {
index.setApiVersion(API_VERSION);
index.setGenerated(new DateTime());
return indexYamlBuilder.build(index, storageFacet);
}
index.setApiVersion(API_VERSION);
index.setGenerated(new DateTime());
return indexYamlBuilder.build(index, storageFacet);
}

private void parseAssetIntoChartEntry(final ChartIndex index, final Asset asset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,16 @@ public void testBuildIndexYaml() throws Exception {
}

@Test
public void testIndexYamlNotBuiltWhenNoAssets() throws Exception {
public void testIndexYamlBuiltEvenWhenNoAssets() throws Exception {
when(assets.iterator()).thenReturn(assetIterator);
when(assetIterator.next()).thenReturn(asset);
when(asset.componentId()).thenReturn(null);
when(helmDataAccess.browseComponentAssets(storageTx, bucket)).thenReturn(assets);
when(indexYamlBuilder.build(anyObject(), anyObject())).thenReturn(tempBlob);

TempBlob result = underTest.buildIndexYaml(repository);

assertThat(result, is(nullValue()));
assertThat(result, is(notNullValue()));
}

private void initializeSystemUnderTest() {
Expand Down

0 comments on commit 7c41668

Please sign in to comment.