Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: update for 1.0.0


Warning
titlenot present in 1.0

This library is not a part of version 1.0 of the pico-engine

Table of Contents
maxLevel3
indent15px

...

ParameterDatatypeRequired
<eci><string>YES


removeChannel
Code Block
title
pico_id = engine:getPicoIDByECI(eci)
/*
    "some_pico_id"
*/

...

Get the parent's pico_id for the current or given pico_id.

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id


newChannel
Code Block
title
parent_id = engine:getParent(pico_id)
/*
	"the parent's pico_id"
*/

...

List the pico's children pico_ids.

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id


newChannel
Code Block
title
children = engine:listChildren(pico_id)
/*
  [
    "child 0 pico_id",
    "child 1 pico_id",
    ...
  ]
*/

listPolicies

List all the engine policies.

Code Block
policies = engine:listPolicies()
/*
  [
    {id: "1234", name: "policy 1", event: {allow: [...]} query: ...},
    {id: "4321", name: "policy 2", event: {allow: [...]} query: ...},
    {id: "5555", name: "policy 3", event: {allow: [...]} query: ...},
  ]
*/


listChannels

List the pico's channels.

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id


newChannel
Code Block
title
channels = engine:listChannels(pico_id)
/*
	[
      {
        "id" : "eci-0...",
        "pico_id": <pico_id>,
        "name": "name 0",
        "type": "type 0"
      },
      {
        "id" : "eci-1...",
        "pico_id": <pico_id>,
        "name": "name 1",
        "type": "type 1"
      }
    ]
*/

...

List the rid's installed on the pico.

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id


newChannel
Code Block
title
rids = engine:listInstalledRIDs(pico_id)
/*
  ["io.picolabs.pico", ...]

*/

...

List all enabled ruleset ids. No parameters are given.

title
Code Block
intall ruleset
rids = engine:listAllEnabledRIDs();
/*
	["io.picolabs.pico", "io.picolabs.logging"]
*/

...

ParameterDatatypeRequired
<rid><string>YES


intall ruleset
Code Block
title
desc = engine:describeRuleset("io.picolabs.hello_world");
/*
    {
        "rid": "io.picolabs.hello_world",
        "src": "ruleset io.picolabs.hello_world{ ...<cut for brevity> ... }",
        "hash": "a096f2f3bfbd63e54bf4f39081814dbc895f3f003ae9918dbe24aec8acc097b9",
        "url": "https://raw.githubusercontent.com/Picolab/node-pico-engine-core/master/test-rulesets/hello-world.krl",
        "timestamp_stored": "2017-05-17T21:31:21.663Z",
        "timestamp_enable": "2017-05-17T21:31:21.663Z",
        "meta": {
            "name": "Hello World",
            "description": "\nA first ruleset for the Quickstart\n    ",
            "author": "Phil Windley"
        }
    }
*/

encryptChannelMessage

Encrypt a message sent over a channel

ParameterDatatypeRequired
<eci><string>YES
<encryptedMessage><string>

YES

<nonce><string>YES
<otherPublicKey><string>YES


Code Block
 encrypted_message = engine:encryptChannelMessage(eci, message, subscription.other_encryption_public_key)
/*
	{
		"encryptedMessage" : <base 58 encrypted message>,
        "nonce" : <base 58 nonce used to encrypt message>,
	}
*/

decryptChannelMessage

Encrypt a message sent over a channel

ParameterDatatypeRequired
<eci><string>YES
<message><string>

YES

<otherPublicKey><string>YES


Code Block
decrypted_message = engine:decryptChannelMessage(eci, encrypted_message, nonce, other_encryption_public_key)

/*
	// The decrypted message if successfully decrypted, false otherwise
*/

signChannelMessage

SIgn a message sent over a channel

ParameterDatatypeRequired
<eci><string>YES
<message><string>

YES


Code Block
signed_message = engine:signChannelMessage(eci, message)
/*
	// Base 58 encoded string that is the signed message
*/

verifySignedMessage

Verify a message sent over a channel

ParameterDatatypeRequired
<verifyKey><string>YES
<message><string>

YES


