@@ -22,6 +22,11 @@ $ npm install node-etcd@3.0.2
22
22
23
23
## Changes
24
24
25
+ - 5.0.0
26
+ - Supports basic auth.
27
+ - Breaking: Constructor changes
28
+ - Breaking: Must provide https url to use https
29
+
25
30
- 4.2.1
26
31
- Newer deasync fixes issues with iojs 3.3.0 and nodejs 4.0.0.
27
32
- 4.1.0
@@ -76,24 +81,39 @@ $ npm install node-etcd@3.0.2
76
81
## Basic usage
77
82
78
83
``` javascript
79
- Etcd = require (' node-etcd' );
80
- etcd = new Etcd ();
84
+ var Etcd = require (' node-etcd' );
85
+ var etcd = new Etcd ();
81
86
etcd .set (" key" , " value" );
82
87
etcd .get (" key" , console .log );
83
88
```
84
89
90
+ Callbacks follows the default (error, result) nodejs convention:
91
+
92
+ ``` javascript
93
+ function callback (err , res ) {
94
+ console .log (" Error: " , err);
95
+ console .log (" Return: " , res);
96
+ }
97
+ etcd .get (" key" , callback);
98
+ // Error: null
99
+ // Return: { action: 'get', node: { key: '/key', value: 'value', modifiedIndex: 4, createdIndex: 4 } }
100
+ ```
101
+
85
102
## Methods
86
103
87
- ### Etcd([ host = '127.0.0.1' ] , [ port = ' 4001'] , [ ssloptions ] )
104
+ ### Etcd(hosts = [ '127.0.0.1: 4001'] , [ options ] )
88
105
89
106
Create a new etcd client for a single host etcd setup
90
107
91
108
``` javascript
92
109
etcd = new Etcd ();
93
- etcd = new Etcd (' 127.0.0.1' , ' 4001' );
110
+ etcd = new Etcd (" 127.0.0.1:4001" );
111
+ etcd = new Etcd (" http://127.0.0.1:4001" );
112
+ etcd = new Etcd (" https://127.0.0.1:4001" );
113
+ etcd = new Etcd ([" http://127.0.0.1:4001" ]);
94
114
```
95
115
96
- ### Etcd(hosts, [ ssloptions ] )
116
+ ### Etcd(hosts, [ options ] )
97
117
98
118
Create a new etcd client for a clustered etcd setup. Client will connect to
99
119
servers in random order. On failure it will try the next server. When all
@@ -103,6 +123,7 @@ retries can be controlled by adding `{ maxRetries: x }` as an option to requests
103
123
104
124
``` javascript
105
125
etcd = new Etcd ([' 127.0.0.1:4001' ,' 192.168.1.1:4001' ]);
126
+ etcd = new Etcd ([' http://127.0.0.1:4001' ,' http://192.168.1.1:4001' ]);
106
127
```
107
128
108
129
### .set(key, value = null, [ options] , [ callback] )
@@ -396,20 +417,44 @@ you won't get any callbacks from the request after calling `.abort()`.
396
417
397
418
## SSL support
398
419
399
- Pass etcdclient a dictionary containing ssl options, check out http://nodejs.org/api/ https.html#https_https_request_options_callback
420
+ Provide ` ca ` , ` cert ` , ` key ` as options. Remember to use ` https ` -url.
400
421
401
422
``` javascript
402
- fs = require (' fs' );
423
+ var fs = require (' fs' );
403
424
404
- sslopts = {
405
- ca: [ fs .readFileSync (' ca.pem' ) ] ,
425
+ var options = {
426
+ ca: fs .readFileSync (' ca.pem' ),
406
427
cert: fs .readFileSync (' cert.pem' ),
407
- key: fs .readFileSync (' key.pem' )
428
+ key: fs .readFileSync (' key.pem' )
408
429
};
409
430
410
- etcdssl = new Etcd (' localhost' , ' 4001' , sslopts );
431
+ var etcdssl = new Etcd (" https:// localhost: 4001" , options );
411
432
```
412
433
434
+ ## Basic auth
435
+
436
+ Pass a hash containing username and password as auth option to use basic auth.
437
+
438
+ ``` javascript
439
+ var auth = {
440
+ user: " username" ,
441
+ pass: " password"
442
+ }
443
+
444
+ var etcd = new Etcd (" localhost:4001" , { auth: auth });
445
+ ```
446
+
447
+ ## Constructor options
448
+
449
+ Useful constructor options include:
450
+
451
+ - ` timeout ` - Integer request timeout in milliseconds to wait for server response.
452
+ - ` ca ` - Ca certificate
453
+ - ` cert ` - Client certificate
454
+ - ` key ` - Client key
455
+ - ` passphrase ` - Client key passphrase
456
+ - ` auth ` - A hash containing ` {user: "username", pass: "password"} ` for basic auth.
457
+
413
458
## FAQ:
414
459
415
460
- Are there any order of execution guarantees when doing multiple requests without using callbacks?
0 commit comments