Code format hawkbit (#1948)
Signed-off-by: Marinov Avgustin <Avgustin.Marinov@bosch.com>
This commit is contained in:
@@ -11,8 +11,6 @@ package org.eclipse.hawkbit.sdk;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.ToString;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.lang.NonNull;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
|
||||
@@ -9,6 +9,11 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.sdk;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
import feign.Client;
|
||||
import feign.Contract;
|
||||
import feign.Feign;
|
||||
@@ -20,49 +25,42 @@ import lombok.Builder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.Objects;
|
||||
import java.util.function.BiFunction;
|
||||
|
||||
@Slf4j
|
||||
@Builder
|
||||
public class HawkbitClient {
|
||||
|
||||
private static final String AUTHORIZATION = "Authorization";
|
||||
private static final ErrorDecoder DEFAULT_ERROR_DECODER_0 = new ErrorDecoder.Default();
|
||||
public static final BiFunction<Tenant, Controller, RequestInterceptor> DEFAULT_REQUEST_INTERCEPTOR_FN =
|
||||
(tenant, controller) ->
|
||||
controller == null ?
|
||||
template -> {
|
||||
template.header(
|
||||
AUTHORIZATION,
|
||||
|
||||
"Basic " +
|
||||
Base64.getEncoder()
|
||||
.encodeToString(
|
||||
(Objects.requireNonNull(tenant.getUsername(), "User is null!") +
|
||||
":" +
|
||||
Objects.requireNonNull(tenant.getPassword(),
|
||||
"Password is not available!"))
|
||||
.getBytes(StandardCharsets.ISO_8859_1)));
|
||||
} :
|
||||
template -> {
|
||||
if (ObjectUtils.isEmpty(tenant.getGatewayToken())) {
|
||||
if (!ObjectUtils.isEmpty(controller.getSecurityToken())) {
|
||||
template.header(AUTHORIZATION, "TargetToken " + controller.getSecurityToken());
|
||||
} // else do not sent authentication
|
||||
} else {
|
||||
template.header(AUTHORIZATION, "GatewayToken " + tenant.getGatewayToken());
|
||||
}
|
||||
};
|
||||
private static final ErrorDecoder DEFAULT_ERROR_DECODER_0 = new ErrorDecoder.Default();
|
||||
public static final ErrorDecoder DEFAULT_ERROR_DECODER = (methodKey, response) -> {
|
||||
final Exception e = DEFAULT_ERROR_DECODER_0.decode(methodKey, response);
|
||||
log.trace("REST API call failed!", e);
|
||||
return e;
|
||||
};
|
||||
|
||||
public static final BiFunction<Tenant, Controller, RequestInterceptor> DEFAULT_REQUEST_INTERCEPTOR_FN =
|
||||
(tenant, controller) ->
|
||||
controller == null ?
|
||||
template -> {
|
||||
template.header(
|
||||
AUTHORIZATION,
|
||||
|
||||
"Basic " +
|
||||
Base64.getEncoder()
|
||||
.encodeToString(
|
||||
(Objects.requireNonNull(tenant.getUsername(), "User is null!") +
|
||||
":" +
|
||||
Objects.requireNonNull(tenant.getPassword(),"Password is not available!"))
|
||||
.getBytes(StandardCharsets.ISO_8859_1)));
|
||||
} :
|
||||
template -> {
|
||||
if (ObjectUtils.isEmpty(tenant.getGatewayToken())) {
|
||||
if (!ObjectUtils.isEmpty(controller.getSecurityToken())) {
|
||||
template.header(AUTHORIZATION, "TargetToken " + controller.getSecurityToken());
|
||||
} // else do not sent authentication
|
||||
} else {
|
||||
template.header(AUTHORIZATION, "GatewayToken " + tenant.getGatewayToken());
|
||||
}
|
||||
};
|
||||
|
||||
private final HawkbitServer hawkBitServerProperties;
|
||||
|
||||
private final Client client;
|
||||
@@ -100,6 +98,7 @@ public class HawkbitClient {
|
||||
public <T> T mgmtService(final Class<T> serviceType, final Tenant tenantProperties) {
|
||||
return service(serviceType, tenantProperties, null);
|
||||
}
|
||||
|
||||
public <T> T ddiService(final Class<T> serviceType, final Tenant tenantProperties, final Controller controller) {
|
||||
return service(serviceType, tenantProperties, controller);
|
||||
}
|
||||
@@ -113,7 +112,7 @@ public class HawkbitClient {
|
||||
.requestInterceptor(requestInterceptorFn.apply(tenant, controller))
|
||||
.target(serviceType,
|
||||
controller == null ?
|
||||
hawkBitServerProperties.getMgmtUrl() :
|
||||
hawkBitServerProperties.getDdiUrl());
|
||||
hawkBitServerProperties.getMgmtUrl() :
|
||||
hawkBitServerProperties.getDdiUrl());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,10 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.sdk;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
import feign.Contract;
|
||||
import feign.MethodMetadata;
|
||||
import feign.RequestInterceptor;
|
||||
@@ -30,13 +34,9 @@ import org.springframework.hateoas.config.EnableHypermediaSupport;
|
||||
import org.springframework.hateoas.config.WebConverters;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
@Slf4j
|
||||
@Configuration
|
||||
@EnableConfigurationProperties({ HawkbitServer.class, Tenant.class})
|
||||
@EnableConfigurationProperties({ HawkbitServer.class, Tenant.class })
|
||||
@EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL)
|
||||
@Import(FeignClientsConfiguration.class)
|
||||
@PropertySource("classpath:/hawkbit-sdk-defaults.properties")
|
||||
@@ -62,7 +62,7 @@ public class HawkbitSDKConfigurtion {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
@ConditionalOnNotWebApplication
|
||||
@ConditionalOnClass({ WebConverters.class})
|
||||
@ConditionalOnClass({ WebConverters.class })
|
||||
public HttpMessageConverterCustomizer webConvertersCustomizerOverrider(WebConverters webConverters) {
|
||||
return new WebConvertersCustomizer(webConverters);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
@ConfigurationProperties(prefix="hawkbit.server")
|
||||
@ConfigurationProperties(prefix = "hawkbit.server")
|
||||
@Data
|
||||
public class HawkbitServer {
|
||||
|
||||
|
||||
@@ -25,11 +25,8 @@ public interface ArtifactHandler {
|
||||
|
||||
interface DownloadHandler {
|
||||
|
||||
enum Status {
|
||||
SUCCESS, ERROR
|
||||
}
|
||||
|
||||
DownloadHandler SKIP = new DownloadHandler() {
|
||||
|
||||
@Override
|
||||
public void read(byte[] buff, int off, int len) {
|
||||
// skip
|
||||
@@ -69,5 +66,9 @@ public interface ArtifactHandler {
|
||||
* @return the path to the download
|
||||
*/
|
||||
Optional<Path> download();
|
||||
|
||||
enum Status {
|
||||
SUCCESS, ERROR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user