Scripting

Tubee makes use of googles V8 javascript engine to provide the possible way to achieve dynamic attribute scripting or condition resolution. The basic knowlegde about scripting is, that it is imporant to provide a return value by using the function core.result(), this doc will provide some advanced knowlegde for scripts.

Debug scripts

Debugging scripts can be a pain but using the provided logger makes life easier. You may use core.logger.debug('foobar') to send debug information to the tubee core logger. Besides debug there are also (emergency,critical,error,warning,notice,info) available but usually debug is just fine since we only want to log during debugging sessions.

For example the current processed object my be logged by calling:

core.logger.debug(JSON.stringify(object));

Other inbuilt functionality

Hashing

Since there is no crypt in vanially javascript, crypt/hash functionality is provided by using core.crypt.hash('algorithm', 'value').

core.crypt.hash('sha1', core.object.data.password))

DataObject => EndpointObject

We know already that we can access the current processing object by core.object. If the object is of kind DataObject there are some additions to mention:

  • All object relations are available at core.object.relations
  • Endpoint sync stats are available at core.object.endpoints
  • The objects attributes are at core.object.data

For example a more comlex script which loops all object relations and selects the relation with the biggest data.weight number.

var primary=null; for(let relation of core.object.relations) { if(relation.object.collection === 'roles' && (primary === null || relation.object.data.weight > primary.data.weight)) {primary = relation.object;} }; core.result('uid='+core.object.data.username+',ou='+primary.data.name+',o=company,dc=example,dc=org')"

The other way around EndpointObject => DataObject, core.object only holds all fields from the EndpointObject directly.