Caller component of SUGOS.
SUGO-Caller works as a client of SUGO-Hub and provides accessors for remote SUGO-Actor .
Table of Contents
Requirements
Installation
$ npm install sugo-caller --save
Usage
Create a caller instance with [SUGO-Hub][sugo_hub_url] url and connect to an [SUGO-Actor][sugo_actor_url] with key.
#!/usr/bin/env node /** * This is an example to use caller to connect remote actor */'use strict' const sugoCaller = const TARGET_ACTOR_ID = 'my-actor-01' { let caller = // Connect to the target actor let actor = await caller let shell = actor // Get bash interface // Trigger ls command on remote actor let lsResult = await shell console // Pipe std out let processstdout shell await shell // Trigger tailing without blocking await // Block for duration shell // Exec reboot command await shell}
For more detail, see API Guide
Tips
Restricting Connecting Modules
Sometime you would like to make sure that the connecting actor has right modules as expected.
You can pass a JSON-Schema to expect
option when accessing a modules.
If the modules does not conform to the schema, it throws an error.
#!/usr/bin/env node /** * This is an example to restrict a module with json schema */'use strict' const sugoCaller = // JSON-Schema for expected spec infoconst shellSchemaV2 = type: 'object' properties: name: enum: 'shell' // Should be shell version: pattern: '^2\.' // Major version must be 2 /* ... */ { let caller = let actor = await caller let shell try shell = actor catch err console /* ... */}
Describing a Module
You can get module spec data via .describe(moduleName)
of actor connection.
#!/usr/bin/env node /** * This is an example to describe a module */'use strict' const sugoCaller = { let caller = let actor = await caller let description = actor console // -> { name: 'shell', desc: 'Shell interface', ... } /* ... */}
Use auth
You can pass auth config to SUGO-Hub by setting auth
field on the constructor.
#!/usr/bin/env node /** * This is an example to use an auth * @see https://github.com/realglobe-Inc/sugo-hub#use-authentication */'use strict' const sugoCaller = { let caller = // Connect to the target actor let actor = await caller let shell = actor // Get bash interface /* ... */}
License
This software is released under the Apache-2.0 License.