From 0759fd80b0f9200672ce8b8b9281a08b3f10a826 Mon Sep 17 00:00:00 2001 From: Shruthi Manavalli Ramanna Date: Fri, 2 Jun 2023 19:09:31 +0200 Subject: [PATCH 1/6] Added support for cdn download url for mgmt API and tests Signed-off-by: Shruthi Manavalli Ramanna --- .../hawkbit-artifactdl-defaults.properties | 9 +++++- .../java/org/eclipse/hawkbit/api/ApiType.java | 7 ++++- .../api/ArtifactUrlHandlerProperties.java | 4 +-- .../api/PropertyBasedArtifactUrlHandler.java | 8 +++-- .../rsql/RSQLTargetFilterQueryFieldsTest.java | 2 +- .../hawkbit-test-defaults.properties | 7 +++++ .../mgmt/rest/api/MgmtRestConstants.java | 6 ++++ .../rest/api/MgmtSoftwareModuleRestApi.java | 7 +++-- .../resource/MgmtSoftwareModuleMapper.java | 19 +++++++++++- .../resource/MgmtSoftwareModuleResource.java | 26 +++++++++++++--- .../MgmtSoftwareModuleResourceTest.java | 31 +++++++++++++++++++ .../application-cloudsandbox.properties | 5 +++ 12 files changed, 115 insertions(+), 16 deletions(-) diff --git a/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties b/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties index c2696d679..9c84f916d 100644 --- a/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties +++ b/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties @@ -21,4 +21,11 @@ hawkbit.artifact.url.protocols.md5sum-http.hostname=${hawkbit.artifact.url.proto hawkbit.artifact.url.protocols.md5sum-http.ip=${hawkbit.artifact.url.protocols.download-http.ip} hawkbit.artifact.url.protocols.md5sum-http.port=${hawkbit.artifact.url.protocols.download-http.port} hawkbit.artifact.url.protocols.md5sum-http.supports=DDI -hawkbit.artifact.url.protocols.md5sum-http.ref=${hawkbit.artifact.url.protocols.download-http.ref}.MD5SUM \ No newline at end of file +hawkbit.artifact.url.protocols.md5sum-http.ref=${hawkbit.artifact.url.protocols.download-http.ref}.MD5SUM +hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.hostname=localhost +hawkbit.artifact.url.protocols.download-cdn-http.ip=127.0.0.1 +hawkbit.artifact.url.protocols.download-cdn-http.protocol=http +hawkbit.artifact.url.protocols.download-cdn-http.port=8080 +hawkbit.artifact.url.protocols.download-cdn-http.supports=MGMT +hawkbit.artifact.url.protocols.download-cdn-http.ref={protocol}://{hostnameRequest}:{portRequest}/rest/v1/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} \ No newline at end of file diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ApiType.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ApiType.java index e683b420b..017e3edb9 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ApiType.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ApiType.java @@ -22,5 +22,10 @@ public enum ApiType { /** * Support for Direct Device Integration API. */ - DDI + DDI, + + /** + * Support for Management API. + */ + MGMT } diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java index 4dec09e7b..115a86b22 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/ArtifactUrlHandlerProperties.java @@ -54,7 +54,7 @@ public class ArtifactUrlHandlerProperties { * artifactFileName,artifactSHA1, * artifactIdBase62,artifactId,tenant,softwareModuleId, * softwareModuleIdBase62. - * + * * The update server itself supports */ private String ref = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}"; @@ -84,7 +84,7 @@ public class ArtifactUrlHandlerProperties { /** * Support for the following hawkBit API. */ - private List supports = Arrays.asList(ApiType.DDI, ApiType.DMF); + private List supports = Arrays.asList(ApiType.DDI, ApiType.DMF, ApiType.MGMT); public boolean isEnabled() { return enabled; diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java index 4b02c9efd..de9729954 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/api/PropertyBasedArtifactUrlHandler.java @@ -104,7 +104,9 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { urlPattern = urlPattern.replace(":{" + entry.getKey() + "}", StringUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue())); } else { - urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue()); + if(entry.getValue() != null) { + urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue()); + } } } return urlPattern; @@ -135,7 +137,9 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler { replaceMap.put(TENANT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTenantId())); replaceMap.put(CONTROLLER_ID_PLACEHOLDER, placeholder.getControllerId()); replaceMap.put(TARGET_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTargetId())); - replaceMap.put(TARGET_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTargetId())); + if(placeholder.getTargetId() != null) { + replaceMap.put(TARGET_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getTargetId())); + } replaceMap.put(ARTIFACT_ID_BASE62_PLACEHOLDER, Base62Util.fromBase10(placeholder.getSoftwareData().getArtifactId())); replaceMap.put(ARTIFACT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getSoftwareData().getArtifactId())); diff --git a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java index f8c93920b..26ddbc8d4 100644 --- a/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java +++ b/hawkbit-repository/hawkbit-repository-jpa/src/test/java/org/eclipse/hawkbit/repository/jpa/rsql/RSQLTargetFilterQueryFieldsTest.java @@ -34,7 +34,7 @@ public class RSQLTargetFilterQueryFieldsTest extends AbstractJpaIntegrationTest private TargetFilterQuery filter2; @BeforeEach - public void setupBeforeTest() throws InterruptedException { + public void setupBeforeTest() { final String filterName1 = "filter_a"; final String filterName2 = "filter_b"; final String filterName3 = "filter_c"; diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties b/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties index 161e23204..c1a03b2e1 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties +++ b/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties @@ -51,6 +51,13 @@ hawkbit.artifact.url.protocols.md5sum-http.ip=${hawkbit.artifact.url.protocols.d hawkbit.artifact.url.protocols.md5sum-http.port=${hawkbit.artifact.url.protocols.download-http.port} hawkbit.artifact.url.protocols.md5sum-http.supports=DDI hawkbit.artifact.url.protocols.md5sum-http.ref=${hawkbit.artifact.url.protocols.download-http.ref}.MD5SUM +hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.hostname=localhost +hawkbit.artifact.url.protocols.download-cdn-http.ip=127.0.0.1 +hawkbit.artifact.url.protocols.download-cdn-http.protocol=http +hawkbit.artifact.url.protocols.download-cdn-http.port=8080 +hawkbit.artifact.url.protocols.download-cdn-http.supports=MGMT +hawkbit.artifact.url.protocols.download-cdn-http.ref={protocol}://{hostnameRequest}:{portRequest}/rest/v1/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} ## Download URL Generation - END # Quota - START diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java index 009eb5b1d..83b26e132 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java @@ -271,6 +271,12 @@ public final class MgmtRestConstants { */ public static final String AUTH_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/userinfo"; + /** + * The artifact download URL type + */ + public static final String ARTIFACT_DOWNLOAD_URL_TYPE = "downloadurltype"; + + // constant class, private constructor. private MgmtRestConstants() { diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index f6746474b..efc1f280d 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -98,9 +98,10 @@ public interface MgmtSoftwareModuleRestApi { @GetMapping(value = MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}", produces = { MediaTypes.HAL_JSON_VALUE, MediaType.APPLICATION_JSON_VALUE }) - @ResponseBody - ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, - @PathVariable("artifactId") final Long artifactId); + @ResponseBody ResponseEntity getArtifact( + @PathVariable("softwareModuleId") final Long softwareModuleId, + @PathVariable("artifactId") final Long artifactId, + @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType); /** * Handles the DELETE request for a single SoftwareModule. diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 7b1903430..37f65d8a0 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -16,6 +16,10 @@ import java.util.Collections; import java.util.List; import java.util.stream.Collectors; +import org.eclipse.hawkbit.api.ApiType; +import org.eclipse.hawkbit.api.ArtifactUrl; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; +import org.eclipse.hawkbit.api.URLPlaceholder; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifactHash; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; @@ -25,12 +29,14 @@ import org.eclipse.hawkbit.mgmt.rest.api.MgmtRestConstants; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleRestApi; import org.eclipse.hawkbit.mgmt.rest.api.MgmtSoftwareModuleTypeRestApi; import org.eclipse.hawkbit.repository.EntityFactory; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.builder.SoftwareModuleCreate; import org.eclipse.hawkbit.repository.builder.SoftwareModuleMetadataCreate; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.SoftwareModule; import org.eclipse.hawkbit.repository.model.SoftwareModuleMetadata; import org.eclipse.hawkbit.rest.data.ResponseList; +import org.springframework.hateoas.Link; /** * A mapper which maps repository model to RESTful model representation and @@ -143,7 +149,7 @@ public final class MgmtSoftwareModuleMapper { MgmtRestModelMapper.mapBaseToBase(artifactRest, artifact); artifactRest.add(linkTo(methodOn(MgmtSoftwareModuleRestApi.class) - .getArtifact(artifact.getSoftwareModule().getId(), artifact.getId())).withSelfRel().expand()); + .getArtifact(artifact.getSoftwareModule().getId(), artifact.getId(), null)).withSelfRel().expand()); return artifactRest; } @@ -155,6 +161,17 @@ public final class MgmtSoftwareModuleMapper { .expand()); } + static void addLinks(final Artifact artifact, final MgmtArtifact response, + final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) { + + List urls = artifactUrlHandler.getUrls( + new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(), + systemManagement.getTenantMetadata().getId(), null, null, + new URLPlaceholder.SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(), + artifact.getId(), artifact.getSha1Hash())), ApiType.MGMT, null); + response.add(Link.of(urls.get(0).getRef()).withRel("cdn-download").expand()); + } + static List artifactsToResponse(final Collection artifacts) { if (artifacts == null) { return Collections.emptyList(); diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index d7b0682dd..55200ee23 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; import org.eclipse.hawkbit.mgmt.json.model.softwaremodule.MgmtSoftwareModule; @@ -29,6 +30,7 @@ import org.eclipse.hawkbit.repository.EntityFactory; import org.eclipse.hawkbit.repository.OffsetBasedPageRequest; import org.eclipse.hawkbit.repository.SoftwareModuleManagement; import org.eclipse.hawkbit.repository.SoftwareModuleTypeManagement; +import org.eclipse.hawkbit.repository.SystemManagement; import org.eclipse.hawkbit.repository.exception.EntityNotFoundException; import org.eclipse.hawkbit.repository.model.Artifact; import org.eclipse.hawkbit.repository.model.ArtifactUpload; @@ -68,13 +70,21 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { private final SoftwareModuleTypeManagement softwareModuleTypeManagement; + private final ArtifactUrlHandler artifactUrlHandler; + + private final SystemManagement systemManagement; + private final EntityFactory entityFactory; MgmtSoftwareModuleResource(final ArtifactManagement artifactManagement, final SoftwareModuleManagement softwareModuleManagement, - final SoftwareModuleTypeManagement softwareModuleTypeManagement, final EntityFactory entityFactory) { + final SoftwareModuleTypeManagement softwareModuleTypeManagement, + final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement, + final EntityFactory entityFactory) { this.artifactManagement = artifactManagement; this.softwareModuleManagement = softwareModuleManagement; this.softwareModuleTypeManagement = softwareModuleTypeManagement; + this.artifactUrlHandler = artifactUrlHandler; + this.systemManagement = systemManagement; this.entityFactory = entityFactory; } @@ -125,15 +135,21 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { // subroutine @SuppressWarnings("squid:S3655") public ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, - @PathVariable("artifactId") final Long artifactId) { + @PathVariable("artifactId") final Long artifactId, + @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); - final MgmtArtifact reponse = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()); + final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()); if (!module.isDeleted()) { - MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), reponse); + if(artifactDownloadUrlType == null || artifactDownloadUrlType == "default") { + MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response); + } else { + MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler, + systemManagement); + } } - return ResponseEntity.ok(reponse); + return ResponseEntity.ok(response); } @Override diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index a8f2a12c6..69cb7c34c 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -592,6 +592,37 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId()))); } + @Test + @Description("Verifies the listing of one defined artifact assigned to a given software module. That includes the artifact metadata and cdn download links.") + void getArtifactWithCdnDownloadUrl() throws Exception { + // prepare data for test + final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); + + final int artifactSize = 5 * 1024; + final byte random[] = randomBytes(artifactSize); + + final Artifact artifact = artifactManagement.create( + new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); + + // perform test + mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( + MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(jsonPath("$.id", equalTo(artifact.getId().intValue()))) + .andExpect(jsonPath("$.size", equalTo(random.length))) + .andExpect(jsonPath("$.hashes.md5", equalTo(artifact.getMd5Hash()))) + .andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash()))) + .andExpect(jsonPath("$.hashes.sha256", equalTo(artifact.getSha256Hash()))) + .andExpect(jsonPath("$.providedFilename", equalTo("file1"))) + .andExpect(jsonPath("$._links.cdn-download.href", + equalTo("http://localhost:8080/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + + artifact.getFilename()))) + .andExpect(jsonPath("$._links.self.href", equalTo( + "http://localhost/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getId()))); + } + @Test @Description("Verifies the listing of an artifact that belongs to a soft deleted software module.") void getArtifactSoftDeleted() throws Exception { diff --git a/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties b/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties index bf28ee36c..260d33add 100644 --- a/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties +++ b/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties @@ -19,6 +19,11 @@ hawkbit.artifact.url.protocols.download-http.protocol=https hawkbit.artifact.url.protocols.download-http.supports=DMF,DDI hawkbit.artifact.url.protocols.download-http.hostname=hawkbit.eclipse.org hawkbit.artifact.url.protocols.download-http.ref={protocol}://{hostname}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} +hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.protocol=https +hawkbit.artifact.url.protocols.download-cdn-http.supports=MGMT +hawkbit.artifact.url.protocols.download-cdn-http.hostname=hawkbit.eclipse.org +hawkbit.artifact.url.protocols.download-cdn-http.ref={protocol}://{hostnameRequest}:{portRequest}/rest/v1/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} hawkbit.artifact.url.protocols.md5sum-http.rel=md5sum-http hawkbit.artifact.url.protocols.md5sum-http.protocol=${hawkbit.artifact.url.protocols.download-http.protocol} hawkbit.artifact.url.protocols.md5sum-http.supports=DDI From 80c471cf80f2ba4f90df7ca8ef3fba33df198e97 Mon Sep 17 00:00:00 2001 From: Shruthi Manavalli Ramanna Date: Tue, 6 Jun 2023 10:42:39 +0200 Subject: [PATCH 2/6] Added documentation test changes as well Signed-off-by: Shruthi Manavalli Ramanna --- .../resource/MgmtSoftwareModuleMapper.java | 2 +- .../MgmtSoftwareModuleResourceTest.java | 2 +- .../asciidoc/softwaremodules-api-guide.adoc | 4 ++++ .../documentation/MgmtApiModelProperties.java | 5 ++-- .../SoftwaremodulesDocumentationTest.java | 23 ++++++++++++++++++- 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 37f65d8a0..0683d0793 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -169,7 +169,7 @@ public final class MgmtSoftwareModuleMapper { systemManagement.getTenantMetadata().getId(), null, null, new URLPlaceholder.SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getId(), artifact.getSha1Hash())), ApiType.MGMT, null); - response.add(Link.of(urls.get(0).getRef()).withRel("cdn-download").expand()); + response.add(Link.of(urls.get(0).getRef()).withRel("download").expand()); } static List artifactsToResponse(final Collection artifacts) { diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 69cb7c34c..fefcdc9b5 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -616,7 +616,7 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes .andExpect(jsonPath("$.hashes.sha1", equalTo(artifact.getSha1Hash()))) .andExpect(jsonPath("$.hashes.sha256", equalTo(artifact.getSha256Hash()))) .andExpect(jsonPath("$.providedFilename", equalTo("file1"))) - .andExpect(jsonPath("$._links.cdn-download.href", + .andExpect(jsonPath("$._links.download.href", equalTo("http://localhost:8080/rest/v1/softwaremodules/" + sm.getId() + "/artifacts/" + artifact.getFilename()))) .andExpect(jsonPath("$._links.self.href", equalTo( diff --git a/hawkbit-rest/hawkbit-rest-docs/src/main/asciidoc/softwaremodules-api-guide.adoc b/hawkbit-rest/hawkbit-rest-docs/src/main/asciidoc/softwaremodules-api-guide.adoc index 002d3c1d6..8a8f237e0 100644 --- a/hawkbit-rest/hawkbit-rest-docs/src/main/asciidoc/softwaremodules-api-guide.adoc +++ b/hawkbit-rest/hawkbit-rest-docs/src/main/asciidoc/softwaremodules-api-guide.adoc @@ -417,6 +417,10 @@ include::{snippets}/softwaremodules/get-artifact/http-request.adoc[] include::{snippets}/softwaremodules/get-artifact/path-parameters.adoc[] +==== Request query parameter + +include::{snippets}/softwaremodules/get-artifact-with-parameters/request-parameters.adoc[] + === Response (Status 200) ==== Response fields diff --git a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java index 97d6ed458..a85c2d77b 100644 --- a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java +++ b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java @@ -55,10 +55,9 @@ public final class MgmtApiModelProperties { public static final String ARTIFACT_HASHES_SHA1 = "SHA1 hash of the artifact."; public static final String ARTIFACT_HASHES_MD5 = "MD5 hash of the artifact."; public static final String ARTIFACT_HASHES_SHA256 = "SHA256 hash of the artifact."; - - public static final String ARTIFACT_DOWNLOAD_LINK = "Download link of the artifact."; - + public static final String ARTIFACT_DOWNLOAD_LINK = "Download link of the artifact based on the chosen download url type parameter."; public static final String ARTIFACT_LIST = "List of artifacts of given software module."; + public static final String ARTIFACT_DOWNLOAD_URL_TYPE = "Type of the artifact download url. (can be default or cdn)"; // Distribution Set public static final String DS_OS = "Operating system or firmware software module - DEPRECATED (use modules)."; diff --git a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java index 909651e1e..a579cd577 100644 --- a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java +++ b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java @@ -368,7 +368,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati mockMvc.perform( get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}", - sm.getId(), artifact.getId())) + sm.getId(), artifact.getId()).param("downloadurltype", "default")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) .andDo(this.document.document( @@ -391,6 +391,27 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati .description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_LINK)))); } + @Test + @Description("Handles the GET request of retrieving a single Artifact meta data request. Required Permission: " + + SpPermission.READ_REPOSITORY) + public void getArtifactWithParameters() throws Exception { + final SoftwareModule sm = testdataFactory.createSoftwareModuleOs(); + + final byte random[] = RandomStringUtils.random(5).getBytes(); + + final Artifact artifact = artifactManagement + .create(new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, 0)); + + mockMvc.perform( + get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}", + sm.getId(), artifact.getId()).param("downloadurltype", "default")) + .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) + .andExpect(content().contentType(MediaTypes.HAL_JSON)) + .andDo(this.document.document( + requestParameters( + parameterWithName("downloadurltype").description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_URL_TYPE)))); + } + @Test @Description("Handles the GET request for downloading an artifact. Required Permission: " + SpPermission.READ_REPOSITORY) From 154875818ca9f00abb860354a98c07cd05148e28 Mon Sep 17 00:00:00 2001 From: Sebastian Firsching Date: Tue, 20 Jun 2023 07:58:04 +0200 Subject: [PATCH 3/6] Add all artifactUrls to the Mgmt API response Signed-off-by: Sebastian Firsching --- .../hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java index 0683d0793..7fdc9f2fa 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleMapper.java @@ -164,12 +164,12 @@ public final class MgmtSoftwareModuleMapper { static void addLinks(final Artifact artifact, final MgmtArtifact response, final ArtifactUrlHandler artifactUrlHandler, final SystemManagement systemManagement) { - List urls = artifactUrlHandler.getUrls( + final List urls = artifactUrlHandler.getUrls( new URLPlaceholder(systemManagement.getTenantMetadata().getTenant(), systemManagement.getTenantMetadata().getId(), null, null, new URLPlaceholder.SoftwareData(artifact.getSoftwareModule().getId(), artifact.getFilename(), artifact.getId(), artifact.getSha1Hash())), ApiType.MGMT, null); - response.add(Link.of(urls.get(0).getRef()).withRel("download").expand()); + urls.forEach(entry -> response.add(Link.of(entry.getRef()).withRel(entry.getRel()).expand())); } static List artifactsToResponse(final Collection artifacts) { From 41922bfa0cd52530b2db1205e7ebac81803f1518 Mon Sep 17 00:00:00 2001 From: Sebastian Firsching Date: Tue, 20 Jun 2023 09:08:05 +0200 Subject: [PATCH 4/6] Adapt rel value in properties files Signed-off-by: Sebastian Firsching --- .../src/main/resources/hawkbit-artifactdl-defaults.properties | 2 +- .../src/main/resources/hawkbit-test-defaults.properties | 2 +- .../src/main/resources/application-cloudsandbox.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties b/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties index 9c84f916d..551ab88e7 100644 --- a/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties +++ b/hawkbit-autoconfigure/src/main/resources/hawkbit-artifactdl-defaults.properties @@ -22,7 +22,7 @@ hawkbit.artifact.url.protocols.md5sum-http.ip=${hawkbit.artifact.url.protocols.d hawkbit.artifact.url.protocols.md5sum-http.port=${hawkbit.artifact.url.protocols.download-http.port} hawkbit.artifact.url.protocols.md5sum-http.supports=DDI hawkbit.artifact.url.protocols.md5sum-http.ref=${hawkbit.artifact.url.protocols.download-http.ref}.MD5SUM -hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.rel=download hawkbit.artifact.url.protocols.download-cdn-http.hostname=localhost hawkbit.artifact.url.protocols.download-cdn-http.ip=127.0.0.1 hawkbit.artifact.url.protocols.download-cdn-http.protocol=http diff --git a/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties b/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties index c1a03b2e1..ddf7f37b0 100644 --- a/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties +++ b/hawkbit-repository/hawkbit-repository-test/src/main/resources/hawkbit-test-defaults.properties @@ -51,7 +51,7 @@ hawkbit.artifact.url.protocols.md5sum-http.ip=${hawkbit.artifact.url.protocols.d hawkbit.artifact.url.protocols.md5sum-http.port=${hawkbit.artifact.url.protocols.download-http.port} hawkbit.artifact.url.protocols.md5sum-http.supports=DDI hawkbit.artifact.url.protocols.md5sum-http.ref=${hawkbit.artifact.url.protocols.download-http.ref}.MD5SUM -hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.rel=download hawkbit.artifact.url.protocols.download-cdn-http.hostname=localhost hawkbit.artifact.url.protocols.download-cdn-http.ip=127.0.0.1 hawkbit.artifact.url.protocols.download-cdn-http.protocol=http diff --git a/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties b/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties index 260d33add..ec80a5477 100644 --- a/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties +++ b/hawkbit-runtime/hawkbit-update-server/src/main/resources/application-cloudsandbox.properties @@ -19,7 +19,7 @@ hawkbit.artifact.url.protocols.download-http.protocol=https hawkbit.artifact.url.protocols.download-http.supports=DMF,DDI hawkbit.artifact.url.protocols.download-http.hostname=hawkbit.eclipse.org hawkbit.artifact.url.protocols.download-http.ref={protocol}://{hostname}/{tenant}/controller/v1/{controllerId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName} -hawkbit.artifact.url.protocols.download-cdn-http.rel=cdndownload-http +hawkbit.artifact.url.protocols.download-cdn-http.rel=download hawkbit.artifact.url.protocols.download-cdn-http.protocol=https hawkbit.artifact.url.protocols.download-cdn-http.supports=MGMT hawkbit.artifact.url.protocols.download-cdn-http.hostname=hawkbit.eclipse.org From bdcb361ae5e28daa3c827e2744d7e0d5f6f1c5a1 Mon Sep 17 00:00:00 2001 From: Sebastian Firsching Date: Tue, 20 Jun 2023 12:42:50 +0200 Subject: [PATCH 5/6] Introduce useArtifactUrlHandler parameter Signed-off-by: Sebastian Firsching --- .../hawkbit/mgmt/rest/api/MgmtRestConstants.java | 4 ++-- .../mgmt/rest/api/MgmtSoftwareModuleRestApi.java | 4 ++-- .../rest/resource/MgmtSoftwareModuleResource.java | 14 +++++++------- .../resource/MgmtSoftwareModuleResourceTest.java | 6 +++++- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java index 83b26e132..8d9e0cdd3 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtRestConstants.java @@ -272,9 +272,9 @@ public final class MgmtRestConstants { public static final String AUTH_V1_REQUEST_MAPPING = BASE_V1_REQUEST_MAPPING + "/userinfo"; /** - * The artifact download URL type + * Request parameter if the artifact url handler should be used */ - public static final String ARTIFACT_DOWNLOAD_URL_TYPE = "downloadurltype"; + public static final String REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER = "useartifacturlhandler"; // constant class, private constructor. diff --git a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java index efc1f280d..2055b07ef 100644 --- a/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java +++ b/hawkbit-rest/hawkbit-mgmt-api/src/main/java/org/eclipse/hawkbit/mgmt/rest/api/MgmtSoftwareModuleRestApi.java @@ -52,7 +52,7 @@ public interface MgmtSoftwareModuleRestApi { * checksum for uploaded content check * @param sha256Sum * checksum for uploaded content check - * + * * @return In case all sets could successful be created the ResponseEntity * with status code 201 - Created but without ResponseBody. In any * failure the JsonResponseExceptionHandler is handling the @@ -101,7 +101,7 @@ public interface MgmtSoftwareModuleRestApi { @ResponseBody ResponseEntity getArtifact( @PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId, - @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType); + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER, required = false) final Boolean useArtifactUrlHandler); /** * Handles the DELETE request for a single SoftwareModule. diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java index 55200ee23..6b8be1b4e 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/main/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResource.java @@ -15,6 +15,8 @@ import java.util.Collection; import java.util.List; import java.util.Optional; +import javax.validation.ValidationException; + import org.eclipse.hawkbit.api.ArtifactUrlHandler; import org.eclipse.hawkbit.mgmt.json.model.PagedList; import org.eclipse.hawkbit.mgmt.json.model.artifact.MgmtArtifact; @@ -53,8 +55,6 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import javax.validation.ValidationException; - /** * REST Resource handling for {@link SoftwareModule} and related * {@link Artifact} CRUD operations. @@ -136,16 +136,16 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { @SuppressWarnings("squid:S3655") public ResponseEntity getArtifact(@PathVariable("softwareModuleId") final Long softwareModuleId, @PathVariable("artifactId") final Long artifactId, - @RequestParam(value = MgmtRestConstants.ARTIFACT_DOWNLOAD_URL_TYPE, required = false) final String artifactDownloadUrlType) { + @RequestParam(value = MgmtRestConstants.REQUEST_PARAMETER_USE_ARTIFACT_URL_HANDLER, required = false) final Boolean useArtifactUrlHandler) { final SoftwareModule module = findSoftwareModuleWithExceptionIfNotFound(softwareModuleId, artifactId); final MgmtArtifact response = MgmtSoftwareModuleMapper.toResponse(module.getArtifact(artifactId).get()); if (!module.isDeleted()) { - if(artifactDownloadUrlType == null || artifactDownloadUrlType == "default") { - MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response); - } else { + if(useArtifactUrlHandler != null && useArtifactUrlHandler) { MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response, artifactUrlHandler, systemManagement); + } else { + MgmtSoftwareModuleMapper.addLinks(module.getArtifact(artifactId).get(), response); } } @@ -208,7 +208,7 @@ public class MgmtSoftwareModuleResource implements MgmtSoftwareModuleRestApi { LOG.debug("creating {} softwareModules", softwareModules.size()); - for (MgmtSoftwareModuleRequestBodyPost sm : softwareModules) { + for (final MgmtSoftwareModuleRequestBodyPost sm : softwareModules) { final Optional opt = softwareModuleTypeManagement.getByKey(sm.getType()); opt.ifPresent(smType -> { if (smType.isDeleted()) { diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index fefcdc9b5..67889db61 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -604,8 +604,12 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final Artifact artifact = artifactManagement.create( new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); + final MvcResult result = mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( + MediaType.APPLICATION_JSON)) + .andDo(MockMvcResultPrinter.print()).andReturn(); + // perform test - mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( + mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?useartifacturlhandler=true", sm.getId(), artifact.getId()).accept( MediaType.APPLICATION_JSON)) .andDo(MockMvcResultPrinter.print()) .andExpect(status().isOk()) From 450bfda31ebe1de01befa9fbeeb0f89a4e5f281f Mon Sep 17 00:00:00 2001 From: Sebastian Firsching Date: Wed, 21 Jun 2023 16:20:34 +0200 Subject: [PATCH 6/6] Adapt rest docs tests Signed-off-by: Sebastian Firsching --- .../mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java | 4 ---- .../hawkbit/rest/documentation/MgmtApiModelProperties.java | 2 +- .../documentation/SoftwaremodulesDocumentationTest.java | 6 +++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java index 67889db61..33b44a87c 100644 --- a/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java +++ b/hawkbit-rest/hawkbit-mgmt-resource/src/test/java/org/eclipse/hawkbit/mgmt/rest/resource/MgmtSoftwareModuleResourceTest.java @@ -604,10 +604,6 @@ class MgmtSoftwareModuleResourceTest extends AbstractManagementApiIntegrationTes final Artifact artifact = artifactManagement.create( new ArtifactUpload(new ByteArrayInputStream(random), sm.getId(), "file1", false, artifactSize)); - final MvcResult result = mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?downloadurltype=cdn", sm.getId(), artifact.getId()).accept( - MediaType.APPLICATION_JSON)) - .andDo(MockMvcResultPrinter.print()).andReturn(); - // perform test mvc.perform(get("/rest/v1/softwaremodules/{smId}/artifacts/{artId}?useartifacturlhandler=true", sm.getId(), artifact.getId()).accept( MediaType.APPLICATION_JSON)) diff --git a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java index a85c2d77b..0ba4bf4e4 100644 --- a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java +++ b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/documentation/MgmtApiModelProperties.java @@ -57,7 +57,7 @@ public final class MgmtApiModelProperties { public static final String ARTIFACT_HASHES_SHA256 = "SHA256 hash of the artifact."; public static final String ARTIFACT_DOWNLOAD_LINK = "Download link of the artifact based on the chosen download url type parameter."; public static final String ARTIFACT_LIST = "List of artifacts of given software module."; - public static final String ARTIFACT_DOWNLOAD_URL_TYPE = "Type of the artifact download url. (can be default or cdn)"; + public static final String ARTIFACT_DOWNLOAD_USE_URL_HANDLER = "Indicates if the artifact URL handler should be used e.g. for external links."; // Distribution Set public static final String DS_OS = "Operating system or firmware software module - DEPRECATED (use modules)."; diff --git a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java index a579cd577..09d6f4f67 100644 --- a/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java +++ b/hawkbit-rest/hawkbit-rest-docs/src/test/java/org/eclipse/hawkbit/rest/mgmt/documentation/SoftwaremodulesDocumentationTest.java @@ -368,7 +368,7 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati mockMvc.perform( get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}", - sm.getId(), artifact.getId()).param("downloadurltype", "default")) + sm.getId(), artifact.getId())) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) .andDo(this.document.document( @@ -404,12 +404,12 @@ public class SoftwaremodulesDocumentationTest extends AbstractApiRestDocumentati mockMvc.perform( get(MgmtRestConstants.SOFTWAREMODULE_V1_REQUEST_MAPPING + "/{softwareModuleId}/artifacts/{artifactId}", - sm.getId(), artifact.getId()).param("downloadurltype", "default")) + sm.getId(), artifact.getId()).param("useartifacturlhandler", "true")) .andDo(MockMvcResultPrinter.print()).andExpect(status().isOk()) .andExpect(content().contentType(MediaTypes.HAL_JSON)) .andDo(this.document.document( requestParameters( - parameterWithName("downloadurltype").description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_URL_TYPE)))); + parameterWithName("useartifacturlhandler").description(MgmtApiModelProperties.ARTIFACT_DOWNLOAD_USE_URL_HANDLER)))); } @Test