First implemtation of REST-API
Signed-off-by: Nonnenmacher Fabian <fabian.nonnenmacher@bosch-si.com>
This commit is contained in:
committed by
Nonnenmacher Fabian
parent
088df73ea9
commit
f3fa085c62
@@ -18,9 +18,9 @@ import org.eclipse.hawkbit.report.model.SystemUsageReport;
|
||||
import org.eclipse.hawkbit.report.model.TenantUsage;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.TenantConfiguration;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.AuthenticationConfigurationRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.CacheRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemStatisticsRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.TenantConfigurationRest;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.TenantSystemUsageRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -141,7 +141,7 @@ public class SystemManagementResource {
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/conf/{key}")
|
||||
@PreAuthorize(SpringEvalExpressions.HAS_AUTH_SYSTEM_ADMIN)
|
||||
public ResponseEntity<Void> addUpdateConfig(@RequestBody final TenantConfigurationRest configuration,
|
||||
public ResponseEntity<Void> addUpdateConfig(@RequestBody final AuthenticationConfigurationRest configuration,
|
||||
@PathVariable final String key) {
|
||||
systemManagement.addOrUpdateConfiguration(new TenantConfiguration(key, configuration.getValue()));
|
||||
return ResponseEntity.ok().build();
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.repository.model.TenantMetaData;
|
||||
import org.eclipse.hawkbit.repository.model.helper.DurationHelper;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
|
||||
import org.eclipse.hawkbit.tenancy.configuration.TenantConfigurationKey;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
final public class SystemMapper {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(SystemMapper.class);
|
||||
|
||||
private SystemMapper() {
|
||||
// Utility class
|
||||
}
|
||||
|
||||
private static DurationHelper dh = new DurationHelper();
|
||||
|
||||
public static SystemConfigurationRest toResponse(SystemManagement systemManagement) {
|
||||
|
||||
TenantMetaData tenantMetaData = systemManagement.getTenantMetadata();
|
||||
|
||||
SystemConfigurationRest sysconf = new SystemConfigurationRest();
|
||||
|
||||
sysconf.setDefaultDistributionSetType(tenantMetaData.getDefaultDsType().getKey());
|
||||
sysconf.setCreatedAt(tenantMetaData.getCreatedAt());
|
||||
sysconf.setCreatedBy(tenantMetaData.getCreatedBy());
|
||||
sysconf.setLastModifiedAt(tenantMetaData.getLastModifiedAt());
|
||||
sysconf.setLastModifiedBy(tenantMetaData.getLastModifiedBy());
|
||||
|
||||
sysconf.setPollingOverdueTime(dh.durationToFormattedString(tenantMetaData.getPollingOverdueTime()));
|
||||
sysconf.setPollingTime(dh.durationToFormattedString(tenantMetaData.getPollingTime()));
|
||||
|
||||
Map<String, Object> authconf = new HashMap<String, Object>();
|
||||
|
||||
for (TenantConfigurationKey key : TenantConfigurationKey.values()) {
|
||||
Object value;
|
||||
|
||||
switch (key) {
|
||||
case AUTHENTICATION_MODE_HEADER_ENABLED:
|
||||
case AUTHENTICATION_MODE_TARGET_SECURITY_TOKEN_ENABLED:
|
||||
case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_ENABLED:
|
||||
value = systemManagement.getConfigurationValue(key, Boolean.class);
|
||||
break;
|
||||
case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_NAME:
|
||||
case AUTHENTICATION_MODE_GATEWAY_SECURITY_TOKEN_KEY:
|
||||
case AUTHENTICATION_MODE_HEADER_AUTHORITY_NAME:
|
||||
value = systemManagement.getConfigurationValue(key, String.class);
|
||||
break;
|
||||
default:
|
||||
LOG.warn("There is no data type specified for TenantConfigurationKey {}.", key.getKeyName());
|
||||
value = systemManagement.getConfigurationValue(key, String.class);
|
||||
}
|
||||
authconf.put(key.getKeyName(), value);
|
||||
}
|
||||
|
||||
sysconf.setAuthenticationConfiguration(authconf);
|
||||
|
||||
return sysconf;
|
||||
}
|
||||
|
||||
public static TenantMetaData fromRequest(SystemManagement systemManagement,
|
||||
SystemConfigurationRequestBodyPut systemConReq, DistributionSetManagement distributionSetManagement) {
|
||||
|
||||
TenantMetaData tenantMetaData = systemManagement.getTenantMetadata();
|
||||
|
||||
String ddstypeKey = systemConReq.getDefaultDistributionSetType();
|
||||
|
||||
if (distributionSetManagement.findDistributionSetTypeByKey(ddstypeKey) == null) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("The specified default distribution set type %s doe not exist.", ddstypeKey));
|
||||
}
|
||||
|
||||
tenantMetaData.setPollingOverdueTime(dh.formattedStringToDuration(systemConReq.getPollingOverdueTime()));
|
||||
tenantMetaData.setPollingTime(dh.formattedStringToDuration(systemConReq.getPollingTime()));
|
||||
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package org.eclipse.hawkbit.rest.resource;
|
||||
|
||||
import org.eclipse.hawkbit.repository.DistributionSetManagement;
|
||||
import org.eclipse.hawkbit.repository.SystemManagement;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRequestBodyPut;
|
||||
import org.eclipse.hawkbit.rest.resource.model.system.SystemConfigurationRest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(RestConstants.SYSTEM_V1_REQUEST_MAPPING)
|
||||
public class SystemResource {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(SystemResource.class);
|
||||
|
||||
@Autowired
|
||||
private SystemManagement systemManagement;
|
||||
|
||||
@Autowired
|
||||
private DistributionSetManagement distributionSetManagement;
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET, value = "/conf", produces = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SystemConfigurationRest> getSystemConfiguration() {
|
||||
|
||||
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.PUT, value = "/conf", consumes = { "application/hal+json",
|
||||
MediaType.APPLICATION_JSON_VALUE }, produces = { "application/hal+json", MediaType.APPLICATION_JSON_VALUE })
|
||||
public ResponseEntity<SystemConfigurationRest> updateSoftwareModuleType(
|
||||
@RequestBody final SystemConfigurationRequestBodyPut systemConReq) {
|
||||
|
||||
systemManagement.updateTenantConfiguration(systemConReq);
|
||||
|
||||
return new ResponseEntity<>(SystemMapper.toResponse(systemManagement), HttpStatus.OK);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user