Options
All
  • Public
  • Public/Protected
  • All
Menu

Etcd3 is a high-level interface for interacting and calling etcd endpoints. It also provides several lower-level clients for directly calling methods.

const { Etcd3 } = require('etcd3');
const client = new Etcd3();

await client.put('foo').value('bar');
console.log('foo is:', await client.get('foo').string());

const keys = await client.getAll().prefix('f').strings();
console.log('all keys starting with "f"': keys);

await client.delete().all();

Hierarchy

Index

Constructors

constructor

Methods

close

  • close(): void
  • Frees resources associated with the client.

    Returns void

delete

election

  • election(name: string, ttl?: undefined | number): Election
  • Creates a new Election instead. See more information on the Election class documentation.

    Parameters

    • name: string

      Name of the election in the etcd instance.

    • Optional ttl: undefined | number

      Lease TTL used in the election. This is the maximum time that a node which goes down can remain the leader before being automatically evicted.

    Returns Election

get

getAll

getRoles

  • getRoles(): Promise<Role[]>
  • Resolves to an array of roles available in etcd.

    Returns Promise<Role[]>

getUsers

  • getUsers(): Promise<User[]>
  • Resolves to an array of users available in etcd.

    Returns Promise<User[]>

if

  • if() starts a new etcd transaction, which allows you to execute complex statements atomically. See documentation on the ComparatorBuilder for more information.

    Parameters

    • key: string | Buffer
    • column: keyof typeof compareTarget
    • cmp: keyof typeof comparator
    • value: string | Buffer | number

    Returns ComparatorBuilder

lease

  • lease() grants and returns a new Lease instance. The Lease is automatically kept alive for you until it is revoked. See the documentation on the Lease class for some examples.

    Parameters

    Returns Lease

lock

  • lock(key: string | Buffer): Lock
  • lock() is a helper to provide distributed locking capability. See the documentation on the Lock class for more information and examples.

    Parameters

    • key: string | Buffer

    Returns Lock

mock

  • mock<T>(callable: T): T
  • .mock() allows you to insert an interface that will be called into instead of calling out to the "real" service. unmock should be called after mocking is finished.

    For example:

    const sinon = require('sinon');
    const { expect } = require('chai');
    
    const { Etcd3 } = require('etcd3');
    const client = new Etcd3();
    
    const mock = client.mock({ exec: sinon.stub() });
    mock.exec.resolves({ kvs: [{ key: 'foo', value: 'bar' }]});
    const output = client.get('foo').string();
    expect(output).to.equal('bar');
    client.unmock();

    Type parameters

    Parameters

    • callable: T

    Returns T

namespace

  • namespace(prefix: string | Buffer): Namespace
  • namespace adds a prefix and returns a new Namespace, which is used for operating on keys in a prefixed domain. For example, if the current namespace is the default "" and you call namespace('user1/'), all operations on that new namespace will be automatically prefixed with user1/. See the Namespace class for more details.

    Parameters

    • prefix: string | Buffer

    Returns Namespace

put

range

  • Creates a structure representing an etcd range. Used in permission grants and queries. This is a convenience method for Etcd3.Range.from(...).

    Parameters

    Returns Range

role

  • role(name: string): Role
  • Returns an object to manipulate the role with the provided name.

    Parameters

    • name: string

    Returns Role

stm

unmock

  • unmock(): void
  • Removes any previously-inserted mock.

    Returns void

user

  • user(name: string): User
  • Returns an object to manipulate the user with the provided name.

    Parameters

    • name: string

    Returns User

watch

Legend

  • Constructor
  • Method
  • Inherited method

Generated using TypeDoc