-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use new download url for snyk downloads (#150)
* chore: use new download url for snyk downloads * fix(downloader): correct snyk-to-html url * fix: use correct integration name * chore: log download url --------- Co-authored-by: Peter Schäfer <[email protected]>
- Loading branch information
1 parent
6a700a4
commit e485548
Showing
4 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 15 additions & 5 deletions
20
src/main/java/io/snyk/jenkins/tools/internal/DownloadService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
package io.snyk.jenkins.tools.internal; | ||
|
||
import io.snyk.jenkins.PluginMetadata; | ||
import io.snyk.jenkins.tools.Platform; | ||
|
||
import javax.annotation.Nonnull; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
import static java.lang.String.format; | ||
|
||
public class DownloadService { | ||
private static final String SNYK_DOWNLOAD_PRIMARY = "https://downloads.snyk.io/%s/%s/%s"; | ||
private static final String SNYK_DOWNLOAD_SECONDARY = "https://static.snyk.io/%s/%s/%s"; | ||
public static final List<String> SNYK_CLI_DOWNLOAD_URLS = Collections.unmodifiableList(Arrays.asList(SNYK_DOWNLOAD_PRIMARY, SNYK_DOWNLOAD_SECONDARY)); | ||
|
||
private DownloadService() { | ||
// squid:S1118 | ||
} | ||
|
||
public static URL getDownloadUrlForSnyk(@Nonnull String version, @Nonnull Platform platform) throws IOException { | ||
return new URL(format("https://static.snyk.io/cli/%s/%s", version, platform.snykWrapperFileName)); | ||
} | ||
public static URL constructDownloadUrlForSnyk(@Nonnull String urlTemplate, @Nonnull String product, @Nonnull String version, @Nonnull Platform platform) throws IOException { | ||
URL urlNoUtm; | ||
|
||
public static URL getDownloadUrlForSnykToHtml(@Nonnull String version, @Nonnull Platform platform) throws IOException { | ||
return new URL(format("https://static.snyk.io/snyk-to-html/%s/%s", version, platform.snykToHtmlWrapperFileName)); | ||
if (product.equals("cli")) { | ||
urlNoUtm = new URL(format(urlTemplate, product, version, platform.snykWrapperFileName)); | ||
} else { // snyk-to-html | ||
urlNoUtm = new URL(format(urlTemplate, product, version, platform.snykToHtmlWrapperFileName)); | ||
} | ||
return new URL(urlNoUtm.toString() + "?utm_source=" + PluginMetadata.getIntegrationName()); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/io/snyk/jenkins/tools/internal/DownloadServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package io.snyk.jenkins.tools.internal; | ||
|
||
import io.snyk.jenkins.PluginMetadata; | ||
import org.junit.Test; | ||
|
||
import io.snyk.jenkins.tools.Platform; | ||
|
||
import java.io.IOException; | ||
import java.net.URL; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.hamcrest.core.IsNull.notNullValue; | ||
|
||
|
||
public class DownloadServiceTest { | ||
|
||
@Test | ||
public void constructDownloadUrlForSnyk_shouldReturnExpectedUrlForCli() throws IOException { | ||
String urlTemplate = "https://downloads.snyk.io/%s/%s/%s"; | ||
String product = "cli"; | ||
String version = "stable"; | ||
String queryParam = "?utm_source=" + PluginMetadata.getIntegrationName(); | ||
Platform platform = Platform.MAC_OS; | ||
|
||
URL expectedUrl = new URL("https://downloads.snyk.io/" + product + "/" + version + "/" + "snyk-macos" + queryParam); | ||
URL actualUrl = DownloadService.constructDownloadUrlForSnyk(urlTemplate, product, version, platform); | ||
|
||
assertThat(actualUrl, notNullValue()); | ||
assertThat(actualUrl, equalTo(expectedUrl)); | ||
} | ||
|
||
@Test | ||
public void constructDownloadUrlForSnyk_shouldReturnExpectedUrlForSnykToHtml() throws IOException { | ||
String urlTemplate = "https://downloads.snyk.io/%s/%s/%s"; | ||
String product = "snyk-to-html"; | ||
String version = "stable"; | ||
String queryParam = "?utm_source=" + PluginMetadata.getIntegrationName(); | ||
Platform platform = Platform.MAC_OS; | ||
|
||
URL expectedUrl = new URL("https://downloads.snyk.io/" + product + "/" + version + "/" + "snyk-to-html-macos" + queryParam); | ||
URL actualUrl = DownloadService.constructDownloadUrlForSnyk(urlTemplate, product, version, platform); | ||
|
||
assertThat(actualUrl, notNullValue()); | ||
assertThat(actualUrl, equalTo(expectedUrl)); | ||
} | ||
} |