|
| 1 | +## set: Write data |
| 2 | + |
| 3 | +KUKSA.val supports basic set requests according to VISS validated against the [following schema](https://github.com/eclipse/kuksa.val/blob/master/include/VSSRequestJsonSchema.hpp#L48-L71): |
| 4 | + |
| 5 | + |
| 6 | +```json |
| 7 | +{ |
| 8 | + "$schema": "http://json-schema.org/draft-04/schema#", |
| 9 | + "title": "Set Request", |
| 10 | + "description": "Enables the client to set one or more values once.", |
| 11 | + "type": "object", |
| 12 | + "required": ["action", "path", "value", "requestId"], |
| 13 | + "properties": { |
| 14 | + "action": { |
| 15 | + "enum": [ "set" ], |
| 16 | + "description": "The identifier for the set request" |
| 17 | + }, |
| 18 | + "path": { |
| 19 | + "$ref": "viss#/definitions/path" |
| 20 | + }, |
| 21 | + "value": { |
| 22 | + "$ref": "viss#/definitions/value" |
| 23 | + }, |
| 24 | + "requestId": { |
| 25 | + "$ref": "viss#/definitions/requestId" |
| 26 | + } |
| 27 | + } |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +The following shows some valid and invalid sample requests. Unless otherwise noticed, we assume you are authorised to read the paths used in the examples. |
| 32 | + |
| 33 | +### VSS1-Path Example Request |
| 34 | + |
| 35 | +KUKSA.val supports VISS1 (dot-seperated) and VISS2 (slash-seperated) paths. VISS1 example: |
| 36 | + |
| 37 | +```json |
| 38 | +{ |
| 39 | + "action": "set", |
| 40 | + "path": "Vehicle.Speed", |
| 41 | + "value": "200", |
| 42 | + "requestId": "4204a97e-d25e-4ba9-891b-1703145865bd" |
| 43 | +} |
| 44 | +``` |
| 45 | + |
| 46 | +### Response |
| 47 | + |
| 48 | +```json |
| 49 | +{ |
| 50 | + "action": "set", |
| 51 | + "requestId": "4204a97e-d25e-4ba9-891b-1703145865bd", |
| 52 | + "timestamp": 1615832573528 |
| 53 | +} |
| 54 | +``` |
| 55 | + |
| 56 | +### VISS2-Path Example Request |
| 57 | + |
| 58 | +```json |
| 59 | +{ |
| 60 | + "action": "set", |
| 61 | + "path": "Vehicle/Speed", |
| 62 | + "value": "200", |
| 63 | + "requestId": "8cedc7c8-089d-48d6-b913-9f1504c14342" |
| 64 | +} |
| 65 | +``` |
| 66 | + |
| 67 | +### Response |
| 68 | + |
| 69 | +```json |
| 70 | +{ |
| 71 | + "action": "set", |
| 72 | + "requestId": "8cedc7c8-089d-48d6-b913-9f1504c14342", |
| 73 | + "timestamp": 1615832646622 |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## Wildcards/Multisets |
| 78 | + |
| 79 | +Setting wildcards/multiple values or branches is currently not supported |
| 80 | + |
| 81 | +### Try setting branch |
| 82 | + |
| 83 | +```json |
| 84 | +{ |
| 85 | + "action": "set", |
| 86 | + "path": "Vehicle", |
| 87 | + "value": "200", |
| 88 | + "requestId": "3ef9e4c1-ff99-4b2c-be13-ce69bfb170b0" |
| 89 | +} |
| 90 | +``` |
| 91 | + |
| 92 | +### Response |
| 93 | + |
| 94 | +```json |
| 95 | +{ |
| 96 | + "action": "set", |
| 97 | + "error": { |
| 98 | + "message": "Can not set Vehicle. Only sensor or actor leaves can be set.", |
| 99 | + "number": 403, |
| 100 | + "reason": "Forbidden" |
| 101 | + }, |
| 102 | + "requestId": "3ef9e4c1-ff99-4b2c-be13-ce69bfb170b0", |
| 103 | + "timestamp": 1615832783387 |
| 104 | +} |
| 105 | +``` |
| 106 | + |
| 107 | +### Try setting attribute |
| 108 | +Attributes are considered a deployment attribute that does not change during the lifetime of a vehicle, therefore they can not be set using normal means. KUKSA.val assumes them to be initialized correctly by the loaded VSS JSON. |
| 109 | + |
| 110 | +```json |
| 111 | +{ |
| 112 | + "action": "set", |
| 113 | + "path": "Vehicle/VehicleIdentification/VIN", |
| 114 | + "value": "deadbeef", |
| 115 | + "requestId": "4544fd5f-249e-4da6-8576-248b42504394" |
| 116 | +} |
| 117 | +``` |
| 118 | + |
| 119 | +### Response |
| 120 | + |
| 121 | +```json |
| 122 | +{ |
| 123 | + "action": "set", |
| 124 | + "error": { |
| 125 | + "message": "Can not set Vehicle/VehicleIdentification/VIN. Only sensor or actor leaves can be set.", |
| 126 | + "number": 403, |
| 127 | + "reason": "Forbidden" |
| 128 | + }, |
| 129 | + "requestId": "4544fd5f-249e-4da6-8576-248b42504394", |
| 130 | + "timestamp": 1615833005144 |
| 131 | +} |
| 132 | + |
| 133 | +``` |
| 134 | + |
| 135 | +### Non-existing path |
| 136 | +As expected, trying to set a non-existent path returns a 404 |
| 137 | + |
| 138 | +```json |
| 139 | +{ |
| 140 | + "action": "set", |
| 141 | + "path": "Vehicle/FluxCapacitor/Charge", |
| 142 | + "value": "1.21", |
| 143 | + "requestId": "882a6bdd-ff74-433a-a7c4-c2ce2c7f5c07" |
| 144 | +} |
| 145 | +``` |
| 146 | + |
| 147 | +### Response |
| 148 | + |
| 149 | +```json |
| 150 | +{ |
| 151 | + "action": "set", |
| 152 | + "error": { |
| 153 | + "message": "I can not find Vehicle/FluxCapacitor/Charge in my db", |
| 154 | + "number": 404, |
| 155 | + "reason": "Path not found" |
| 156 | + }, |
| 157 | + "requestId": "882a6bdd-ff74-433a-a7c4-c2ce2c7f5c07", |
| 158 | + "timestamp": 1615833326191 |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +### Authorization Checks first |
| 163 | +Please note, that authorization is checked *first*, i.e. in the previous example, if we do not have a permission covering the requested path, no matter it exists or not, we get a 403 |
| 164 | + |
| 165 | +```json |
| 166 | +{ |
| 167 | + "action": "set", |
| 168 | + "path": "Vehicle/FluxCapacitor/Charge", |
| 169 | + "value": "1.21", |
| 170 | + "requestId": "458a269f-ca42-4175-b88c-5ff8bea7855e" |
| 171 | +} |
| 172 | +``` |
| 173 | + |
| 174 | +### Response |
| 175 | + |
| 176 | +```json |
| 177 | +{ |
| 178 | + "action": "set", |
| 179 | + "error": { |
| 180 | + "message": "No write access to Vehicle/FluxCapacitor/Charge", |
| 181 | + "number": 403, |
| 182 | + "reason": "Forbidden" |
| 183 | + }, |
| 184 | + "requestId": "458a269f-ca42-4175-b88c-5ff8bea7855e", |
| 185 | + "timestamp": 1615833458803 |
| 186 | +} |
| 187 | +``` |
| 188 | + |
0 commit comments