Code format - hawkbit-core (#1924)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
SPDX-License-Identifier: EPL-2.0
|
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"
|
<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">
|
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>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<parent>
|
<parent>
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit;
|
package org.eclipse.hawkbit;
|
||||||
|
|
||||||
import org.eclipse.hawkbit.tenancy.TenantAware;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
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
|
* {@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)}
|
* to execute a {@link Runnable} or a {@link Function} in the same context using {@link #runInContext(String, Runnable)}
|
||||||
@@ -38,7 +38,6 @@ public interface ContextAware extends TenantAware {
|
|||||||
*
|
*
|
||||||
* @param <T> the type of the input to the function
|
* @param <T> the type of the input to the function
|
||||||
* @param <R> the type of the result of 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 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 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
|
* @param t the argument that will be passed to the function
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ package org.eclipse.hawkbit;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +24,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
|
|||||||
@Data
|
@Data
|
||||||
@ConfigurationProperties(prefix = "hawkbit.controller")
|
@ConfigurationProperties(prefix = "hawkbit.controller")
|
||||||
public class ControllerPollProperties implements Serializable {
|
public class ControllerPollProperties implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -39,6 +39,12 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu
|
|||||||
setUseCodeAsDefaultMessage(true);
|
setUseCodeAsDefaultMessage(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setResourceLoader(final ResourceLoader resourceLoader) {
|
||||||
|
this.resourceLoader = resourceLoader;
|
||||||
|
super.setResourceLoader(resourceLoader);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected PropertiesHolder refreshProperties(final String filename, final PropertiesHolder propHolder) {
|
protected PropertiesHolder refreshProperties(final String filename, final PropertiesHolder propHolder) {
|
||||||
final Properties properties = new Properties();
|
final Properties properties = new Properties();
|
||||||
@@ -66,10 +72,4 @@ public class DistributedResourceBundleMessageSource extends ReloadableResourceBu
|
|||||||
}
|
}
|
||||||
return new PropertiesHolder(properties, lastModified);
|
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.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties for the server e.g. the server's URL which must be configured.
|
* Properties for the server e.g. the server's URL which must be configured.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Getter
|
@Getter
|
||||||
@ConfigurationProperties("hawkbit.server")
|
@ConfigurationProperties("hawkbit.server")
|
||||||
public class HawkbitServerProperties {
|
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
|
* Defines under which URI the update server can be reached. Used to
|
||||||
* calculate download URLs for DMF transmitted update actions.
|
* calculate download URLs for DMF transmitted update actions.
|
||||||
*/
|
*/
|
||||||
private String url = "http://localhost:8080";
|
private String url = "http://localhost:8080";
|
||||||
|
|
||||||
private final Anonymous anonymous = new Anonymous();
|
public void setUrl(final String url) {
|
||||||
|
this.url = url;
|
||||||
private final Build build = new Build();
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties for anonymous API access by Devices/Controllers.
|
* Properties for anonymous API access by Devices/Controllers.
|
||||||
@@ -42,7 +43,6 @@ public class HawkbitServerProperties {
|
|||||||
/**
|
/**
|
||||||
* Properties for artifact download under anonymous API access by
|
* Properties for artifact download under anonymous API access by
|
||||||
* Devices/Controllers.
|
* Devices/Controllers.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public static class Download {
|
public static class Download {
|
||||||
@@ -56,7 +56,6 @@ public class HawkbitServerProperties {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build information of the hawkBit instance. Influenced by maven.
|
* Build information of the hawkBit instance. Influenced by maven.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public static class Build {
|
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.
|
* Container for a generated Artifact URL.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class ArtifactUrl {
|
public class ArtifactUrl {
|
||||||
@@ -25,12 +24,9 @@ public class ArtifactUrl {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param protocol
|
* @param protocol string, e.g. ftp, http, https
|
||||||
* string, e.g. ftp, http, https
|
* @param rel hypermedia value
|
||||||
* @param rel
|
* @param ref hypermedia value
|
||||||
* hypermedia value
|
|
||||||
* @param ref
|
|
||||||
* hypermedia value
|
|
||||||
*/
|
*/
|
||||||
public ArtifactUrl(final String protocol, final String rel, final String ref) {
|
public ArtifactUrl(final String protocol, final String rel, final String ref) {
|
||||||
this.protocol = protocol;
|
this.protocol = protocol;
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* Interface declaration of the {@link ArtifactUrlHandler} which generates the
|
* Interface declaration of the {@link ArtifactUrlHandler} which generates the
|
||||||
* URLs to specific artifacts.
|
* URLs to specific artifacts.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ArtifactUrlHandler {
|
public interface ArtifactUrlHandler {
|
||||||
|
|
||||||
@@ -23,11 +22,8 @@ public interface ArtifactUrlHandler {
|
|||||||
* Returns a generated download URL for a given artifact parameters for a
|
* Returns a generated download URL for a given artifact parameters for a
|
||||||
* specific protocol.
|
* specific protocol.
|
||||||
*
|
*
|
||||||
* @param placeholder
|
* @param placeholder data for URL generation
|
||||||
* data for URL generation
|
* @param api given protocol that URL needs to support
|
||||||
* @param api
|
|
||||||
* given protocol that URL needs to support
|
|
||||||
*
|
|
||||||
* @return an URL for the given artifact parameters in a given protocol
|
* @return an URL for the given artifact parameters in a given protocol
|
||||||
*/
|
*/
|
||||||
List<ArtifactUrl> getUrls(URLPlaceholder placeholder, ApiType api);
|
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
|
* Returns a generated download URL for a given artifact parameters for a
|
||||||
* specific protocol.
|
* specific protocol.
|
||||||
*
|
*
|
||||||
* @param placeholder
|
* @param placeholder data for URL generation
|
||||||
* data for URL generation
|
* @param api given protocol that URL needs to support
|
||||||
* @param api
|
* @param requestUri of the request that allows the handler to align the generated
|
||||||
* 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.
|
* URL to the original request.
|
||||||
*
|
|
||||||
* @return an URL for the given artifact parameters in a given protocol
|
* @return an URL for the given artifact parameters in a given protocol
|
||||||
*/
|
*/
|
||||||
List<ArtifactUrl> getUrls(URLPlaceholder placeholder, ApiType api, URI requestUri);
|
List<ArtifactUrl> getUrls(URLPlaceholder placeholder, ApiType api, URI requestUri);
|
||||||
|
|||||||
@@ -23,8 +23,7 @@ public final class Base62Util {
|
|||||||
private static final int BASE62_BASE = BASE62_ALPHABET.length();
|
private static final int BASE62_BASE = BASE62_ALPHABET.length();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param base10
|
* @param base10 number
|
||||||
* number
|
|
||||||
* @return converted number into Base62 ASCII string
|
* @return converted number into Base62 ASCII string
|
||||||
*/
|
*/
|
||||||
public static String fromBase10(final long base10) {
|
public static String fromBase10(final long base10) {
|
||||||
@@ -42,8 +41,7 @@ public final class Base62Util {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param base62
|
* @param base62 number
|
||||||
* number
|
|
||||||
* @return converted number into Base10
|
* @return converted number into Base10
|
||||||
*/
|
*/
|
||||||
public static Long toBase10(final String base62) {
|
public static Long toBase10(final String base62) {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ import java.net.URL;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve to reach the server url.
|
* Resolve to reach the server url.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface HostnameResolver {
|
public interface HostnameResolver {
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ import org.springframework.util.StringUtils;
|
|||||||
* Default (MD5SUM files):
|
* Default (MD5SUM files):
|
||||||
* {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/
|
* {protocol}://{hostname}:{port}{contextPath}/{tenant}/controller/v1/{controllerId}/
|
||||||
* softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}.MD5SUM
|
* softwaremodules/{softwareModuleId}/artifacts/{artifactFileName}.MD5SUM
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
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_BASE10_PLACEHOLDER = "tenantId";
|
||||||
private static final String TENANT_ID_BASE62_PLACEHOLDER = "tenantIdBase62";
|
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_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 + "}";
|
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 ArtifactUrlHandlerProperties urlHandlerProperties;
|
||||||
private final String contextPath;
|
private final String contextPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param urlHandlerProperties
|
* @param urlHandlerProperties for URL generation configuration
|
||||||
* for URL generation configuration
|
|
||||||
*/
|
*/
|
||||||
public PropertyBasedArtifactUrlHandler(final ArtifactUrlHandlerProperties urlHandlerProperties, final String contextPath) {
|
public PropertyBasedArtifactUrlHandler(final ArtifactUrlHandlerProperties urlHandlerProperties, final String contextPath) {
|
||||||
this.urlHandlerProperties = urlHandlerProperties;
|
this.urlHandlerProperties = urlHandlerProperties;
|
||||||
@@ -95,6 +91,58 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getRequestPort(final UrlProtocol protocol, final URI requestUri) {
|
||||||
|
if (requestUri == null) {
|
||||||
|
return getPort(protocol);
|
||||||
|
}
|
||||||
|
// if port undefined then default protocol port is used
|
||||||
|
return requestUri.getPort() > 0 ? String.valueOf(requestUri.getPort()) : "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRequestHost(final UrlProtocol protocol, final URI requestUri) {
|
||||||
|
if (requestUri == null) {
|
||||||
|
return protocol.getHostname();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(requestUri.getHost()).orElse(protocol.getHostname());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getRequestProtocol(final UrlProtocol protocol, final URI requestUri) {
|
||||||
|
if (requestUri == null) {
|
||||||
|
return protocol.getProtocol();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.ofNullable(requestUri.getScheme()).orElse(protocol.getProtocol());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPort(final UrlProtocol protocol) {
|
||||||
|
return ObjectUtils.isEmpty(protocol.getPort()) ? null : String.valueOf(protocol.getPort());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String computeHostWithRequestDomain(final UrlProtocol protocol, final URI requestUri) {
|
||||||
|
|
||||||
|
if (requestUri == null) {
|
||||||
|
return protocol.getHostname();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!protocol.getHostname().contains(".")) {
|
||||||
|
return protocol.getHostname();
|
||||||
|
}
|
||||||
|
|
||||||
|
final String host = StringUtils.delimitedListToStringArray(protocol.getHostname(), ".")[0].trim();
|
||||||
|
|
||||||
|
final List<String> domainElements = Arrays
|
||||||
|
.asList(StringUtils.delimitedListToStringArray(requestUri.getHost(), "."));
|
||||||
|
final String domain = StringUtils.collectionToDelimitedString(domainElements.subList(1, domainElements.size()),
|
||||||
|
".");
|
||||||
|
|
||||||
|
if (ObjectUtils.isEmpty(domain)) {
|
||||||
|
return protocol.getHostname();
|
||||||
|
}
|
||||||
|
|
||||||
|
return host + "." + domain;
|
||||||
|
}
|
||||||
|
|
||||||
private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
private String generateUrl(final UrlProtocol protocol, final URLPlaceholder placeholder,
|
||||||
final URI requestUri) {
|
final URI requestUri) {
|
||||||
final Set<Entry<String, String>> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet();
|
final Set<Entry<String, String>> entrySet = getReplaceMap(protocol, placeholder, requestUri).entrySet();
|
||||||
@@ -153,56 +201,4 @@ public class PropertyBasedArtifactUrlHandler implements ArtifactUrlHandler {
|
|||||||
return replaceMap;
|
return replaceMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getRequestPort(final UrlProtocol protocol, final URI requestUri) {
|
|
||||||
if (requestUri == null) {
|
|
||||||
return getPort(protocol);
|
|
||||||
}
|
|
||||||
// if port undefined then default protocol port is used
|
|
||||||
return requestUri.getPort() > 0 ? String.valueOf(requestUri.getPort()) : "";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getRequestHost(final UrlProtocol protocol, final URI requestUri) {
|
|
||||||
if (requestUri == null) {
|
|
||||||
return protocol.getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.ofNullable(requestUri.getHost()).orElse(protocol.getHostname());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getRequestProtocol(final UrlProtocol protocol, final URI requestUri) {
|
|
||||||
if (requestUri == null) {
|
|
||||||
return protocol.getProtocol();
|
|
||||||
}
|
|
||||||
|
|
||||||
return Optional.ofNullable(requestUri.getScheme()).orElse(protocol.getProtocol());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getPort(final UrlProtocol protocol) {
|
|
||||||
return ObjectUtils.isEmpty(protocol.getPort()) ? null : String.valueOf(protocol.getPort());
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String computeHostWithRequestDomain(final UrlProtocol protocol, final URI requestUri) {
|
|
||||||
|
|
||||||
if (requestUri == null) {
|
|
||||||
return protocol.getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!protocol.getHostname().contains(".")) {
|
|
||||||
return protocol.getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
final String host = StringUtils.delimitedListToStringArray(protocol.getHostname(), ".")[0].trim();
|
|
||||||
|
|
||||||
final List<String> domainElements = Arrays
|
|
||||||
.asList(StringUtils.delimitedListToStringArray(requestUri.getHost(), "."));
|
|
||||||
final String domain = StringUtils.collectionToDelimitedString(domainElements.subList(1, domainElements.size()),
|
|
||||||
".");
|
|
||||||
|
|
||||||
if (ObjectUtils.isEmpty(domain)) {
|
|
||||||
return protocol.getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
return host + "." + domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.api;
|
|||||||
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Container for variables available to the {@link ArtifactUrlHandler}.
|
* Container for variables available to the {@link ArtifactUrlHandler}.
|
||||||
*/
|
*/
|
||||||
@@ -28,16 +26,11 @@ public class URLPlaceholder {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant of the client
|
||||||
* of the client
|
* @param tenantId of teh tenant
|
||||||
* @param tenantId
|
* @param controllerId of the target
|
||||||
* of teh tenant
|
* @param targetId of the target
|
||||||
* @param controllerId
|
* @param softwareData information about the artifact and software module that can be
|
||||||
* of the target
|
|
||||||
* @param targetId
|
|
||||||
* of the target
|
|
||||||
* @param softwareData
|
|
||||||
* information about the artifact and software module that can be
|
|
||||||
* accessed by the URL.
|
* accessed by the URL.
|
||||||
*/
|
*/
|
||||||
public URLPlaceholder(final String tenant, final Long tenantId, final String controllerId, final Long targetId,
|
public URLPlaceholder(final String tenant, final Long tenantId, final String controllerId, final Long targetId,
|
||||||
@@ -64,14 +57,10 @@ public class URLPlaceholder {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param softwareModuleId
|
* @param softwareModuleId of the module the artifact belongs to
|
||||||
* of the module the artifact belongs to
|
* @param filename of the artifact
|
||||||
* @param filename
|
* @param artifactId of the artifact
|
||||||
* of the artifact
|
* @param sha1Hash of the artifact
|
||||||
* @param artifactId
|
|
||||||
* of the artifact
|
|
||||||
* @param sha1Hash
|
|
||||||
* of the artifact
|
|
||||||
*/
|
*/
|
||||||
public SoftwareData(final Long softwareModuleId, final String filename, final Long artifactId,
|
public SoftwareData(final Long softwareModuleId, final String filename, final Long artifactId,
|
||||||
final String sha1Hash) {
|
final String sha1Hash) {
|
||||||
|
|||||||
@@ -83,19 +83,8 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1,
|
protected static String sanitizeTenant(final String tenant) {
|
||||||
final String calculatedMd5, final String calculatedSha256) {
|
return tenant.trim().toUpperCase();
|
||||||
|
|
||||||
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 void deleteTempFile(final String tempFile) {
|
protected void deleteTempFile(final String tempFile) {
|
||||||
@@ -116,6 +105,9 @@ public abstract class AbstractArtifactRepository implements ArtifactRepository {
|
|||||||
return file.getPath();
|
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() {
|
private static File createTempFile() {
|
||||||
try {
|
try {
|
||||||
return Files.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX).toFile();
|
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);
|
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,
|
private static DigestInputStream wrapInDigestInputStream(final InputStream input, final MessageDigest mdSHA1,
|
||||||
final MessageDigest mdMD5, final MessageDigest mdSHA256) {
|
final MessageDigest mdMD5, final MessageDigest mdSHA256) {
|
||||||
return new DigestInputStream(new DigestInputStream(new DigestInputStream(input, mdSHA256), mdMD5), mdSHA1);
|
return new DigestInputStream(new DigestInputStream(new DigestInputStream(input, mdSHA256), mdMD5), mdSHA1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String sanitizeTenant(final String tenant) {
|
private AbstractDbArtifact addMissingHashes(final AbstractDbArtifact existing, final String calculatedSha1,
|
||||||
return tenant.trim().toUpperCase();
|
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,33 +19,22 @@ import org.eclipse.hawkbit.artifact.repository.model.DbArtifactHash;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ArtifactRepository service interface.
|
* ArtifactRepository service interface.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public interface ArtifactRepository {
|
public interface ArtifactRepository {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Stores an artifact into the repository.
|
* Stores an artifact into the repository.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant to store the artifact
|
||||||
* the tenant to store the artifact
|
* @param content the content to store
|
||||||
* @param content
|
* @param filename the filename of the artifact
|
||||||
* the content to store
|
* @param contentType the content type of the artifact
|
||||||
* @param filename
|
* @param hash the hashes of the artifact to do hash-checks after storing the
|
||||||
* 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}
|
* artifact, might be {@code null}
|
||||||
* @return the stored artifact
|
* @return the stored artifact
|
||||||
*
|
* @throws MethodNotSupportedException if implementation does not support the operation
|
||||||
* @throws MethodNotSupportedException
|
* @throws ArtifactStoreException in case storing of the artifact was not successful
|
||||||
* if implementation does not support the operation
|
* @throws HashNotMatchException in case {@code hash} is provided and not matching to the
|
||||||
* @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
|
* calculated hashes during storing
|
||||||
*/
|
*/
|
||||||
AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
AbstractDbArtifact store(@NotEmpty String tenant, @NotNull InputStream content, @NotEmpty String filename,
|
||||||
@@ -54,46 +43,34 @@ public interface ArtifactRepository {
|
|||||||
/**
|
/**
|
||||||
* Deletes an artifact by its SHA1 hash.
|
* Deletes an artifact by its SHA1 hash.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant to store the artifact
|
||||||
* the tenant to store the artifact
|
* @param sha1Hash the sha1-hash of the artifact to delete
|
||||||
* @param sha1Hash
|
* @throws MethodNotSupportedException if implementation does not support the operation
|
||||||
* 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);
|
void deleteBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash.
|
* Retrieves a {@link AbstractDbArtifact} from the store by its SHA1 hash.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant to store the artifact
|
||||||
* the tenant to store the artifact
|
* @param sha1Hash the sha1-hash of the file to lookup.
|
||||||
* @param sha1Hash
|
|
||||||
* the sha1-hash of the file to lookup.
|
|
||||||
* @return The artifact file object or {@code null} if no file exists.
|
* @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);
|
AbstractDbArtifact getArtifactBySha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all artifacts of given tenant.
|
* Deletes all artifacts of given tenant.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant to erase
|
||||||
* to erase
|
|
||||||
*/
|
*/
|
||||||
void deleteByTenant(@NotEmpty String tenant);
|
void deleteByTenant(@NotEmpty String tenant);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if an artifact exists for a given tenant by its sha1 hash
|
* Checks if an artifact exists for a given tenant by its sha1 hash
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant
|
||||||
* the tenant
|
* @param sha1Hash the sha1-hash of the file to lookup.
|
||||||
* @param sha1Hash
|
|
||||||
* the sha1-hash of the file to lookup.
|
|
||||||
*
|
|
||||||
* @return the boolean whether the artifact exists or not
|
* @return the boolean whether the artifact exists or not
|
||||||
*/
|
*/
|
||||||
boolean existsByTenantAndSha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
boolean existsByTenantAndSha1(@NotEmpty String tenant, @NotEmpty String sha1Hash);
|
||||||
|
|||||||
@@ -20,10 +20,8 @@ public class ArtifactStoreException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a ArtifactStoreException with message and cause.
|
* Constructs a ArtifactStoreException with message and cause.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message the message of the exception
|
||||||
* the message of the exception
|
* @param cause of the exception
|
||||||
* @param cause
|
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public ArtifactStoreException(final String message, final Throwable cause) {
|
public ArtifactStoreException(final String message, final Throwable cause) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
@@ -32,8 +30,7 @@ public class ArtifactStoreException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a ArtifactStoreException with message.
|
* Constructs a ArtifactStoreException with message.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message the message of the exception
|
||||||
* the message of the exception
|
|
||||||
*/
|
*/
|
||||||
public ArtifactStoreException(final String message) {
|
public ArtifactStoreException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
@@ -42,8 +39,7 @@ public class ArtifactStoreException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a ArtifactStoreException with cause.
|
* Constructs a ArtifactStoreException with cause.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public ArtifactStoreException(final Throwable cause) {
|
public ArtifactStoreException(final Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
|
|||||||
@@ -12,29 +12,21 @@ package org.eclipse.hawkbit.artifact.repository;
|
|||||||
/**
|
/**
|
||||||
* Thrown when provided hashes and hashes caluclated during storing are not
|
* Thrown when provided hashes and hashes caluclated during storing are not
|
||||||
* matching.
|
* matching.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class HashNotMatchException extends RuntimeException {
|
public class HashNotMatchException extends RuntimeException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
public static final String SHA1 = "SHA-1";
|
public static final String SHA1 = "SHA-1";
|
||||||
public static final String MD5 = "MD5";
|
public static final String MD5 = "MD5";
|
||||||
public static final String SHA256 = "SHA-256";
|
public static final String SHA256 = "SHA-256";
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
private final String hashFunction;
|
private final String hashFunction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a HashNotMatchException with message and cause.
|
* Constructs a HashNotMatchException with message and cause.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message the message of the exception
|
||||||
* the message of the exception
|
* @param cause the cause of the exception
|
||||||
* @param cause
|
* @param hashFunction the hash function which caused this exception
|
||||||
* 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) {
|
public HashNotMatchException(final String message, final Throwable cause, final String hashFunction) {
|
||||||
super(message, cause);
|
super(message, cause);
|
||||||
@@ -44,10 +36,8 @@ public class HashNotMatchException extends RuntimeException {
|
|||||||
/**
|
/**
|
||||||
* Constructs a HashNotMatchException with message.
|
* Constructs a HashNotMatchException with message.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message the message of the exception
|
||||||
* the message of the exception
|
* @param hashFunction the hash function which caused this exception
|
||||||
* @param hashFunction
|
|
||||||
* the hash function which caused this exception
|
|
||||||
*/
|
*/
|
||||||
public HashNotMatchException(final String message, final String hashFunction) {
|
public HashNotMatchException(final String message, final String hashFunction) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|||||||
@@ -22,8 +22,7 @@ public interface TenancyCacheManager extends CacheManager {
|
|||||||
* tenant key. This is necessary e.g. for retrieving caches not for the
|
* tenant key. This is necessary e.g. for retrieving caches not for the
|
||||||
* current tenant.
|
* current tenant.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name the name of the cache to retrieve directly
|
||||||
* the name of the cache to retrieve directly
|
|
||||||
* @return the cache associated with the name without tenancy separation
|
* @return the cache associated with the name without tenancy separation
|
||||||
*/
|
*/
|
||||||
Cache getDirectCache(String name);
|
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
|
* Evicts all caches for a given tenant. All caches under a certain tenant
|
||||||
* gets evicted.
|
* gets evicted.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant to evict caches
|
||||||
* the tenant to evict caches
|
|
||||||
*/
|
*/
|
||||||
void evictCaches(final String tenant);
|
void evictCaches(final String tenant);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,8 @@ public class TenantAwareCacheManager implements TenancyCacheManager {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* @param delegate
|
* @param delegate the {@link CacheManager} to delegate to.
|
||||||
* the {@link CacheManager} to delegate to.
|
* @param tenantAware the tenant aware to retrieve the current tenant
|
||||||
* @param tenantAware
|
|
||||||
* the tenant aware to retrieve the current tenant
|
|
||||||
*/
|
*/
|
||||||
public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) {
|
public TenantAwareCacheManager(final CacheManager delegate, final TenantAware tenantAware) {
|
||||||
this.tenantAware = tenantAware;
|
this.tenantAware = tenantAware;
|
||||||
|
|||||||
@@ -9,12 +9,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.exception;
|
package org.eclipse.hawkbit.exception;
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import java.io.Serial;
|
import java.io.Serial;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generic Custom Exception to wrap the Runtime and checked exception
|
* Generic Custom Exception to wrap the Runtime and checked exception
|
||||||
*/
|
*/
|
||||||
@@ -93,7 +93,8 @@ public abstract class AbstractServerRtException extends RuntimeException {
|
|||||||
* @param error detail
|
* @param error detail
|
||||||
* @param cause of the exception
|
* @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);
|
super(message, cause);
|
||||||
this.error = error;
|
this.error = error;
|
||||||
this.info = info;
|
this.info = info;
|
||||||
|
|||||||
@@ -13,11 +13,9 @@ package org.eclipse.hawkbit.exception;
|
|||||||
* {@link GenericSpServerException} is thrown when a given entity in's actual
|
* {@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
|
* and cannot be stored within the current session. Reason could be that it has
|
||||||
* been changed within another session.
|
* been changed within another session.
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class GenericSpServerException extends AbstractServerRtException {
|
public class GenericSpServerException extends AbstractServerRtException {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR;
|
private static final SpServerError THIS_ERROR = SpServerError.SP_REPO_GENERIC_ERROR;
|
||||||
|
|
||||||
@@ -31,8 +29,7 @@ public class GenericSpServerException extends AbstractServerRtException {
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public GenericSpServerException(final Throwable cause) {
|
public GenericSpServerException(final Throwable cause) {
|
||||||
super(THIS_ERROR, cause);
|
super(THIS_ERROR, cause);
|
||||||
@@ -41,10 +38,8 @@ public class GenericSpServerException extends AbstractServerRtException {
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message custom error message
|
||||||
* custom error message
|
* @param cause of the exception
|
||||||
* @param cause
|
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public GenericSpServerException(final String message, final Throwable cause) {
|
public GenericSpServerException(final String message, final Throwable cause) {
|
||||||
super(message, THIS_ERROR, cause);
|
super(message, THIS_ERROR, cause);
|
||||||
@@ -53,8 +48,7 @@ public class GenericSpServerException extends AbstractServerRtException {
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message custom error message
|
||||||
* custom error message
|
|
||||||
*/
|
*/
|
||||||
public GenericSpServerException(final String message) {
|
public GenericSpServerException(final String message) {
|
||||||
super(message, THIS_ERROR);
|
super(message, THIS_ERROR);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ package org.eclipse.hawkbit.exception;
|
|||||||
|
|
||||||
public enum SpServerError {
|
public enum SpServerError {
|
||||||
|
|
||||||
|
|
||||||
SP_REPO_GENERIC_ERROR("hawkbit.server.error.repo.genericError", "unknown error occurred"),
|
SP_REPO_GENERIC_ERROR("hawkbit.server.error.repo.genericError", "unknown error occurred"),
|
||||||
SP_REPO_ENTITY_ALREADY_EXISTS("hawkbit.server.error.repo.entitiyAlreayExists",
|
SP_REPO_ENTITY_ALREADY_EXISTS("hawkbit.server.error.repo.entitiyAlreayExists",
|
||||||
"The given entity already exists in database"),
|
"The given entity already exists in database"),
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort and search fields for actions.
|
* Sort and search fields for actions.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describing the fields of the DistributionSet model which can be used in the
|
* Describing the fields of the DistributionSet model which can be used in the
|
||||||
* REST API e.g. for sorting etc.
|
* REST API e.g. for sorting etc.
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describing the fields of the Tag model which can be used in the REST API e.g.
|
* Describing the fields of the Tag model which can be used in the REST API e.g.
|
||||||
* for sorting etc.
|
* for sorting etc.
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.
|
* 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 java.util.Optional;
|
||||||
|
|
||||||
import jakarta.validation.constraints.NotNull;
|
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.
|
* 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;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
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.
|
* 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) {
|
SoftwareModuleFields(final String jpaEntityFieldName, final String... subEntityAttributes) {
|
||||||
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
|
this(jpaEntityFieldName, List.of(subEntityAttributes), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
SoftwareModuleFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
|
SoftwareModuleFields(final String jpaEntityFieldName, final Entry<String, String> subEntityMapTuple) {
|
||||||
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
|
this(jpaEntityFieldName, Collections.emptyList(), subEntityMapTuple);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,14 +9,14 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.AbstractMap.SimpleImmutableEntry;
|
import java.util.AbstractMap.SimpleImmutableEntry;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describing the fields of the Target model which can be used in the REST API
|
* Describing the fields of the Target model which can be used in the REST API
|
||||||
* e.g. for sorting etc.
|
* e.g. for sorting etc.
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
package org.eclipse.hawkbit.repository;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.
|
* Describing the fields of the Target model which can be used in the REST API e.g. for sorting etc.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -34,10 +34,8 @@ public interface TenantAware {
|
|||||||
* {@link TenantRunner} it must be ensured that the original tenant before
|
* {@link TenantRunner} it must be ensured that the original tenant before
|
||||||
* this invocation is reset.
|
* this invocation is reset.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant which the specific code should run
|
||||||
* the tenant which the specific code should run
|
* @param tenantRunner the runner which is implemented to run this specific code
|
||||||
* @param tenantRunner
|
|
||||||
* the runner which is implemented to run this specific code
|
|
||||||
* under the given tenant
|
* under the given tenant
|
||||||
* @return the return type of the {@link TenantRunner}
|
* @return the return type of the {@link TenantRunner}
|
||||||
*/
|
*/
|
||||||
@@ -50,12 +48,9 @@ public interface TenantAware {
|
|||||||
* {@link TenantRunner} it must be ensured that the original tenant before
|
* {@link TenantRunner} it must be ensured that the original tenant before
|
||||||
* this invocation is reset.
|
* this invocation is reset.
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant the tenant which the specific code should run with
|
||||||
* the tenant which the specific code should run with
|
* @param username the username which the specific code should run with
|
||||||
* @param username
|
* @param tenantRunner the runner which is implemented to run this specific code
|
||||||
* 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
|
* under the given tenant
|
||||||
* @return the return type of the {@link TenantRunner}
|
* @return the return type of the {@link TenantRunner}
|
||||||
*/
|
*/
|
||||||
@@ -66,14 +61,11 @@ public interface TenantAware {
|
|||||||
* a given tenant by using the
|
* a given tenant by using the
|
||||||
* {@link TenantAware#runAsTenant(String, TenantRunner)}.
|
* {@link TenantAware#runAsTenant(String, TenantRunner)}.
|
||||||
*
|
*
|
||||||
*
|
* @param <T> the return type of the runner
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* the return type of the runner
|
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface TenantRunner<T> {
|
interface TenantRunner<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called to run specific code and a given tenant.
|
* 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
|
* User authorities/roles lookup based on the tenant and the username
|
||||||
*
|
*
|
||||||
* @param tenant
|
* @param tenant The tenant that this user belongs to
|
||||||
* The tenant that this user belongs to
|
* @param username The username of the user
|
||||||
* @param username
|
|
||||||
* The username of the user
|
|
||||||
* @return a {@link Collection} of authorities/roles for this user
|
* @return a {@link Collection} of authorities/roles for this user
|
||||||
*/
|
*/
|
||||||
Collection<String> getUserAuthorities(String tenant, String username);
|
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
|
* The {@link #InvalidTenantConfigurationKeyException} is thrown when an invalid
|
||||||
* configuration key is used.
|
* configuration key is used.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class InvalidTenantConfigurationKeyException extends AbstractServerRtException {
|
public class InvalidTenantConfigurationKeyException extends AbstractServerRtException {
|
||||||
|
|
||||||
@@ -32,8 +31,7 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public InvalidTenantConfigurationKeyException(final Throwable cause) {
|
public InvalidTenantConfigurationKeyException(final Throwable cause) {
|
||||||
super(THIS_ERROR, cause);
|
super(THIS_ERROR, cause);
|
||||||
@@ -42,10 +40,8 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the exception
|
||||||
* of the exception
|
* @param cause of the exception
|
||||||
* @param cause
|
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public InvalidTenantConfigurationKeyException(final String message, final Throwable cause) {
|
public InvalidTenantConfigurationKeyException(final String message, final Throwable cause) {
|
||||||
super(message, THIS_ERROR, cause);
|
super(message, THIS_ERROR, cause);
|
||||||
@@ -54,8 +50,7 @@ public class InvalidTenantConfigurationKeyException extends AbstractServerRtExce
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public InvalidTenantConfigurationKeyException(final String message) {
|
public InvalidTenantConfigurationKeyException(final String message) {
|
||||||
super(message, THIS_ERROR);
|
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
|
* Exception which is thrown, when the validation of the configuration value has
|
||||||
* not been successful.
|
* not been successful.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class TenantConfigurationValidatorException extends AbstractServerRtException {
|
public class TenantConfigurationValidatorException extends AbstractServerRtException {
|
||||||
|
|
||||||
@@ -32,8 +31,7 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param cause
|
* @param cause of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public TenantConfigurationValidatorException(final Throwable cause) {
|
public TenantConfigurationValidatorException(final Throwable cause) {
|
||||||
super(THIS_ERROR, cause);
|
super(THIS_ERROR, cause);
|
||||||
@@ -42,10 +40,8 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the exception
|
||||||
* of the exception
|
* @param cause of the exception
|
||||||
* @param cause
|
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public TenantConfigurationValidatorException(final String message, final Throwable cause) {
|
public TenantConfigurationValidatorException(final String message, final Throwable cause) {
|
||||||
super(message, THIS_ERROR, cause);
|
super(message, THIS_ERROR, cause);
|
||||||
@@ -54,8 +50,7 @@ public class TenantConfigurationValidatorException extends AbstractServerRtExcep
|
|||||||
/**
|
/**
|
||||||
* Parameterized constructor.
|
* Parameterized constructor.
|
||||||
*
|
*
|
||||||
* @param message
|
* @param message of the exception
|
||||||
* of the exception
|
|
||||||
*/
|
*/
|
||||||
public TenantConfigurationValidatorException(final String message) {
|
public TenantConfigurationValidatorException(final String message) {
|
||||||
super(message, THIS_ERROR);
|
super(message, THIS_ERROR);
|
||||||
|
|||||||
@@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@Feature("Unit Tests - Artifact URL Handler")
|
@Feature("Unit Tests - Artifact URL Handler")
|
||||||
@Story("Base62 Utility tests")
|
@Story("Base62 Utility tests")
|
||||||
|
|||||||
@@ -13,18 +13,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
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.ArtifactUrlHandlerProperties.UrlProtocol;
|
||||||
import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData;
|
import org.eclipse.hawkbit.api.URLPlaceholder.SoftwareData;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
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;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -51,13 +49,10 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|||||||
private static final String TENANT = "TEST_TENANT";
|
private static final String TENANT = "TEST_TENANT";
|
||||||
|
|
||||||
private static final String HTTP_LOCALHOST = "http://localhost:8080/";
|
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,
|
private static URLPlaceholder placeholder = new URLPlaceholder(TENANT, TENANT_ID, CONTROLLER_ID, TARGETID,
|
||||||
new SoftwareData(SOFTWAREMODULEID, FILENAME_DECODE, ARTIFACTID, SHA1HASH));
|
new SoftwareData(SOFTWAREMODULEID, FILENAME_DECODE, ARTIFACTID, SHA1HASH));
|
||||||
|
private ArtifactUrlHandler urlHandlerUnderTest;
|
||||||
|
private ArtifactUrlHandlerProperties properties;
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setup() {
|
public void setup() {
|
||||||
@@ -142,6 +137,7 @@ public class PropertyBasedArtifactUrlHandlerTest {
|
|||||||
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + "://"
|
assertThat(urls).containsExactly(new ArtifactUrl(TEST_PROTO.toUpperCase(), TEST_REL, TEST_PROTO + "://"
|
||||||
+ testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
+ testHost + ":5683/fws/" + TENANT + "/" + TARGETID_BASE62 + "/" + ARTIFACTID_BASE62));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Description("Verfies that the protocol of the statically defined hostname is replaced with the protocol of the request.")
|
@Description("Verfies that the protocol of the statically defined hostname is replaced with the protocol of the request.")
|
||||||
public void urlGenerationWithProtocolFromRequest() throws URISyntaxException {
|
public void urlGenerationWithProtocolFromRequest() throws URISyntaxException {
|
||||||
|
|||||||
@@ -11,11 +11,10 @@ package org.eclipse.hawkbit.api;
|
|||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import io.qameta.allure.Feature;
|
import io.qameta.allure.Feature;
|
||||||
import io.qameta.allure.Story;
|
import io.qameta.allure.Story;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
@Feature("Unit Tests - Artifact URL Handler")
|
@Feature("Unit Tests - Artifact URL Handler")
|
||||||
@Story("URL placeholder tests")
|
@Story("URL placeholder tests")
|
||||||
|
|||||||
@@ -9,16 +9,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.eclipse.hawkbit.repository;
|
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.ClassGraph;
|
||||||
import io.github.classgraph.ClassInfo;
|
import io.github.classgraph.ClassInfo;
|
||||||
import io.github.classgraph.ScanResult;
|
import io.github.classgraph.ScanResult;
|
||||||
import io.qameta.allure.Description;
|
import io.qameta.allure.Description;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
|
|
||||||
public class FileNameFieldsTest {
|
public class FileNameFieldsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user