From bdae785bf6861d72e9f9e3cf1abf8f2de051216c Mon Sep 17 00:00:00 2001 From: Aissam EN-NAHEL <121689923+aissam-en@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:04:52 +0100 Subject: [PATCH 1/3] Add policy creation --- rest-to-websocket/README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rest-to-websocket/README.md b/rest-to-websocket/README.md index b74e87e4..4dc67b8e 100644 --- a/rest-to-websocket/README.md +++ b/rest-to-websocket/README.md @@ -42,6 +42,39 @@ All we need for this example is a running Eclipse Ditto instance. Please follow the guidelines at the [Eclipse Ditto](https://eclipse.dev/ditto/installation-running.html) project to get started. +Additionally, you should create a policy `org.eclipse.ditto:smartcoffee`, example of creating a policy: +```sh +curl --request PUT \ + --url http://localhost:8080/api/2/policies/org.eclipse.ditto:smartcoffee \ + --header 'Content-Type: application/json' \ + --header 'Authorization: Basic ZGl0dG86ZGl0dG8=' \ + --data '{ + "entries": { + "owner": { + "subjects": { + "nginx:ditto": { + "type": "admin aissam" + } + }, + "resources": { + "thing:/": { + "grant": ["READ", "WRITE"], + "revoke": [] + }, + "policy:/": { + "grant": ["READ", "WRITE"], + "revoke": [] + }, + "message:/": { + "grant": ["READ", "WRITE"], + "revoke": [] + } + } + } + } +}' +``` + To use the UI, you can simply open `index.html` in your favorite (hopefully state-of-the-art :wink:) browser. From 8b2f37ad6736c8f59980c92f176f3f538376475b Mon Sep 17 00:00:00 2001 From: Aissam EN-NAHEL <121689923+aissam-en@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:30:23 +0100 Subject: [PATCH 2/3] updated from v1 to v2 --- rest-to-websocket/FrontendApp.js | 2 +- rest-to-websocket/SmartCoffeeApp.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rest-to-websocket/FrontendApp.js b/rest-to-websocket/FrontendApp.js index a3c6e4d0..c8b15e11 100644 --- a/rest-to-websocket/FrontendApp.js +++ b/rest-to-websocket/FrontendApp.js @@ -33,7 +33,7 @@ class FrontendApp { const thingId = this.config.thingId; const connectionConfig = this.connectionConfigFunction(); - this.baseUrl = `http://${connectionConfig.getHost()}/api/1/things/${thingId}`; + this.baseUrl = `http://${connectionConfig.getHost()}/api/2/things/${thingId}`; // updated from v1 to v2 const basicAuth = btoa(`${connectionConfig.getUsername()}:${connectionConfig.getPassword()}`); $.ajaxSetup({ diff --git a/rest-to-websocket/SmartCoffeeApp.js b/rest-to-websocket/SmartCoffeeApp.js index ed9499a3..32c8a5d3 100644 --- a/rest-to-websocket/SmartCoffeeApp.js +++ b/rest-to-websocket/SmartCoffeeApp.js @@ -312,7 +312,7 @@ class DittoWebSocket { } connect(connectionConfig, callback) { - const baseUrl = `ws://${connectionConfig.getUsername()}:${connectionConfig.getPassword()}@${connectionConfig.getHost()}/ws/1`; + const baseUrl = `ws://${connectionConfig.getUsername()}:${connectionConfig.getPassword()}@${connectionConfig.getHost()}/ws/2`; // updated from v1 to v2 this.ws = new WebSocket(baseUrl); this.ws.onopen = () => this.onOpen(callback); } From 80ff11c48d0e071bc7cbc928a36ba6d658e79fe4 Mon Sep 17 00:00:00 2001 From: Aissam EN-NAHEL <121689923+aissam-en@users.noreply.github.com> Date: Thu, 4 Jul 2024 11:32:20 +0100 Subject: [PATCH 3/3] add policy creation instructions --- rest-to-websocket/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-to-websocket/README.md b/rest-to-websocket/README.md index 4dc67b8e..fafa4f7f 100644 --- a/rest-to-websocket/README.md +++ b/rest-to-websocket/README.md @@ -42,7 +42,7 @@ All we need for this example is a running Eclipse Ditto instance. Please follow the guidelines at the [Eclipse Ditto](https://eclipse.dev/ditto/installation-running.html) project to get started. -Additionally, you should create a policy `org.eclipse.ditto:smartcoffee`, example of creating a policy: +Additionally, you should create the policy `org.eclipse.ditto:smartcoffee` (if it does not exist), example of creating a policy: ```sh curl --request PUT \ --url http://localhost:8080/api/2/policies/org.eclipse.ditto:smartcoffee \