Code Block
verifiedMessage = engine:verifySignedMessage(verify_key, signedMessage)
/*
	// The original message if verified, false otherwise
*/

Actions

newPico

Creates a new pico.

ParameterDatatypeRequiredDefault
<parent_id><string>NOthe running pico_id


newPico
Code Block
title
engine:newPico() setting(resp)
/*
	{
		"id" : <new_pico_id>,
        "parent_id" : <current pico_id>,
	}
*/

Note: newPico does not provide an eci. This action is used in conjunction with engine:createChannel to create a pico with both an id and eci. See wranglerNPE.krl for an example of how to fully create a pico according to a given prototype.


removePico

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id


Code Block
titleremovePico
engine:removePico(idengine:removePico(id)


newPolicy

Creates a new policy.

ParameterDatatypeRequired
<policy><map>YES


Code Block
engine:newPolicy({
    name: "only allow foo/bar events",
    event: {
        allow: [
            {domain: "foo", type: "bar"}
        ]
    }
}) setting(resp)
/*
	{
        id: "1234",
    	name: "only allow foo/bar events",
        event: {
            allow: [{domain: "foo", type: "bar"}],
            deny: [],
        },
        query: {allow: [], deny: []}
	}
*/

For more description on how these policies work see: https://github.com/Picolab/pico-engine/pull/350#issue-160657235

removePolicy

Removes a policy. It will error if any channels are still using it.

ParameterDatatypeRequired
<policy_id><string>YES


Code Block
engine:removePolicy("1234")


newChannel

Creates a new channel for a pico.

...

ParameterDatatypeRequiredDefault
<pico_id><string>NOthe running pico_id
<name><string>YES
<type><string>YES

...


<policy_id><string>YES


Code Block
engine:newChannel(name = "channel_name", type = "channel_type", policy_id = "1234") setting(resp)
/*
	{
		"id" : <new_eci>,
        "pico_id": <pico_id>,
		"name": "channel_name",
		"type": "channel_type",
		"policy_id": "1234"
 	}
*/

Note: "id" in the resp body is the given pico's new channel eci, not the original id passed into the function.

...

ParameterDatatypeRequired
<eci><string>YES


removeChannel
Code Block
title
engine:removeChannel("eci123...")

...

If you provide `base` then it will be resolved with the url. For example, `base` is  "http://raw.githubusercontent.com/" and `url` is "/username/repository1/file.txt" then the engine will register `http`http://raw.githubusercontent.com/username/repository1/file.txt`txt`

Attempting to register a ruleset with the same rid as a rule that is already registered will pull the ruleset from the given base/url and act as an update action, overwriting the current file with the one from the remote repository.

If you register a ruleset sharing a rid with a system ruleset, the system ruleset will be restored when the engine is restarted.

title
Code Block
registerRuleset
engine:registerRuleset("some.cool.ruleset.krl", base = "http://example.com/krl-files/") setting(resp)
/*
    "some.cool.ruleset.id"
*/

...

ParameterDatatypeRequired
<rid>string | arrayYES


unregisterRuleset
Code Block
title
engine:unregisterRuleset("myRuleset")


engine:unregisterRuleset(["rid.1", "rid.2"])

...

Do not provide the "rid" key if you want to retrieve the krl file from a remote repository (just provide the "base" and "url" keys). If you provide the "rid" key at all, this function will assume the ruleset is already registered with the engine and will simply throw an error if it is not found, ignoring the "base" and "url" as if they were not submitted. If the "base" and "url" are provided, then the krl file will be registered to the engine (if not already) and then installed on the pico with the given "pico_id".

title
Code Block
intall ruleset
engine:installRuleset( ent:id, "wrangler" ) setting(resp)
/*
    "wrangler"
*/

engine:installRuleset( ent:id, ["wrangler","Pds"] ) setting(resp)
/*
    ["wrangler","Pds"]
*/

engine:installRuleset( ent:id, base = <base>, url = <url> ) setting(resp)
/*
    "the.rid.at.that.url"
*/

...

This does not return anything

unregisterRuleset
Code Block
title
engine:uninstallRuleset( rid = "myRuleset")


engine:uninstallRuleset( meta:picoId, ["rid.1", "rid.2"])

...