Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Security (and type) metadata #116

Closed
zolkis opened this issue May 16, 2018 · 1 comment
Closed

Security (and type) metadata #116

zolkis opened this issue May 16, 2018 · 1 comment

Comments

@zolkis
Copy link
Contributor

zolkis commented May 16, 2018

As in these examples,
in a TD we may want to define security metadata dictionaries and reuse them later by name.

Similarly, we could have a section in the TD that would define type definitions which can be reused inside the TD (e.g. in action parameters).

Mapping this to the Scripting API, it would be possible to use the following conventions:

  • have @securityDefinitions and @typeDefinitions array properties in the ThingTemplate. If defined and not empty, they would initialize internal slots for the given Thing, as dictionaries of dictionaries.
  • everywhere a security dictionary or type definition dictionary is needed, also a string would be accepted, if it matched one of the entries in the corresponding internal slot.

This would make the example code shorter and more concise (define types and security metadata only in one place).

For instance, the quite verbose Example 7 would become a little more concise:

//EXAMPLE 7: Create a new blank exposed Thing
try {
  var thing = WoT.produce({
    name: "tempSensor",
    "@typeDefinitions": {
        temperatureType:  {
          type: "number",
          value: 0.0,
          minimum: -50,
          maximum: 10000,
          forms: []
       }
   },
    properties: {
      temperature: "temperatureType"
    },
    actions: {
      reset: {
        description: "Reset the temperature sensor",
        input: {
          temperature: "temperatureType"
        },
        output: null,
        forms: []
      },
    },
    events: {
      onchange: {
        type: "temperatureType"
    },
    links: []
  });
  thing.expose().then(() => {
      thing.register();
  });
  // define Thing business logic
  setInterval( async () => {
    let mock = Math.random()*100;
    thing.writeProperty("temperature", mock);
    let old = await thing.readProperty("max");
    if (old < mock) {
      thing.writeProperty("max", mock);
      thing.emitEvent("onchange");
    }
  }, 1000);
} catch (err) {
   console.log("Error creating ExposedThing: " + err);
}
@zolkis
Copy link
Contributor Author

zolkis commented Jun 8, 2018

Obsoleted by #113.

@zolkis zolkis closed this as completed Jun 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant