- extend simulator rest-api for simulating also DDI devices
- adapt readme.md to document new simulator rest-api - remove basic-auth from standard application properties and introduce an extra cloud-profile which includes basic-auth-security parameters for easier use locally - fix dialog for amount with 4 digit and comma charachter Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
@@ -8,9 +8,13 @@
|
||||
*/
|
||||
package org.eclipse.hawkbit.simulator;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.eclipse.hawkbit.simulator.AbstractSimulatedDevice.Protocol;
|
||||
import org.eclipse.hawkbit.simulator.amqp.SpSenderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -43,18 +47,37 @@ public class SimulationController {
|
||||
* @param tenant
|
||||
* the tenant to create the device to
|
||||
* @return a response string that devices has been created
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
@RequestMapping("/start")
|
||||
String start(@RequestParam(value = "name", defaultValue = "dmfSimulated") final String name,
|
||||
ResponseEntity<String> start(@RequestParam(value = "name", defaultValue = "simulated") final String name,
|
||||
@RequestParam(value = "amount", defaultValue = "20") final int amount,
|
||||
@RequestParam(value = "tenant", defaultValue = "DEFAULT") final String tenant) {
|
||||
@RequestParam(value = "tenant", defaultValue = "DEFAULT") final String tenant,
|
||||
@RequestParam(value = "api", defaultValue = "dmf") final String api,
|
||||
@RequestParam(value = "endpoint", defaultValue = "http://localhost:8080") final String endpoint,
|
||||
@RequestParam(value = "polldelay", defaultValue = "30") final int pollDelay,
|
||||
@RequestParam(value = "gatewaytoken", defaultValue = "") final String gatewayToken)
|
||||
throws MalformedURLException {
|
||||
|
||||
final Protocol protocol;
|
||||
switch (api.toLowerCase()) {
|
||||
case "dmf":
|
||||
protocol = Protocol.DMF_AMQP;
|
||||
break;
|
||||
case "ddi":
|
||||
protocol = Protocol.DDI_HTTP;
|
||||
break;
|
||||
default:
|
||||
return ResponseEntity.badRequest().body("query param api only allows value of 'dmf' or 'ddi'");
|
||||
}
|
||||
|
||||
for (int i = 0; i < amount; i++) {
|
||||
final String deviceId = name + i;
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, tenant, Protocol.DMF_AMQP));
|
||||
repository.add(deviceFactory.createSimulatedDevice(deviceId, tenant, protocol, pollDelay, new URL(endpoint),
|
||||
gatewayToken));
|
||||
spSenderService.createOrUpdateThing(tenant, deviceId);
|
||||
}
|
||||
|
||||
return "Updated " + amount + " DMF connected targets!";
|
||||
return ResponseEntity.ok("Updated " + amount + " DMF connected targets!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,8 +83,8 @@ public class GenerateDialog extends Window {
|
||||
tf5.setIcon(FontAwesome.FLAG_O);
|
||||
tf5.setRequired(true);
|
||||
tf5.setVisible(false);
|
||||
tf5.addValidator(new RegexpValidator(
|
||||
"^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]", "is not an URL"));
|
||||
tf5.addValidator(new RegexpValidator("^(https?|ftp|file)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]",
|
||||
"is not an URL"));
|
||||
|
||||
final TextField tf6 = new TextField("gateway token", "");
|
||||
tf6.setColumns(50);
|
||||
@@ -125,7 +125,8 @@ public class GenerateDialog extends Window {
|
||||
@Override
|
||||
public void buttonClick(final ClickEvent event) {
|
||||
try {
|
||||
callback.okButton(tf1.getValue(), tf3.getValue(), Integer.valueOf(tf2.getValue().replace(".", "")),
|
||||
callback.okButton(tf1.getValue(), tf3.getValue(),
|
||||
Integer.valueOf(tf2.getValue().replace(".", "").replace(",", "")),
|
||||
Integer.valueOf(tf4.getValue().replace(".", "")), new URL(tf5.getValue()), tf6.getValue(),
|
||||
(Protocol) protocolGroup.getValue());
|
||||
} catch (final NumberFormatException e) {
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# SECURITY (SecurityProperties)
|
||||
security.basic.enabled=true
|
||||
security.user.name=${BASIC_USERNAME:admin}
|
||||
security.user.password=${BASIC_PASSWORD:admin}
|
||||
security.user.role=USER
|
||||
security.require-ssl=false
|
||||
security.enable-csrf=false
|
||||
security.basic.enabled=true
|
||||
security.basic.realm=DeviceSimulator
|
||||
security.basic.path= /**
|
||||
security.basic.authorize-mode=ROLE
|
||||
security.filter-order=0
|
||||
security.headers.xss=false
|
||||
security.headers.cache=false
|
||||
security.headers.frame=false
|
||||
security.headers.content-type=false
|
||||
security.headers.hsts=all
|
||||
security.sessions=stateless
|
||||
security.ignored=/VAADIN/**
|
||||
@@ -27,23 +27,5 @@ spring.rabbitmq.port=5672
|
||||
spring.rabbitmq.dynamic=true
|
||||
spring.rabbitmq.listener.prefetch=100
|
||||
|
||||
# SECURITY (SecurityProperties)
|
||||
security.user.name=${BASIC_USERNAME:admin}
|
||||
security.user.password=${BASIC_PASSWORD:admin}
|
||||
security.user.role=USER
|
||||
security.require-ssl=false
|
||||
security.enable-csrf=false
|
||||
security.basic.enabled=true
|
||||
security.basic.realm=DeviceSimulator
|
||||
security.basic.path= /**
|
||||
security.basic.authorize-mode=ROLE
|
||||
security.filter-order=0
|
||||
security.headers.xss=false
|
||||
security.headers.cache=false
|
||||
security.headers.frame=false
|
||||
security.headers.content-type=false
|
||||
security.headers.hsts=all
|
||||
security.sessions=stateless
|
||||
security.ignored=/VAADIN/**
|
||||
|
||||
security.basic.enabled=false
|
||||
server.port=8083
|
||||
|
||||
Reference in New Issue
Block a user