diff --git a/README.md b/README.md index c3ef9a942..239bb4c31 100644 --- a/README.md +++ b/README.md @@ -92,6 +92,7 @@ gitlab: The following CI services are supported: - Artifactory +- Nexus - Concourse - Gitlab CI - Google Cloud Build (GCB) diff --git a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/model/ArtifactServiceProvider.java b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/model/ArtifactServiceProvider.java index 5aeb89d4e..2d1045f1d 100644 --- a/igor-web/src/main/groovy/com/netflix/spinnaker/igor/model/ArtifactServiceProvider.java +++ b/igor-web/src/main/groovy/com/netflix/spinnaker/igor/model/ArtifactServiceProvider.java @@ -19,5 +19,6 @@ public enum ArtifactServiceProvider { CUSTOM, - ARTIFACTORY + ARTIFACTORY, + NEXUS } diff --git a/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusController.java b/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusController.java index 29059255a..2db651934 100644 --- a/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusController.java +++ b/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusController.java @@ -21,9 +21,13 @@ import com.netflix.spinnaker.igor.config.NexusProperties; import com.netflix.spinnaker.igor.history.EchoService; import com.netflix.spinnaker.igor.nexus.model.NexusAssetWebhookPayload; +import com.netflix.spinnaker.igor.nexus.model.NexusRepo; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; @@ -49,6 +53,11 @@ public NexusController( missedNotificationId = registry.createId("webhook.missedEchoNotification"); } + @GetMapping("/names") + List getNexusNames() { + return nexusProperties.getRepos().stream().map(NexusRepo::getName).collect(Collectors.toList()); + } + @PostMapping(path = "/webhook", consumes = "application/json") public void webhook(@RequestBody NexusAssetWebhookPayload payload) { if (!echoService.isPresent()) { diff --git a/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusEventPoster.java b/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusEventPoster.java index 045f7ef20..4db98c213 100644 --- a/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusEventPoster.java +++ b/igor-web/src/main/java/com/netflix/spinnaker/igor/nexus/NexusEventPoster.java @@ -48,23 +48,50 @@ public void postEvent(NexusAssetWebhookPayload payload) { final String version = nameList.get(nameList.size() - 2); final String artifactId = nameList.get(nameList.size() - 3); final String group = Strings.join(nameList.subList(0, nameList.size() - 3), '.'); - final Artifact artifact = - Artifact.builder() - .type("maven/file") - .reference(group + ":" + artifactId + ":" + version) - .name(group + ":" + artifactId) - .version(version) - .provenance(payload.getRepositoryName()) - .build(); + final String path = Strings.join(nameList.subList(0, nameList.size() - 3), '/'); + final String specificArtifactName = + nameList.subList(nameList.size() - 1, nameList.size()).get(0); + final String specificArtifactVersion = + specificArtifactName.substring( + specificArtifactName.indexOf('-') + 1, specificArtifactName.lastIndexOf(".pom")); final Optional oRepo = findNexusRepo(payload); oRepo.ifPresent( - repo -> { - AuthenticatedRequest.allowAnonymous( - () -> - echoService.postEvent( - new NexusAssetEvent( - new NexusAssetEvent.Content(repo.getName(), artifact)))); - }); + repo -> + AuthenticatedRequest.allowAnonymous( + () -> { + String location = null; + if (repo.getBaseUrl() != null) { + String baseUrl = + repo.getBaseUrl() + .replace("/repository", "/service/rest/repository/browse"); + if (!baseUrl.endsWith("/")) { + baseUrl = baseUrl + "/"; + } + location = + baseUrl + + repo.getRepo() + + "/" + + path + + "/" + + artifactId + + "/" + + version + + "/" + + specificArtifactVersion + + "/"; + } + final Artifact artifact = + Artifact.builder() + .type("maven/file") + .reference(group + ":" + artifactId + ":" + version) + .name(group + ":" + artifactId) + .version(version) + .provenance(payload.getRepositoryName()) + .location(location) + .build(); + return echoService.postEvent( + new NexusAssetEvent(new NexusAssetEvent.Content(repo.getName(), artifact))); + })); } } diff --git a/igor-web/src/test/java/com/netflix/spinnaker/igor/nexus/NexusEventPosterTest.java b/igor-web/src/test/java/com/netflix/spinnaker/igor/nexus/NexusEventPosterTest.java index e491566c6..f54d7f59b 100644 --- a/igor-web/src/test/java/com/netflix/spinnaker/igor/nexus/NexusEventPosterTest.java +++ b/igor-web/src/test/java/com/netflix/spinnaker/igor/nexus/NexusEventPosterTest.java @@ -38,6 +38,7 @@ class NexusEventPosterTest { final NexusRepo nexusRepo = new NexusRepo(); nexusRepo.setName("nexus-snapshots"); nexusRepo.setRepo("maven-snapshots"); + nexusRepo.setBaseUrl("http://localhost:8082/repository/"); nexusRepo.setNodeId("123"); nexusProperties.setRepos(Collections.singletonList(nexusRepo)); } @@ -65,6 +66,8 @@ void postArtifact() { .name("com.example" + ":" + "demo") .version("0.0.1-SNAPSHOT") .provenance("maven-snapshots") + .location( + "http://localhost:8082/service/rest/repository/browse/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/0.0.1-20190828.022502-3/") .build(); verify(echoService) .postEvent( @@ -86,6 +89,8 @@ void postUpdatedArtifact() { .name("com.example" + ":" + "demo") .version("0.0.1-SNAPSHOT") .provenance("maven-snapshots") + .location( + "http://localhost:8082/service/rest/repository/browse/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/0.0.1-20190828.022502-3/") .build(); verify(echoService) .postEvent( @@ -138,6 +143,8 @@ void postNonMatchingRepoArtifactWithRepoId() { .name("com.example" + ":" + "demo") .version("0.0.1-SNAPSHOT") .provenance("DNE") + .location( + "http://localhost:8082/service/rest/repository/browse/maven-snapshots/com/example/demo/0.0.1-SNAPSHOT/0.0.1-20190828.022502-3/") .build(); verify(echoService) .postEvent(