Code format - hawkbit-core (#1924)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -9,52 +9,52 @@
|
||||
SPDX-License-Identifier: EPL-2.0
|
||||
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-core</artifactId>
|
||||
<name>hawkBit :: Core</name>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.eclipse.hawkbit</groupId>
|
||||
<artifactId>hawkbit-parent</artifactId>
|
||||
<version>${revision}</version>
|
||||
</parent>
|
||||
<artifactId>hawkbit-core</artifactId>
|
||||
<name>hawkBit :: Core</name>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.validation</groupId>
|
||||
<artifactId>jakarta.validation-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- TEST -->
|
||||
<dependency>
|
||||
<groupId>io.github.classgraph</groupId>
|
||||
<artifactId>classgraph</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.qameta.allure</groupId>
|
||||
<artifactId>allure-junit5</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -9,12 +9,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit;
|
||||
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
||||
|
||||
/**
|
||||
* {@link ContextAware} provides means for getting the current context (via {@link #getCurrentContext()}) and then
|
||||
* to execute a {@link Runnable} or a {@link Function} in the same context using {@link #runInContext(String, Runnable)}
|
||||
@@ -28,7 +28,7 @@ public interface ContextAware extends TenantAware {
|
||||
/**
|
||||
* Return the current context encoded as a {@link String}. Depending on the implementation it could,
|
||||
* for instance, be a serialized context or a reference to such.
|
||||
*
|
||||
*
|
||||
* @return could be empty if there is nothing to serialize or context aware is not supported.
|
||||
*/
|
||||
Optional<String> getCurrentContext();
|
||||
@@ -38,7 +38,6 @@ public interface ContextAware extends TenantAware {
|
||||
*
|
||||
* @param <T> the type of the input to the function
|
||||
* @param <R> the type of the result of the function
|
||||
*
|
||||
* @param serializedContext created by {@link #getCurrentContext()}. Must be non-<code>null</code>.
|
||||
* @param function function to call in the reconstructed context. Must be non-<code>null</code>.
|
||||
* @param t the argument that will be passed to the function
|
||||
|
||||
@@ -12,19 +12,19 @@ package org.eclipse.hawkbit;
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Defines global configuration for the controllers/clients on the provisioning
|
||||
* targets/devices.
|
||||
*
|
||||
*
|
||||
* Note: many of the controller related properties can be overridden on tenant
|
||||
* level.
|
||||
*/
|
||||
@Data
|
||||
@ConfigurationProperties(prefix = "hawkbit.controller")
|
||||
public class ControllerPollProperties implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,12 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu
|
||||
setUseCodeAsDefaultMessage(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourceLoader(final ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
super.setResourceLoader(resourceLoader);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PropertiesHolder refreshProperties(final String filename, final PropertiesHolder propHolder) {
|
||||
final Properties properties = new Properties();
|
||||
@@ -66,10 +72,4 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu
|
||||
}
|
||||
return new PropertiesHolder(properties, lastModified);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setResourceLoader(final ResourceLoader resourceLoader) {
|
||||
this.resourceLoader = resourceLoader;
|
||||
super.setResourceLoader(resourceLoader);
|
||||
}
|
||||
}
|
||||
@@ -11,25 +11,26 @@ package org.eclipse.hawkbit;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
/**
|
||||
* Properties for the server e.g. the server's URL which must be configured.
|
||||
*
|
||||
*/
|
||||
@Getter
|
||||
@ConfigurationProperties("hawkbit.server")
|
||||
public class HawkbitServerProperties {
|
||||
|
||||
private final Anonymous anonymous = new Anonymous();
|
||||
private final Build build = new Build();
|
||||
/**
|
||||
* Defines under which URI the update server can be reached. Used to
|
||||
* calculate download URLs for DMF transmitted update actions.
|
||||
*/
|
||||
private String url = "http://localhost:8080";
|
||||
|
||||
private final Anonymous anonymous = new Anonymous();
|
||||
|
||||
private final Build build = new Build();
|
||||
public void setUrl(final String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Properties for anonymous API access by Devices/Controllers.
|
||||
@@ -42,7 +43,6 @@ public class HawkbitServerProperties {
|
||||
/**
|
||||
* Properties for artifact download under anonymous API access by
|
||||
* Devices/Controllers.
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public static class Download {
|
||||
@@ -56,7 +56,6 @@ public class HawkbitServerProperties {
|
||||
|
||||
/**
|
||||
* Build information of the hawkBit instance. Influenced by maven.
|
||||
*
|
||||
*/
|
||||
public static class Build {
|
||||
|
||||
@@ -74,8 +73,4 @@ public class HawkbitServerProperties {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setUrl(final String url) {
|
||||
this.url = url;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import lombok.Data;
|
||||
|
||||
/**
|
||||
* Container for a generated Artifact URL.
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class ArtifactUrl {
|
||||
@@ -24,13 +23,10 @@ public class ArtifactUrl {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param protocol
|
||||
* string, e.g. ftp, http, https
|
||||
* @param rel
|
||||
* hypermedia value
|
||||
* @param ref
|
||||
* hypermedia value
|
||||
*
|
||||
* @param protocol string, e.g. ftp, http, https
|
||||
* @param rel hypermedia value
|
||||
* @param ref hypermedia value
|
||||
*/
|
||||
public ArtifactUrl(final String protocol, final String rel, final String ref) {
|
||||
this.protocol = protocol;
|
||||
|
||||
@@ -15,7 +15,6 @@ import java.util.List;
|
||||
/**
|
||||
* Interface declaration of the {@link ArtifactUrlHandler} which generates the
|
||||
* URLs to specific artifacts.
|
||||
*
|
||||
*/
|
||||
public interface ArtifactUrlHandler {
|
||||
|
||||
@@ -23,11 +22,8 @@ public interface ArtifactUrlHandler {
|
||||
* Returns a generated download URL for a given artifact parameters for a
|
||||
* specific protocol.
|
||||
*
|
||||
* @param placeholder
|
||||
* data for URL generation
|
||||
* @param api
|
||||
* given protocol that URL needs to support
|
||||
*
|
||||
* @param placeholder data for URL generation
|
||||
* @param api given protocol that URL needs to support
|
||||
* @return an URL for the given artifact parameters in a given protocol
|
||||
*/
|
||||
List<ArtifactUrl> getUrls(URLPlaceholder placeholder, ApiType api);
|
||||
@@ -36,14 +32,10 @@ public interface ArtifactUrlHandler {
|
||||
* Returns a generated download URL for a given artifact parameters for a
|
||||
* specific protocol.
|
||||
*
|
||||
* @param placeholder
|
||||
* data for URL generation
|
||||
* @param api
|
||||
* given protocol that URL needs to support
|
||||
* @param requestUri
|
||||
* of the request that allows the handler to align the generated
|
||||
* URL to the original request.
|
||||
*
|
||||
* @param placeholder data for URL generation
|
||||
* @param api given protocol that URL needs to support
|
||||
* @param requestUri of the request that allows the handler to align the generated
|
||||
* URL to the original request.
|
||||
* @return an URL for the given artifact parameters in a given protocol
|
||||
*/
|
||||
List<ArtifactUrl> getUrls(URLPlaceholder placeholder, ApiType api, URI requestUri);
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
/**
|
||||
* Artifact handler properties class for holding all supported protocols with
|
||||
* host, ip, port and download pattern.
|
||||
*
|
||||
*
|
||||
* @see PropertyBasedArtifactUrlHandler
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -23,8 +23,7 @@ public final class Base62Util {
|
||||
private static final int BASE62_BASE = BASE62_ALPHABET.length();
|
||||
|
||||
/**
|
||||
* @param base10
|
||||
* number
|
||||
* @param base10 number
|
||||
* @return converted number into Base62 ASCII string
|
||||
*/
|
||||
public static String fromBase10(final long base10) {
|
||||
@@ -42,8 +41,7 @@ public final class Base62Util {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param base62
|
||||
* number
|
||||
* @param base62 number
|
||||
* @return converted number into Base10
|
||||
*/
|
||||
public static Long toBase10(final String base62) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.net.URL;
|
||||
|
||||
/**
|
||||
* Resolve to reach the server url.
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface HostnameResolver {
|
||||
|
||||
@@ -28,19 +28,18 @@ import org.springframework.util.StringUtils;
|
||||
/**
|
||||
* Implementation for ArtifactUrlHandler for creating urls to download resource
|
||||
* based on patterns configured by {@link ArtifactUrlHandlerProperties}.
|
||||
*
|
||||
*
|
||||
* This mechanism can be used to generate links to arbitrary file hosting
|
||||
* infrastructure. However, the hawkBit update server supports hosting files as
|
||||
* well in the following {@link UrlProtocol#getRef()} patterns:
|
||||
*
|
||||
*
|
||||
* Default:
|
||||
* {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/
|
||||
* softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}
|
||||
*
|
||||
*
|
||||
* Default (MD5SUM files):
|
||||
* {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/
|
||||
* softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}.MD5SUM
|
||||
*
|
||||
*/
|
||||
public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
||||
|
||||
@@ -64,16 +63,13 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
||||
private static final String TENANT_ID_BASE10_PLACEHOLDER = "tenantId";
|
||||
private static final String TENANT_ID_BASE62_PLACEHOLDER = "tenantIdBase62";
|
||||
private static final String SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER = "softwareModuleId";
|
||||
private static final String SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER = "softwareModuleIdBase62";
|
||||
|
||||
final static String DEFAULT_URL_PROTOCOL_REF = "{" + PROTOCOL_PLACEHOLDER + "}://{" + HOSTNAME_PLACEHOLDER + "}:{" + PORT_PLACEHOLDER + "}{" + CONTEXT_PATH + "}/{" + TENANT_PLACEHOLDER + "}/controller/v1/{" + CONTROLLER_ID_PLACEHOLDER + "}/softwaremodules/{" + SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER + "}/artifacts/{" + ARTIFACT_FILENAME_PLACEHOLDER + "}";
|
||||
|
||||
private static final String SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER = "softwareModuleIdBase62";
|
||||
private final ArtifactUrlHandlerProperties urlHandlerProperties;
|
||||
private final String contextPath;
|
||||
|
||||
/**
|
||||
* @param urlHandlerProperties
|
||||
* for URL generation configuration
|
||||
* @param urlHandlerProperties for URL generation configuration
|
||||
*/
|
||||
public PropertyBasedArtifactUrlHandler(final ArtifactUrlHandlerProperties urlHandlerProperties, final String contextPath) {
|
||||
this.urlHandlerProperties = urlHandlerProperties;
|
||||
@@ -95,64 +91,6 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
||||
|
||||
}
|
||||
|
||||
private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
||||
final URI requestUri) {
|
||||
final Set<Entry<String, String>> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet();
|
||||
|
||||
String urlPattern = protocol.getRef();
|
||||
|
||||
for (final Entry<String, String> entry : entrySet) {
|
||||
if (List.of(PORT_PLACEHOLDER,PORT_REQUEST_PLACEHOLDER).contains(entry.getKey())) {
|
||||
urlPattern = urlPattern.replace(":{" + entry.getKey() + "}",
|
||||
ObjectUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue()));
|
||||
} else {
|
||||
if(entry.getValue() != null) {
|
||||
urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return urlPattern;
|
||||
}
|
||||
|
||||
private Map<String, String> getReplaceMap(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
||||
final URI requestUri) {
|
||||
final Map<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put(IP_PLACEHOLDER, protocol.getIp());
|
||||
|
||||
replaceMap.put(HOSTNAME_PLACEHOLDER, protocol.getHostname());
|
||||
|
||||
replaceMap.put(HOSTNAME_REQUEST_PLACEHOLDER, getRequestHost(protocol, requestUri));
|
||||
replaceMap.put(PORT_REQUEST_PLACEHOLDER, getRequestPort(protocol, requestUri));
|
||||
replaceMap.put(HOSTNAME_WITH_DOMAIN_REQUEST_PLACEHOLDER, computeHostWithRequestDomain(protocol, requestUri));
|
||||
replaceMap.put(PROTOCOL_REQUEST_PLACEHOLDER, getRequestProtocol(protocol, requestUri));
|
||||
|
||||
replaceMap.put(CONTEXT_PATH, contextPath);
|
||||
|
||||
replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER,
|
||||
URLEncoder.encode(placeholder.getSoftwareData().getFilename(), StandardCharsets.UTF_8));
|
||||
|
||||
replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, placeholder.getSoftwareData().getSha1Hash());
|
||||
replaceMap.put(PROTOCOL_PLACEHOLDER, protocol.getProtocol());
|
||||
replaceMap.put(PORT_PLACEHOLDER, getPort(protocol));
|
||||
replaceMap.put(TENANT_PLACEHOLDER, placeholder.getTenant());
|
||||
replaceMap.put(TENANT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTenantId()));
|
||||
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()));
|
||||
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()));
|
||||
replaceMap.put(SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER,
|
||||
String.valueOf(placeholder.getSoftwareData().getSoftwareModuleId()));
|
||||
replaceMap.put(SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER,
|
||||
Base62Util.fromBase10(placeholder.getSoftwareData().getSoftwareModuleId()));
|
||||
return replaceMap;
|
||||
}
|
||||
|
||||
private static String getRequestPort(final UrlProtocol protocol, final URI requestUri) {
|
||||
if (requestUri == null) {
|
||||
return getPort(protocol);
|
||||
@@ -205,4 +143,62 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
||||
return host + "." + domain;
|
||||
}
|
||||
|
||||
private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
||||
final URI requestUri) {
|
||||
final Set<Entry<String, String>> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet();
|
||||
|
||||
String urlPattern = protocol.getRef();
|
||||
|
||||
for (final Entry<String, String> entry : entrySet) {
|
||||
if (List.of(PORT_PLACEHOLDER, PORT_REQUEST_PLACEHOLDER).contains(entry.getKey())) {
|
||||
urlPattern = urlPattern.replace(":{" + entry.getKey() + "}",
|
||||
ObjectUtils.isEmpty(entry.getValue()) ? "" : (":" + entry.getValue()));
|
||||
} else {
|
||||
if (entry.getValue() != null) {
|
||||
urlPattern = urlPattern.replace("{" + entry.getKey() + "}", entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return urlPattern;
|
||||
}
|
||||
|
||||
private Map<String, String> getReplaceMap(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
||||
final URI requestUri) {
|
||||
final Map<String, String> replaceMap = new HashMap<>();
|
||||
replaceMap.put(IP_PLACEHOLDER, protocol.getIp());
|
||||
|
||||
replaceMap.put(HOSTNAME_PLACEHOLDER, protocol.getHostname());
|
||||
|
||||
replaceMap.put(HOSTNAME_REQUEST_PLACEHOLDER, getRequestHost(protocol, requestUri));
|
||||
replaceMap.put(PORT_REQUEST_PLACEHOLDER, getRequestPort(protocol, requestUri));
|
||||
replaceMap.put(HOSTNAME_WITH_DOMAIN_REQUEST_PLACEHOLDER, computeHostWithRequestDomain(protocol, requestUri));
|
||||
replaceMap.put(PROTOCOL_REQUEST_PLACEHOLDER, getRequestProtocol(protocol, requestUri));
|
||||
|
||||
replaceMap.put(CONTEXT_PATH, contextPath);
|
||||
|
||||
replaceMap.put(ARTIFACT_FILENAME_PLACEHOLDER,
|
||||
URLEncoder.encode(placeholder.getSoftwareData().getFilename(), StandardCharsets.UTF_8));
|
||||
|
||||
replaceMap.put(ARTIFACT_SHA1_PLACEHOLDER, placeholder.getSoftwareData().getSha1Hash());
|
||||
replaceMap.put(PROTOCOL_PLACEHOLDER, protocol.getProtocol());
|
||||
replaceMap.put(PORT_PLACEHOLDER, getPort(protocol));
|
||||
replaceMap.put(TENANT_PLACEHOLDER, placeholder.getTenant());
|
||||
replaceMap.put(TENANT_ID_BASE10_PLACEHOLDER, String.valueOf(placeholder.getTenantId()));
|
||||
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()));
|
||||
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()));
|
||||
replaceMap.put(SOFTWARE_MODULE_ID_BASE10_PLACEHOLDER,
|
||||
String.valueOf(placeholder.getSoftwareData().getSoftwareModuleId()));
|
||||
replaceMap.put(SOFTWARE_MODULE_ID_BASE62_PLACEHOLDER,
|
||||
Base62Util.fromBase10(placeholder.getSoftwareData().getSoftwareModuleId()));
|
||||
return replaceMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.api;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Container for variables available to the {@link ArtifactUrlHandler}.
|
||||
*/
|
||||
@@ -27,18 +25,13 @@ public class URLPlaceholder {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param tenant
|
||||
* of the client
|
||||
* @param tenantId
|
||||
* of teh tenant
|
||||
* @param controllerId
|
||||
* of the target
|
||||
* @param targetId
|
||||
* of the target
|
||||
* @param softwareData
|
||||
* information about the artifact and software module that can be
|
||||
* accessed by the URL.
|
||||
*
|
||||
* @param tenant of the client
|
||||
* @param tenantId of teh tenant
|
||||
* @param controllerId of the target
|
||||
* @param targetId of the target
|
||||
* @param softwareData information about the artifact and software module that can be
|
||||
* accessed by the URL.
|
||||
*/
|
||||
public URLPlaceholder(final String tenant, final Long tenantId, final String controllerId, final Long targetId,
|
||||
final SoftwareData softwareData) {
|
||||
@@ -64,14 +57,10 @@ public class URLPlaceholder {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param softwareModuleId
|
||||
* of the module the artifact belongs to
|
||||
* @param filename
|
||||
* of the artifact
|
||||
* @param artifactId
|
||||
* of the artifact
|
||||
* @param sha1Hash
|
||||
* of the artifact
|
||||
* @param softwareModuleId of the module the artifact belongs to
|
||||
* @param filename of the artifact
|
||||
* @param artifactId of the artifact
|
||||
* @param sha1Hash of the artifact
|
||||
*/
|
||||
public SoftwareData(final Long softwareModuleId, final String filename, final Long artifactId,
|
||||
final String sha1Hash) {
|
||||
|
||||
@@ -83,19 +83,8 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1,
|
||||
final String calculatedMd5, final String calculatedSha256) {
|
||||
|
||||
final String sha1 = checkEmpty(existing.getHashes().getSha1(), calculatedSha1);
|
||||
final String md5 = checkEmpty(existing.getHashes().getMd5(), calculatedMd5);
|
||||
final String sha256 = checkEmpty(existing.getHashes().getSha256(), calculatedSha256);
|
||||
|
||||
existing.setHashes(new DbArtifactHash(sha1, md5, sha256));
|
||||
return existing;
|
||||
}
|
||||
|
||||
private String checkEmpty(final String value, final String fallback) {
|
||||
return StringUtils.isEmpty(value) ? fallback : value;
|
||||
protected static String sanitizeTenant(final String tenant) {
|
||||
return tenant.trim().toUpperCase();
|
||||
}
|
||||
|
||||
protected void deleteTempFile(final String tempFile) {
|
||||
@@ -116,6 +105,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
||||
return file.getPath();
|
||||
}
|
||||
|
||||
protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes,
|
||||
final String contentType, final String tempFile) throws IOException;
|
||||
|
||||
private static File createTempFile() {
|
||||
try {
|
||||
return Files.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX).toFile();
|
||||
@@ -149,15 +141,23 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
||||
return providedHashValue != null && !hashValue.equals(providedHashValue);
|
||||
}
|
||||
|
||||
protected abstract AbstractDbArtifact store(final String tenant, final DbArtifactHash base16Hashes,
|
||||
final String contentType, final String tempFile) throws IOException;
|
||||
|
||||
private static DigestInputStream wrapInDigestInputStream(final InputStream input, final MessageDigest mdSHA1,
|
||||
final MessageDigest mdMD5, final MessageDigest mdSHA256) {
|
||||
return new DigestInputStream(new DigestInputStream(new DigestInputStream(input, mdSHA256), mdMD5), mdSHA1);
|
||||
}
|
||||
|
||||
protected static String sanitizeTenant(final String tenant) {
|
||||
return tenant.trim().toUpperCase();
|
||||
private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1,
|
||||
final String calculatedMd5, final String calculatedSha256) {
|
||||
|
||||
final String sha1 = checkEmpty(existing.getHashes().getSha1(), calculatedSha1);
|
||||
final String md5 = checkEmpty(existing.getHashes().getMd5(), calculatedMd5);
|
||||
final String sha256 = checkEmpty(existing.getHashes().getSha256(), calculatedSha256);
|
||||
|
||||
existing.setHashes(new DbArtifactHash(sha1, md5, sha256));
|
||||
return existing;
|
||||
}
|
||||
|
||||
private String checkEmpty(final String value, final String fallback) {
|
||||
return StringUtils.isEmpty(value) ? fallback : value;
|
||||
}
|
||||
}
|
||||
@@ -19,81 +19,58 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
||||
|
||||
/**
|
||||
* ArtifactRepository service interface.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public interface ArtifactRepository {
|
||||
|
||||
/**
|
||||
* Stores an artifact into the repository.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant to store the artifact
|
||||
* @param content
|
||||
* the content to store
|
||||
* @param filename
|
||||
* the filename of the artifact
|
||||
* @param contentType
|
||||
* the content type of the artifact
|
||||
* @param hash
|
||||
* the hashes of the artifact to do hash-checks after storing the
|
||||
* artifact, might be {@code null}
|
||||
*
|
||||
* @param tenant the tenant to store the artifact
|
||||
* @param content the content to store
|
||||
* @param filename the filename of the artifact
|
||||
* @param contentType the content type of the artifact
|
||||
* @param hash the hashes of the artifact to do hash-checks after storing the
|
||||
* artifact, might be {@code null}
|
||||
* @return the stored artifact
|
||||
*
|
||||
* @throws MethodNotSupportedException
|
||||
* if implementation does not support the operation
|
||||
* @throws ArtifactStoreException
|
||||
* in case storing of the artifact was not successful
|
||||
* @throws HashNotMatchException
|
||||
* in case {@code hash} is provided and not matching to the
|
||||
* calculated hashes during storing
|
||||
* @throws MethodNotSupportedException if implementation does not support the operation
|
||||
* @throws ArtifactStoreException in case storing of the artifact was not successful
|
||||
* @throws HashNotMatchException in case {@code hash} is provided and not matching to the
|
||||
* calculated hashes during storing
|
||||
*/
|
||||
AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||
String contentType, DbArtifactHash hash);
|
||||
|
||||
/**
|
||||
* Deletes an artifact by its SHA1 hash.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant to store the artifact
|
||||
* @param sha1Hash
|
||||
* the sha1-hash of the artifact to delete
|
||||
*
|
||||
* @throws MethodNotSupportedException
|
||||
* if implementation does not support the operation
|
||||
*
|
||||
* @param tenant the tenant to store the artifact
|
||||
* @param sha1Hash the sha1-hash of the artifact to delete
|
||||
* @throws MethodNotSupportedException if implementation does not support the operation
|
||||
*/
|
||||
void deleteBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
|
||||
/**
|
||||
* Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant to store the artifact
|
||||
* @param sha1Hash
|
||||
* the sha1-hash of the file to lookup.
|
||||
*
|
||||
* @param tenant the tenant to store the artifact
|
||||
* @param sha1Hash the sha1-hash of the file to lookup.
|
||||
* @return The artifact file object or {@code null} if no file exists.
|
||||
*
|
||||
* @throws MethodNotSupportedException
|
||||
* if implementation does not support the operation
|
||||
* @throws MethodNotSupportedException if implementation does not support the operation
|
||||
*/
|
||||
AbstractDbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
|
||||
/**
|
||||
* Deletes all artifacts of given tenant.
|
||||
*
|
||||
* @param tenant
|
||||
* to erase
|
||||
*
|
||||
* @param tenant to erase
|
||||
*/
|
||||
void deleteByTenant(@NotEmpty String tenant);
|
||||
|
||||
/**
|
||||
* Checks if an artifact exists for a given tenant by its sha1 hash
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant
|
||||
* @param sha1Hash
|
||||
* the sha1-hash of the file to lookup.
|
||||
*
|
||||
* @param tenant the tenant
|
||||
* @param sha1Hash the sha1-hash of the file to lookup.
|
||||
* @return the boolean whether the artifact exists or not
|
||||
*/
|
||||
boolean existsByTenantAndSha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||
|
||||
@@ -19,11 +19,9 @@ public class ArtifactStoreException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a ArtifactStoreException with message and cause.
|
||||
*
|
||||
* @param message
|
||||
* the message of the exception
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param message the message of the exception
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public ArtifactStoreException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
@@ -31,9 +29,8 @@ public class ArtifactStoreException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a ArtifactStoreException with message.
|
||||
*
|
||||
* @param message
|
||||
* the message of the exception
|
||||
*
|
||||
* @param message the message of the exception
|
||||
*/
|
||||
public ArtifactStoreException(final String message) {
|
||||
super(message);
|
||||
@@ -41,9 +38,8 @@ public class ArtifactStoreException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a ArtifactStoreException with cause.
|
||||
*
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public ArtifactStoreException(final Throwable cause) {
|
||||
super(cause);
|
||||
|
||||
@@ -12,29 +12,21 @@ package org.eclipse.hawkbit.artifact.repository;
|
||||
/**
|
||||
* Thrown when provided hashes and hashes caluclated during storing are not
|
||||
* matching.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class HashNotMatchException extends RuntimeException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static final String SHA1 = "SHA-1";
|
||||
public static final String MD5 = "MD5";
|
||||
public static final String SHA256 = "SHA-256";
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final String hashFunction;
|
||||
|
||||
/**
|
||||
* Constructs a HashNotMatchException with message and cause.
|
||||
*
|
||||
* @param message
|
||||
* the message of the exception
|
||||
* @param cause
|
||||
* the cause of the exception
|
||||
* @param hashFunction
|
||||
* the hash function which caused this exception
|
||||
*
|
||||
* @param message the message of the exception
|
||||
* @param cause the cause of the exception
|
||||
* @param hashFunction the hash function which caused this exception
|
||||
*/
|
||||
public HashNotMatchException(final String message, final Throwable cause, final String hashFunction) {
|
||||
super(message, cause);
|
||||
@@ -43,11 +35,9 @@ public class HashNotMatchException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Constructs a HashNotMatchException with message.
|
||||
*
|
||||
* @param message
|
||||
* the message of the exception
|
||||
* @param hashFunction
|
||||
* the hash function which caused this exception
|
||||
*
|
||||
* @param message the message of the exception
|
||||
* @param hashFunction the hash function which caused this exception
|
||||
*/
|
||||
public HashNotMatchException(final String message, final String hashFunction) {
|
||||
super(message);
|
||||
|
||||
@@ -39,7 +39,7 @@ public interface DbArtifact {
|
||||
/**
|
||||
* Creates an {@link InputStream} on this artifact. Caller has to take care of
|
||||
* closing the stream. Repeatable calls open a new {@link InputStream}.
|
||||
*
|
||||
*
|
||||
* @return {@link InputStream} to read from artifact.
|
||||
*/
|
||||
InputStream getFileInputStream();
|
||||
|
||||
@@ -23,7 +23,7 @@ public class DbArtifactHash {
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
*
|
||||
* @param sha1 the sha1 hash
|
||||
* @param md5 the md5 hash
|
||||
* @param sha256 the sha256 hash
|
||||
|
||||
@@ -22,8 +22,7 @@ public interface TenancyCacheManager extends CacheManager {
|
||||
* tenant key. This is necessary e.g. for retrieving caches not for the
|
||||
* current tenant.
|
||||
*
|
||||
* @param name
|
||||
* the name of the cache to retrieve directly
|
||||
* @param name the name of the cache to retrieve directly
|
||||
* @return the cache associated with the name without tenancy separation
|
||||
*/
|
||||
Cache getDirectCache(String name);
|
||||
@@ -32,8 +31,7 @@ public interface TenancyCacheManager extends CacheManager {
|
||||
* Evicts all caches for a given tenant. All caches under a certain tenant
|
||||
* gets evicted.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant to evict caches
|
||||
* @param tenant the tenant to evict caches
|
||||
*/
|
||||
void evictCaches(final String tenant);
|
||||
}
|
||||
|
||||
@@ -38,10 +38,8 @@ public class TenantAwareCacheManager implements TenancyCacheManager {
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param delegate
|
||||
* the {@link CacheManager} to delegate to.
|
||||
* @param tenantAware
|
||||
* the tenant aware to retrieve the current tenant
|
||||
* @param delegate the {@link CacheManager} to delegate to.
|
||||
* @param tenantAware the tenant aware to retrieve the current tenant
|
||||
*/
|
||||
public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) {
|
||||
this.tenantAware = tenantAware;
|
||||
|
||||
@@ -9,12 +9,12 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.exception;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.util.Map;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* Generic Custom Exception to wrap the Runtime and checked exception
|
||||
*/
|
||||
@@ -30,7 +30,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param error detail
|
||||
*/
|
||||
protected AbstractServerRtException(final SpServerError error) {
|
||||
@@ -41,7 +41,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param message custom error message
|
||||
* @param error detail
|
||||
*/
|
||||
@@ -63,7 +63,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param message custom error message
|
||||
* @param error detail
|
||||
* @param cause of the exception
|
||||
@@ -76,7 +76,7 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
*
|
||||
* @param error detail
|
||||
* @param cause of the exception
|
||||
*/
|
||||
@@ -93,7 +93,8 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
||||
* @param error detail
|
||||
* @param cause of the exception
|
||||
*/
|
||||
protected AbstractServerRtException(final String message, final SpServerError error, final Throwable cause, final Map<String, Object> info) {
|
||||
protected AbstractServerRtException(final String message, final SpServerError error, final Throwable cause,
|
||||
final Map<String, Object> info) {
|
||||
super(message, cause);
|
||||
this.error = error;
|
||||
this.info = info;
|
||||
|
||||
@@ -13,11 +13,9 @@ package org.eclipse.hawkbit.exception;
|
||||
* {@link GenericSpServerException} is thrown when a given entity in's actual
|
||||
* and cannot be stored within the current session. Reason could be that it has
|
||||
* been changed within another session.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class GenericSpServerException extends AbstractServerRtException {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR;
|
||||
|
||||
@@ -30,9 +28,8 @@ public class GenericSpServerException extends AbstractServerRtException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public GenericSpServerException(final Throwable cause) {
|
||||
super(THIS_ERROR, cause);
|
||||
@@ -40,11 +37,9 @@ public class GenericSpServerException extends AbstractServerRtException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* custom error message
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param message custom error message
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public GenericSpServerException(final String message, final Throwable cause) {
|
||||
super(message, THIS_ERROR, cause);
|
||||
@@ -52,9 +47,8 @@ public class GenericSpServerException extends AbstractServerRtException {
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* custom error message
|
||||
*
|
||||
* @param message custom error message
|
||||
*/
|
||||
public GenericSpServerException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
|
||||
@@ -15,14 +15,13 @@ package org.eclipse.hawkbit.exception;
|
||||
|
||||
public enum SpServerError {
|
||||
|
||||
|
||||
SP_REPO_GENERIC_ERROR("hawkbit.server.error.repo.genericError", "unknown error occurred"),
|
||||
SP_REPO_ENTITY_ALREADY_EXISTS("hawkbit.server.error.repo.entitiyAlreayExists",
|
||||
"The given entity already exists in database"),
|
||||
"The given entity already exists in database"),
|
||||
SP_REPO_AUTO_CONFIRMATION_ALREADY_ACTIVE("hawkbit.server.error.repo.autoConfAlreadyActive",
|
||||
"Auto confirmation is already active"),
|
||||
"Auto confirmation is already active"),
|
||||
SP_CONFIRMATION_FEEDBACK_INVALID("hawkbit.server.confirmation.feedback.invalid",
|
||||
"Confirmation feedback is not valid"),
|
||||
"Confirmation feedback is not valid"),
|
||||
SP_REPO_CONSTRAINT_VIOLATION("hawkbit.server.error.repo.constraintViolation",
|
||||
"The given entity cannot be saved due to Constraint Violation"),
|
||||
SP_REPO_INVALID_TARGET_ADDRESS("hawkbit.server.error.repo.invalidTargetAddress",
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Sort and search fields for actions.
|
||||
*/
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the DistributionSet model which can be used in the
|
||||
* REST API e.g. for sorting etc.
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the Tag model which can be used in the REST API e.g.
|
||||
* for sorting etc.
|
||||
@@ -23,23 +23,23 @@ import java.util.List;
|
||||
@Getter
|
||||
public enum DistributionSetTagFields implements RsqlQueryField {
|
||||
|
||||
ID(TagFields.ID.getJpaEntityFieldName()),
|
||||
NAME(TagFields.NAME.getJpaEntityFieldName()),
|
||||
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
|
||||
COLOUR(TagFields.COLOUR.getJpaEntityFieldName()),
|
||||
DISTRIBUTIONSET("assignedToDistributionSet",
|
||||
DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName());
|
||||
ID(TagFields.ID.getJpaEntityFieldName()),
|
||||
NAME(TagFields.NAME.getJpaEntityFieldName()),
|
||||
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
|
||||
COLOUR(TagFields.COLOUR.getJpaEntityFieldName()),
|
||||
DISTRIBUTIONSET("assignedToDistributionSet",
|
||||
DistributionSetFields.ID.getJpaEntityFieldName(), DistributionSetFields.NAME.getJpaEntityFieldName());
|
||||
|
||||
private final String jpaEntityFieldName;
|
||||
private final List<String> subEntityAttributes;
|
||||
private final String jpaEntityFieldName;
|
||||
private final List<String> subEntityAttributes;
|
||||
|
||||
DistributionSetTagFields(final String jpaEntityFieldName) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
this.subEntityAttributes = Collections.emptyList();
|
||||
}
|
||||
DistributionSetTagFields(final String jpaEntityFieldName) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
this.subEntityAttributes = Collections.emptyList();
|
||||
}
|
||||
|
||||
DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
this.subEntityAttributes = List.of(subEntityAttributes);
|
||||
}
|
||||
DistributionSetTagFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
this.subEntityAttributes = List.of(subEntityAttributes);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,7 @@ public interface FieldValueConverter<T extends Enum<T>> {
|
||||
/**
|
||||
* Converts the given {@code value} into the representation to build a
|
||||
* generic query.
|
||||
*
|
||||
*
|
||||
* @param e the enum to build the value for
|
||||
* @param value the value in string representation
|
||||
* @return the converted object or {@code null} if conversation fails, if
|
||||
@@ -34,7 +34,7 @@ public interface FieldValueConverter<T extends Enum<T>> {
|
||||
|
||||
/**
|
||||
* returns the possible values associated with the given enum type.
|
||||
*
|
||||
*
|
||||
* @param e the enum type to retrieve the possible values
|
||||
* @return the possible values for a specific enum or {@code null}
|
||||
*/
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the Rollout model which can be used in the REST API e.g. for sorting etc.
|
||||
*/
|
||||
|
||||
@@ -16,7 +16,6 @@ import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* An RSQL query field interface extended by all the fields that could be used in RSQL queries.
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the SoftwareModule model which can be used in the REST API e.g. for sorting etc.
|
||||
*/
|
||||
@@ -41,6 +41,7 @@ public enum SoftwareModuleFields implements RsqlQueryField {
|
||||
SoftwareModuleFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
|
||||
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
|
||||
}
|
||||
|
||||
SoftwareModuleFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
|
||||
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
|
||||
}
|
||||
|
||||
@@ -9,14 +9,14 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the Target model which can be used in the REST API
|
||||
* e.g. for sorting etc.
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc.
|
||||
*/
|
||||
|
||||
@@ -18,14 +18,14 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public enum TargetTagFields implements RsqlQueryField {
|
||||
|
||||
ID(TagFields.ID.getJpaEntityFieldName()),
|
||||
NAME(TagFields.NAME.getJpaEntityFieldName()),
|
||||
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
|
||||
COLOUR(TagFields.COLOUR.getJpaEntityFieldName());
|
||||
ID(TagFields.ID.getJpaEntityFieldName()),
|
||||
NAME(TagFields.NAME.getJpaEntityFieldName()),
|
||||
DESCRIPTION(TagFields.DESCRIPTION.getJpaEntityFieldName()),
|
||||
COLOUR(TagFields.COLOUR.getJpaEntityFieldName());
|
||||
|
||||
private final String jpaEntityFieldName;
|
||||
private final String jpaEntityFieldName;
|
||||
|
||||
TargetTagFields(final String jpaEntityFieldName) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
}
|
||||
TargetTagFields(final String jpaEntityFieldName) {
|
||||
this.jpaEntityFieldName = jpaEntityFieldName;
|
||||
}
|
||||
}
|
||||
@@ -34,11 +34,9 @@ public interface TenantAware {
|
||||
* {@link TenantRunner} it must be ensured that the original tenant before
|
||||
* this invocation is reset.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant which the specific code should run
|
||||
* @param tenantRunner
|
||||
* the runner which is implemented to run this specific code
|
||||
* under the given tenant
|
||||
* @param tenant the tenant which the specific code should run
|
||||
* @param tenantRunner the runner which is implemented to run this specific code
|
||||
* under the given tenant
|
||||
* @return the return type of the {@link TenantRunner}
|
||||
*/
|
||||
<T> T runAsTenant(String tenant, TenantRunner<T> tenantRunner);
|
||||
@@ -50,13 +48,10 @@ public interface TenantAware {
|
||||
* {@link TenantRunner} it must be ensured that the original tenant before
|
||||
* this invocation is reset.
|
||||
*
|
||||
* @param tenant
|
||||
* the tenant which the specific code should run with
|
||||
* @param username
|
||||
* the username which the specific code should run with
|
||||
* @param tenantRunner
|
||||
* the runner which is implemented to run this specific code
|
||||
* under the given tenant
|
||||
* @param tenant the tenant which the specific code should run with
|
||||
* @param username the username which the specific code should run with
|
||||
* @param tenantRunner the runner which is implemented to run this specific code
|
||||
* under the given tenant
|
||||
* @return the return type of the {@link TenantRunner}
|
||||
*/
|
||||
<T> T runAsTenantAsUser(String tenant, String username, TenantRunner<T> tenantRunner);
|
||||
@@ -66,14 +61,11 @@ public interface TenantAware {
|
||||
* a given tenant by using the
|
||||
* {@link TenantAware#runAsTenant(String, TenantRunner)}.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param <T>
|
||||
* the return type of the runner
|
||||
* @param <T> the return type of the runner
|
||||
*/
|
||||
@FunctionalInterface
|
||||
interface TenantRunner<T> {
|
||||
|
||||
/**
|
||||
* Called to run specific code and a given tenant.
|
||||
*
|
||||
|
||||
@@ -21,10 +21,8 @@ public interface UserAuthoritiesResolver {
|
||||
/**
|
||||
* User authorities/roles lookup based on the tenant and the username
|
||||
*
|
||||
* @param tenant
|
||||
* The tenant that this user belongs to
|
||||
* @param username
|
||||
* The username of the user
|
||||
* @param tenant The tenant that this user belongs to
|
||||
* @param username The username of the user
|
||||
* @return a {@link Collection} of authorities/roles for this user
|
||||
*/
|
||||
Collection<String> getUserAuthorities(String tenant, String username);
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
||||
/**
|
||||
* The {@link #InvalidTenantConfigurationKeyException} is thrown when an invalid
|
||||
* configuration key is used.
|
||||
*
|
||||
*/
|
||||
public class InvalidTenantConfigurationKeyException extends AbstractServerRtException {
|
||||
|
||||
@@ -31,9 +30,8 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public InvalidTenantConfigurationKeyException(final Throwable cause) {
|
||||
super(THIS_ERROR, cause);
|
||||
@@ -41,11 +39,9 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param message of the exception
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public InvalidTenantConfigurationKeyException(final String message, final Throwable cause) {
|
||||
super(message, THIS_ERROR, cause);
|
||||
@@ -53,9 +49,8 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
*
|
||||
* @param message of the exception
|
||||
*/
|
||||
public InvalidTenantConfigurationKeyException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
|
||||
@@ -15,7 +15,6 @@ import org.eclipse.hawkbit.exception.SpServerError;
|
||||
/**
|
||||
* Exception which is thrown, when the validation of the configuration value has
|
||||
* not been successful.
|
||||
*
|
||||
*/
|
||||
public class TenantConfigurationValidatorException extends AbstractServerRtException {
|
||||
|
||||
@@ -31,9 +30,8 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public TenantConfigurationValidatorException(final Throwable cause) {
|
||||
super(THIS_ERROR, cause);
|
||||
@@ -41,11 +39,9 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
* @param cause
|
||||
* of the exception
|
||||
*
|
||||
* @param message of the exception
|
||||
* @param cause of the exception
|
||||
*/
|
||||
public TenantConfigurationValidatorException(final String message, final Throwable cause) {
|
||||
super(message, THIS_ERROR, cause);
|
||||
@@ -53,9 +49,8 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
||||
|
||||
/**
|
||||
* Parameterized constructor.
|
||||
*
|
||||
* @param message
|
||||
* of the exception
|
||||
*
|
||||
* @param message of the exception
|
||||
*/
|
||||
public TenantConfigurationValidatorException(final String message) {
|
||||
super(message, THIS_ERROR);
|
||||
|
||||
@@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Feature("Unit Tests - Artifact URL Handler")
|
||||
@Story("Base62 Utility tests")
|
||||
|
||||
@@ -13,18 +13,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.eclipse.hawkbit.api.ArtifactUrlHandlerProperties.UrlProtocol;
|
||||
import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
/**
|
||||
@@ -51,13 +49,10 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
||||
private static final String TENANT = "TEST_TENANT";
|
||||
|
||||
private static final String HTTP_LOCALHOST = "http://localhost:8080/";
|
||||
|
||||
private ArtifactUrlHandler urlHandlerUnderTest;
|
||||
|
||||
private ArtifactUrlHandlerProperties properties;
|
||||
|
||||
private static URLPlaceholder placeholder = new URLPlaceholder(TENANT, TENANT_ID, CONTROLLER_ID, TARGETID,
|
||||
new SoftwareData(SOFTWAREMODULEID, FILENAME_DECODE, ARTIFACTID, SHA1HASH));
|
||||
private ArtifactUrlHandler urlHandlerUnderTest;
|
||||
private ArtifactUrlHandlerProperties properties;
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
@@ -142,6 +137,7 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
||||
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + "://"
|
||||
+ testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Description("Verfies that the protocol of the statically defined hostname is replaced with the protocol of the request.")
|
||||
public void urlGenerationWithProtocolFromRequest() throws URISyntaxException {
|
||||
@@ -191,10 +187,10 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
||||
proto.setProtocol(protocol);
|
||||
properties.getProtocols().put("download-http", proto);
|
||||
|
||||
URI uri = new URI(protocol+"://anotherHost.com");
|
||||
URI uri = new URI(protocol + "://anotherHost.com");
|
||||
final List<ArtifactUrl> urls = urlHandlerUnderTest.getUrls(placeholder, ApiType.DDI, uri);
|
||||
assertThat(urls).containsExactly(new ArtifactUrl(protocol.toUpperCase(), "download-http",
|
||||
uri +"/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
||||
uri + "/" + TENANT + "/controller/v1/" + CONTROLLER_ID + "/softwaremodules/"
|
||||
+ SOFTWAREMODULEID + "/artifacts/" + FILENAME_ENCODE));
|
||||
|
||||
}
|
||||
|
||||
@@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import io.qameta.allure.Description;
|
||||
import io.qameta.allure.Feature;
|
||||
import io.qameta.allure.Story;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@Feature("Unit Tests - Artifact URL Handler")
|
||||
@Story("URL placeholder tests")
|
||||
|
||||
@@ -9,16 +9,16 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.github.classgraph.ClassGraph;
|
||||
import io.github.classgraph.ClassInfo;
|
||||
import io.github.classgraph.ScanResult;
|
||||
import io.qameta.allure.Description;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FileNameFieldsTest {
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user