Made URL generator configurable.
Signed-off-by: Kai Zimmermann <kai.zimmermann@bosch-si.com>
This commit is contained in:
@@ -183,6 +183,7 @@ public class DeviceSimulatorUpdater {
|
|||||||
final Artifact artifact) {
|
final Artifact artifact) {
|
||||||
artifact.getUrls().entrySet().forEach(entry -> {
|
artifact.getUrls().entrySet().forEach(entry -> {
|
||||||
switch (entry.getKey()) {
|
switch (entry.getKey()) {
|
||||||
|
case HTTP:
|
||||||
case HTTPS:
|
case HTTPS:
|
||||||
status.add(downloadUrl(entry.getValue(), targetToken, artifact.getHashes().getSha1()));
|
status.add(downloadUrl(entry.getValue(), targetToken, artifact.getHashes().getSha1()));
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -8,3 +8,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
vaadin.servlet.productionMode=true
|
vaadin.servlet.productionMode=true
|
||||||
|
|
||||||
|
hawkbit.artifact.url.coap.enabled=false
|
||||||
|
hawkbit.artifact.url.http.enabled=false
|
||||||
|
hawkbit.artifact.url.https.enabled=true
|
||||||
|
|||||||
@@ -7,15 +7,22 @@
|
|||||||
# http://www.eclipse.org/legal/epl-v10.html
|
# http://www.eclipse.org/legal/epl-v10.html
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# DDI authentication configuration
|
||||||
hawkbit.server.ddi.security.authentication.anonymous.enabled=true
|
hawkbit.server.ddi.security.authentication.anonymous.enabled=true
|
||||||
hawkbit.server.ddi.security.authentication.targettoken.enabled=false
|
hawkbit.server.ddi.security.authentication.targettoken.enabled=true
|
||||||
hawkbit.server.ddi.security.authentication.gatewaytoken.enabled=false
|
hawkbit.server.ddi.security.authentication.gatewaytoken.enabled=true
|
||||||
|
|
||||||
spring.profiles.active=amqp
|
# Download URL generation config
|
||||||
|
hawkbit.artifact.url.coap.enabled=false
|
||||||
|
hawkbit.artifact.url.http.enabled=true
|
||||||
|
hawkbit.artifact.url.http.port=8080
|
||||||
|
hawkbit.artifact.url.https.enabled=false
|
||||||
|
|
||||||
|
## Vaadin configuration
|
||||||
vaadin.servlet.productionMode=false
|
vaadin.servlet.productionMode=false
|
||||||
|
|
||||||
## Configuration for RabbitMQ integration
|
## Configuration for DMF/RabbitMQ integration
|
||||||
|
spring.profiles.active=amqp
|
||||||
spring.rabbitmq.username=guest
|
spring.rabbitmq.username=guest
|
||||||
spring.rabbitmq.password=guest
|
spring.rabbitmq.password=guest
|
||||||
spring.rabbitmq.virtualHost=/
|
spring.rabbitmq.virtualHost=/
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ package org.eclipse.hawkbit.api;
|
|||||||
* URLs to specific artifacts.
|
* URLs to specific artifacts.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
|
||||||
public interface ArtifactUrlHandler {
|
public interface ArtifactUrlHandler {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,4 +33,11 @@ public interface ArtifactUrlHandler {
|
|||||||
*/
|
*/
|
||||||
String getUrl(String controllerId, final Long softwareModuleId, final String filename, final String sha1Hash,
|
String getUrl(String controllerId, final Long softwareModuleId, final String filename, final String sha1Hash,
|
||||||
final UrlProtocol protocol);
|
final UrlProtocol protocol);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param protocol
|
||||||
|
* to check support for
|
||||||
|
* @return <code>true</code> of the handler supports given protocol.
|
||||||
|
*/
|
||||||
|
boolean protocolSupported(UrlProtocol protocol);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,6 +78,12 @@ public class ArtifactUrlHandlerProperties {
|
|||||||
* @return the pattern to build the URL.
|
* @return the pattern to build the URL.
|
||||||
*/
|
*/
|
||||||
String getPattern();
|
String getPattern();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> if the {@link ProtocolProperties} is
|
||||||
|
* enabled.
|
||||||
|
*/
|
||||||
|
boolean isEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,6 +99,20 @@ public class ArtifactUrlHandlerProperties {
|
|||||||
*/
|
*/
|
||||||
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables HTTP URI generation in DDI and DMF.
|
||||||
|
*/
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
@@ -143,6 +163,20 @@ public class ArtifactUrlHandlerProperties {
|
|||||||
*/
|
*/
|
||||||
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
private String pattern = "{protocol}://{hostname}:{port}/{tenant}/controller/v1/{targetId}/softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables HTTPS URI generation in DDI and DMF.
|
||||||
|
*/
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
@@ -193,6 +227,20 @@ public class ArtifactUrlHandlerProperties {
|
|||||||
*/
|
*/
|
||||||
private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}";
|
private String pattern = "{protocol}://{ip}:{port}/fw/{tenant}/{targetId}/sha1/{artifactSHA1}";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables CoAP URI generation in DMF.
|
||||||
|
*/
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHostname() {
|
public String getHostname() {
|
||||||
return hostname;
|
return hostname;
|
||||||
|
|||||||
@@ -84,4 +84,15 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
|||||||
return replaceMap;
|
return replaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean protocolSupported(final UrlProtocol protocol) {
|
||||||
|
final String protocolString = protocol.name().toLowerCase();
|
||||||
|
final ProtocolProperties properties = urlHandlerProperties.getProperties(protocolString);
|
||||||
|
if (properties == null || properties.getPattern() == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return properties.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,18 +155,26 @@ public class AmqpMessageDispatcherService extends BaseAmqpService {
|
|||||||
private Artifact convertArtifact(final String targetId, final LocalArtifact localArtifact) {
|
private Artifact convertArtifact(final String targetId, final LocalArtifact localArtifact) {
|
||||||
final Artifact artifact = new Artifact();
|
final Artifact artifact = new Artifact();
|
||||||
|
|
||||||
artifact.getUrls().put(Artifact.UrlProtocol.COAP,
|
if (artifactUrlHandler.protocolSupported(UrlProtocol.COAP)) {
|
||||||
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
artifact.getUrls().put(Artifact.UrlProtocol.COAP,
|
||||||
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.COAP));
|
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
||||||
artifact.getUrls().put(Artifact.UrlProtocol.HTTP,
|
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.COAP));
|
||||||
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
}
|
||||||
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTP));
|
|
||||||
artifact.getUrls().put(Artifact.UrlProtocol.HTTPS,
|
if (artifactUrlHandler.protocolSupported(UrlProtocol.HTTP)) {
|
||||||
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
artifact.getUrls().put(Artifact.UrlProtocol.HTTP,
|
||||||
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTPS));
|
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
||||||
|
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTP));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (artifactUrlHandler.protocolSupported(UrlProtocol.HTTPS)) {
|
||||||
|
artifact.getUrls().put(Artifact.UrlProtocol.HTTPS,
|
||||||
|
artifactUrlHandler.getUrl(targetId, localArtifact.getSoftwareModule().getId(),
|
||||||
|
localArtifact.getFilename(), localArtifact.getSha1Hash(), UrlProtocol.HTTPS));
|
||||||
|
}
|
||||||
|
|
||||||
artifact.setFilename(localArtifact.getFilename());
|
artifact.setFilename(localArtifact.getFilename());
|
||||||
artifact.setHashes(new ArtifactHash(localArtifact.getSha1Hash(), null));
|
artifact.setHashes(new ArtifactHash(localArtifact.getSha1Hash(), localArtifact.getMd5Hash()));
|
||||||
artifact.setSize(localArtifact.getSize());
|
artifact.setSize(localArtifact.getSize());
|
||||||
return artifact;
|
return artifact;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON representation of artifact hash.
|
* JSON representation of artifact hash.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class ArtifactHash {
|
public class ArtifactHash {
|
||||||
|
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ public class TestConfiguration implements AsyncConfigurer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bean for the downlod id cache.
|
* Bean for the download id cache.
|
||||||
*
|
*
|
||||||
* @return the cache
|
* @return the cache
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import org.eclipse.hawkbit.repository.model.LocalArtifact;
|
|||||||
import org.eclipse.hawkbit.repository.model.Target;
|
import org.eclipse.hawkbit.repository.model.Target;
|
||||||
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash;
|
import org.eclipse.hawkbit.rest.resource.model.artifact.ArtifactHash;
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
@@ -40,10 +39,6 @@ import com.google.common.base.Charsets;
|
|||||||
* Utility class for the Controller API.
|
* Utility class for the Controller API.
|
||||||
*/
|
*/
|
||||||
public final class DataConversionHelper {
|
public final class DataConversionHelper {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
ArtifactUrlHandler artifactUrlHandler;
|
|
||||||
|
|
||||||
// utility class, private constructor.
|
// utility class, private constructor.
|
||||||
private DataConversionHelper() {
|
private DataConversionHelper() {
|
||||||
|
|
||||||
@@ -55,7 +50,6 @@ public final class DataConversionHelper {
|
|||||||
.map(module -> new Chunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(),
|
.map(module -> new Chunk(mapChunkLegacyKeys(module.getType().getKey()), module.getVersion(),
|
||||||
module.getName(), createArtifacts(targetid, module, artifactUrlHandler)))
|
module.getName(), createArtifacts(targetid, module, artifactUrlHandler)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String mapChunkLegacyKeys(final String key) {
|
private static String mapChunkLegacyKeys(final String key) {
|
||||||
@@ -76,29 +70,39 @@ public final class DataConversionHelper {
|
|||||||
* of the target
|
* of the target
|
||||||
* @param module
|
* @param module
|
||||||
* the software module
|
* the software module
|
||||||
|
*
|
||||||
* @return a list of artifacts or a empty list. Cannot be <null>.
|
* @return a list of artifacts or a empty list. Cannot be <null>.
|
||||||
*/
|
*/
|
||||||
public static List<Artifact> createArtifacts(final String targetid,
|
public static List<Artifact> createArtifacts(final String targetid,
|
||||||
final org.eclipse.hawkbit.repository.model.SoftwareModule module,
|
final org.eclipse.hawkbit.repository.model.SoftwareModule module,
|
||||||
final ArtifactUrlHandler artifactUrlHandler) {
|
final ArtifactUrlHandler artifactUrlHandler) {
|
||||||
final List<Artifact> files = new ArrayList<>();
|
final List<Artifact> files = new ArrayList<>();
|
||||||
module.getLocalArtifacts().forEach(artifact -> {
|
module.getLocalArtifacts()
|
||||||
final Artifact file = new Artifact();
|
.forEach(artifact -> files.add(createArtifact(targetid, artifactUrlHandler, artifact)));
|
||||||
file.setHashes(new ArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
|
return files;
|
||||||
file.setFilename(artifact.getFilename());
|
}
|
||||||
file.setSize(artifact.getSize());
|
|
||||||
|
private static Artifact createArtifact(final String targetid, final ArtifactUrlHandler artifactUrlHandler,
|
||||||
|
final LocalArtifact artifact) {
|
||||||
|
final Artifact file = new Artifact();
|
||||||
|
file.setHashes(new ArtifactHash(artifact.getSha1Hash(), artifact.getMd5Hash()));
|
||||||
|
file.setFilename(artifact.getFilename());
|
||||||
|
file.setSize(artifact.getSize());
|
||||||
|
|
||||||
|
if (artifactUrlHandler.protocolSupported(UrlProtocol.HTTP)) {
|
||||||
final String linkHttp = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(),
|
final String linkHttp = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(),
|
||||||
artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTP);
|
artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTP);
|
||||||
|
file.add(new Link(linkHttp).withRel("download-http"));
|
||||||
|
file.add(new Link(linkHttp + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum-http"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (artifactUrlHandler.protocolSupported(UrlProtocol.HTTPS)) {
|
||||||
final String linkHttps = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(),
|
final String linkHttps = artifactUrlHandler.getUrl(targetid, artifact.getSoftwareModule().getId(),
|
||||||
artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTPS);
|
artifact.getFilename(), artifact.getSha1Hash(), UrlProtocol.HTTPS);
|
||||||
file.add(new Link(linkHttps).withRel("download"));
|
file.add(new Link(linkHttps).withRel("download"));
|
||||||
file.add(new Link(linkHttps + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum"));
|
file.add(new Link(linkHttps + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum"));
|
||||||
file.add(new Link(linkHttp).withRel("download-http"));
|
}
|
||||||
file.add(new Link(linkHttp + ControllerConstants.ARTIFACT_MD5_DWNL_SUFFIX).withRel("md5sum-http"));
|
return file;
|
||||||
|
|
||||||
files.add(file);
|
|
||||||
});
|
|
||||||
return files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static ControllerBase fromTarget(final Target target, final List<Action> actions,
|
static ControllerBase fromTarget(final Target target, final List<Action> actions,
|
||||||
|
|||||||
Reference in New Issue
Block a user