Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenyoung committed Nov 28, 2024
2 parents 2963b9b + 6081e25 commit cf59e58
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 3 deletions.
38 changes: 36 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ Adjust the port if required.

Orbiter will deny all requests by default. To allow a user to interact with Orbiter, the (requesting) user's `id` must be added to Orbiter's "allow" list.

Access to Orbiter can be configured using the Voyager binary.
Access to Orbiter can be configured in two ways; from the terminal and programmatically, using RPC.

The user's `id` used in the examples below can be retrieved from the user's OrbitDB instance's **`orbitdb.identity.id`** field.
**NOTE** The user's `id` used in the examples below can be retrieved using **`orbitdb.identity.id`**, which is available from the user's OrbitDB instance.

### Managing access from the terminal

To add an authorized user to Orbiter:

Expand Down Expand Up @@ -92,6 +94,38 @@ VOYAGER_PATH=/custom/voyager/path voyager auth remove <id>
VOYAGER_PATH=/custom/voyager/path voyager auth list
```

### Managing access using RPC

Authorizing users can be carried out programmatically using Voyager's RPC function.

Start by instantiating the rpc:

```
import { RPC } from '@orbitdb/voyager'
const rpc = await RPC({ directory: '' })
```

To add an authorization:

```
const id = '037ba2545db2e2ec0ba17fc9b35fbbf6bc09db82c9ab324521e62693e8aa96ceb4'
await rpc.authAdd({ id })
```

To list all authorizations:

```
const { message } = await rpc.authList()
console.log(message)
```

And to remove an authorization:

```
await rpc.authDel()
```

## Adding databases using "Lander"

To make databases accessible from Voyager, the database needs to be added to an Orbiter storage service instance. This can be achieved programmatically by using the "Lander" module.
Expand Down
4 changes: 3 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Orbiter from './lib/orbiter.js'
import Lander from './lib/lander.js'
import RPC from './rpc-client.js'

export {
Orbiter,
Lander
Lander,
RPC
}
38 changes: 38 additions & 0 deletions test/rpc.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { deepStrictEqual } from 'assert'
import { rimraf } from 'rimraf'
import { RPC } from '../src/index.js'
import { spawn } from 'node:child_process'
import waitForDaemonStarted from './utils/wait-for-daemon-start.js'

describe('RPC', function () {
let daemon
let rpc

before(async function () {
daemon = spawn('./src/bin/cli.js', ['daemon'])

await waitForDaemonStarted(daemon)

rpc = await RPC({ directory: '' })
})

after(async function () {
daemon.kill()
await rimraf('voyager')
})

it('adds an authorized user', async function () {
const id = '037ba2545db2e2ec0ba17fc9b35fbbf6bc09db82c9ab324521e62693e8aa96ceb4'
await rpc.authAdd({ id })
const { message } = await rpc.authList()
deepStrictEqual(message, [id])
})

it('removes an authorized user', async function () {
const id = '037ba2545db2e2ec0ba17fc9b35fbbf6bc09db82c9ab324521e62693e8aa96ceb4'
await rpc.authAdd({ id })
await rpc.authDel({ id })
const { message } = await rpc.authList()
deepStrictEqual(message, [])
})
})

0 comments on commit cf59e58

Please sign in to comment.