@coorpacademy/squirrel
Local mirror mecanism for ETCD
Last updated 9 months ago by adriean.khisbe .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @coorpacademy/squirrel 
SYNC missed versions from official npm registry.

Squirrel

Local mirror mecanism for ETCD

npm Build Status codecov

Keep a replication of ETCD folder locally for low latency querying. Provide an index system to access a file without scanning all nodes.

Summary

Install

$ npm install --save @coorpacademy/squirrel
import createSquirrel from '@coorpacademy/squirrel';

Usage

Node Interface

const squirrel = createSquirrel({
    hosts: 'http://localhost:2379',
    auth: null,
    ca: null,
    key: null,
    cert: null,

    cwd: '/',
    fallback: '/tmp/squirrel.json',
    indexes: ['foo', 'bar.baz']
});

Options:

  • hosts: ETCD hosts. more
  • auth: A hash containing {user: "username", pass: "password"} for basic auth. more
  • ca: Ca certificate. more
  • key: Client key. more
  • cert: Client certificate. more
  • cwd: ETCD current working directory.
  • fallback: Temporary file to save ETCD backup.
  • indexes: Array of key to index.

Methods

Consider the following folder:

/
├── bar
│   └── baz   { "bar": { "baz": "qux" } }
└── foo       { "foo": "bar" }

get(path)

Get file by path. Returns Promise;

  • path (String): the path of the file to get.
const foo = await squirrel.get('/foo');
console.log(foo); // { "foo": "bar" }

const barBaz = await squirrel.get('/bar/baz');
console.log(barBaz); // { "bar": { "baz": "qux" } }

getBy(index, key)

Get by index value. Returns Promise;

  • index (String): the path of the property to get. It needs to be declared in the indexes option
  • key (String): the value to match
const foo = await squirrel.getBy('foo', 'bar');
console.log(foo); // { "foo": "bar" }

const barBaz = await squirrel.getBy('bar.baz', 'qux');
console.log(barBaz); // { "bar": { "baz": "qux" } }

Fields can be nested, as described by _.get.

getAll(index)

Get index Map. Returns Promise;

  • index (String): the path of the property to get. It needs to be declared in the indexes option
const foo = await squirrel.getAll('foo');
console.log(foo); // { "bar": { "foo": "bar" } }

const barBaz = await squirrel.getAll('bar.baz');
console.log(barBaz); // { "qux": { "bar": { "baz": "qux" } } }

set(path, value)

Set file by path. Returns Promise;

  • path (String): the path of the file to get.
  • value (Object): An object to store in file. Will be serialized.
const foo = await squirrel.set('/foo',  { "foo": "bar" });
console.log(foo); // { "foo": "bar" }

Command Line Interface

squirrel-sync

Synchronize FS folder with ETCD folder.

$ squirrel-sync --hosts localhost:2379 ./fs-folder /etcd-folder

squirrel-watch

Watch ETCD folder changes.

$ squirrel-watch --hosts localhost:2379 /etcd-folder

squirrel-dump

Write ETCD folder in preloadedStore format.

$ squirrel-dump --hosts localhost:2379 /etcd-folder ./dump.json

Arguments

  • --hosts="host1,host2": ETCD hosts. more
  • --ca=/file.ca: Ca certificate. more
  • --key=/file.key: Client key. more
  • --cert=/file.cert: Client certificate. more

Index System

Squirrel allows to put JSON in file. In this case, it could be indexes to access directly. Consider the following ETCD directory.

/
├── file1 { "foo": "bar" }
├── file2 { "foo": "baz" }
└── file3 { "foo": "qux" }

First of all, we should indicate Squirrel which paths we want to index.

const squirrel = createSquirrel({
  indexes: ['foo']
});

Now, we can get the contents of file1 by searching for its foo value.

const file1 = await squirrel.getBy('foo', 'bar');
console.log(file1); // { "foo": "bar" }

We can also get the value of the index as an object.

const fooIndex = await squirrel.getAll('foo');
console.log(fooIndex);
/*
{
  "bar": { "foo": "bar" },
  "baz": { "foo": "baz" },
  "qux": { "foo": "qux" }
}
 */

If two files have the same index value, Squirrel keeps one of the two.

Squirrel scans all files, no matter how deep, that contain a JSON value.

Index could be a complex path, as long as it works with _.get.

Fallback System

By declaring a fallback path, Squirrel is able :

  • to save its state every time a change is made
  • to restore the state to be faster on the next restart even if ETCD isn't available.

Test

You may run tests with

$ npm test

Marble

Current Tags

  • 5.1.0                                ...           latest (9 months ago)
  • 1.4.5                                ...           legacy (4 years ago)

47 Versions

  • 5.1.0                                ...           9 months ago
  • 5.0.4 [deprecated]           ...           a year ago
  • 5.0.3 [deprecated]           ...           a year ago
  • 5.0.2 [deprecated]           ...           a year ago
  • 5.0.1 [deprecated]           ...           a year ago
  • 5.0.0 [deprecated]           ...           a year ago
  • 5.0.0-alpha.0 [deprecated]           ...           a year ago
  • 4.4.0                                ...           2 years ago
  • 4.3.0                                ...           2 years ago
  • 4.2.1                                ...           2 years ago
  • 4.2.0                                ...           2 years ago
  • 4.0.4                                ...           2 years ago
  • 4.1.0                                ...           2 years ago
  • 4.0.3                                ...           2 years ago
  • 4.0.2                                ...           2 years ago
  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.1.1                                ...           3 years ago
  • 3.1.0                                ...           3 years ago
  • 3.0.1                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.4.1                                ...           4 years ago
  • 2.3.2                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.2                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 2.0.0-3                                ...           4 years ago
  • 2.0.0-2                                ...           4 years ago
  • 2.0.0-1                                ...           4 years ago
  • 2.0.0-0                                ...           4 years ago
  • 1.4.5                                ...           4 years ago
  • 1.4.4                                ...           4 years ago
  • 1.4.3                                ...           4 years ago
  • 1.4.1                                ...           4 years ago
  • 1.4.2                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.2                                ...           4 years ago
  • 1.3.1                                ...           4 years ago
  • 1.2.5                                ...           4 years ago
  • 1.1.5                                ...           4 years ago
  • 1.1.4                                ...           4 years ago
  • 1.1.3                                ...           4 years ago
  • 1.1.2                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.2.2                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (7)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |