Skip to content

Commit

Permalink
Adds examples for CreateThing and ModifyThing to demonstrate _copyPol…
Browse files Browse the repository at this point in the history
…icyFrom

Signed-off-by: Klem Yannic (INST/ECS1) <Yannic.Klem@bosch-si.com>
  • Loading branch information
Yannic92 authored and thjaeckle committed Nov 8, 2018
1 parent e89dd5a commit 8c617f5
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 0 deletions.
Expand Up @@ -14,3 +14,5 @@ permalink: protocol-examples-creatething.html
{% capture event %}{% include_relative protocol/things/events/thingcreated.md %}{% endcapture %}
{{ event | markdownify }}

{% capture command %}{% include_relative protocol/things/commands/modify/createthingalternatives.md %}{% endcapture %}
{{ command | markdownify }}
Expand Up @@ -14,3 +14,5 @@ permalink: protocol-examples-modifything.html
{% capture event %}{% include_relative protocol/things/events/thingmodified.md %}{% endcapture %}
{{ event | markdownify }}

{% capture command %}{% include_relative protocol/things/commands/modify/modifythingalternatives.md %}{% endcapture %}
{{ command | markdownify }}
@@ -1,5 +1,7 @@
## CreateThing

Creates a new Thing with ID ``com.acme:xdk_53`` that uses an existing Policy with ID ``com.acme:the_policy_id``.

```json
{
"topic": "com.acme/xdk_53/things/twin/commands/create",
Expand Down
@@ -0,0 +1,46 @@
## Alternative CreateThing commands

If you want to copy an Existing policy instead of creating a new one by yourself or reference an existing Policy, you
can adjust the CreateThing command like demonstrated in the following examples.

### CreateThing with copied Policy by Policy ID

Creates a new Thing with ID ``com.acme:xdk_53`` with a Policy copied from the Policy with ID ``com.acme:the_policy_id_to_copy``.

```json
{
"topic": "com.acme/xdk_53/things/twin/commands/create",
"headers": {},
"path": "/",
"value": {
"__schemaVersion": 2,
"__lifecycle": "ACTIVE",
"_revision": 1,
"_namespace": "com.acme",
"thingId": "com.acme:xdk_53",
"policyId": "com.acme:the_policy_id",
"_copyPolicyFrom": "com:acme:the_policy_id_to_copy"
}
}
```

### CreateThing with copied Policy by Thing reference

Creates a new Thing with ID ``com.acme:xdk_53`` with a Policy copied from a Thing with ID ``com.acme:xdk_52``.

```json
{
"topic": "com.acme/xdk_53/things/twin/commands/create",
"headers": {},
"path": "/",
"value": {
"__schemaVersion": 2,
"__lifecycle": "ACTIVE",
"_revision": 1,
"_namespace": "com.acme",
"thingId": "com.acme:xdk_53",
"policyId": "com.acme:the_policy_id",
"_copyPolicyFrom": "{% raw %}{{ ref:things/com:acme:xdk_52/policyId }}{% endraw %}"
}
}
```
@@ -0,0 +1,50 @@
## Alternative ModifyThing commands

If you want to copy an Existing policy instead of creating a new one by yourself or reference an existing Policy, you
can adjust the ModifyThing command like demonstrated in the following examples.
This only works if a Thing with the given ``thingId`` does not exist, yet. If it exists the ``_copyPolicyFrom`` field
will be ignored.

### ModifyThing with copied Policy by Policy ID

If no Thing with ID ``com.acme:xdk_53`` exists, this command will create a new Thing with ID ``com.acme:xdk_53`` with a
Policy copied from the Policy with ID ``com.acme:the_policy_id_to_copy``.

```json
{
"topic": "com.acme/xdk_53/things/twin/commands/modify",
"headers": {},
"path": "/",
"value": {
"__schemaVersion": 2,
"__lifecycle": "ACTIVE",
"_revision": 1,
"_namespace": "com.acme",
"thingId": "com.acme:xdk_53",
"policyId": "com.acme:the_policy_id",
"_copyPolicyFrom": "com:acme:the_policy_id_to_copy"
}
}
```

### ModifyThing with copied Policy by Thing reference

If no Thing with ID ``com.acme:xdk_53`` exists, this command will create a new Thing with ID ``com.acme:xdk_53`` with a
Policy copied from a Thing with ID ``com.acme:xdk_52``.

```json
{
"topic": "com.acme/xdk_53/things/twin/commands/modify",
"headers": {},
"path": "/",
"value": {
"__schemaVersion": 2,
"__lifecycle": "ACTIVE",
"_revision": 1,
"_namespace": "com.acme",
"thingId": "com.acme:xdk_53",
"policyId": "com.acme:the_policy_id",
"_copyPolicyFrom": "{% raw %}{{ ref:things/com:acme:xdk_52/policyId }}{% endraw %}"
}
}
```

0 comments on commit 8c617f5

Please sign in to comment.