-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
73 changed files
with
1,792 additions
and
2,777 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
etcd: | ||
image: quay.io/coreos/etcd | ||
image: quay.io/coreos/etcd:v3.2.13 | ||
ports: | ||
- "2379:2379" | ||
- "4001:4001" | ||
command: etcd --listen-client-urls 'http://0.0.0.0:2379' --advertise-client-urls 'http://0.0.0.0:2379' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {promisify} from 'util'; | ||
import {escape as qsEscape} from 'querystring'; | ||
import {join} from 'path'; | ||
import {writeFile} from 'fs'; | ||
import {Observable} from 'rxjs'; | ||
import mkdirp from 'mkdirp'; | ||
import {parseRangeResponse} from '../../etcd/command'; | ||
|
||
const mkdirpP = promisify(mkdirp); | ||
const writeFileP = promisify(writeFile); | ||
|
||
const dump = async (client, outDir) => { | ||
await mkdirpP(outDir); | ||
|
||
return Observable.fromPromise(client.getAll().exec()) | ||
.map(parseRangeResponse) | ||
.concatMap(Observable.from) | ||
.mergeMap(record => | ||
Observable.fromPromise( | ||
writeFileP(join(outDir, qsEscape(record.key)), JSON.stringify(record.value, null, 2), { | ||
encoding: 'utf8' | ||
}) | ||
) | ||
) | ||
.toPromise(); | ||
}; | ||
|
||
export default dump; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {readFileSync} from 'fs'; | ||
import {resolve} from 'path'; | ||
import {Etcd3} from 'etcd3'; | ||
|
||
const createEtcd = ( | ||
{ | ||
hosts = 'http://127.0.0.1:2379', | ||
username, | ||
password, | ||
rootCertificate, | ||
|
||
namespace = '' | ||
} = {} | ||
) => { | ||
const auth = | ||
!!username || !!password | ||
? { | ||
username, | ||
password | ||
} | ||
: null; | ||
|
||
const credentials = rootCertificate | ||
? { | ||
rootCertificate: readFileSync(resolve(process.cwd(), rootCertificate)) | ||
} | ||
: null; | ||
|
||
const client = new Etcd3({ | ||
hosts: hosts.split(','), | ||
auth, | ||
credentials | ||
}); | ||
|
||
return client; | ||
}; | ||
|
||
export default createEtcd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import {promisify} from 'util'; | ||
import {unescape as qsUnescape} from 'querystring'; | ||
import {join} from 'path'; | ||
import {readFile, readdir} from 'fs'; | ||
import mkdirp from 'mkdirp'; | ||
import {Observable} from 'rxjs'; | ||
|
||
const mkdirpP = promisify(mkdirp); | ||
const readFileP = promisify(readFile); | ||
const readdirP = promisify(readdir); | ||
|
||
const restore = async (client, inDir) => { | ||
await mkdirpP(inDir); | ||
|
||
return Observable.fromPromise(readdirP(inDir)) | ||
.concatMap(Observable.from) | ||
.mergeMap(file => | ||
Observable.fromPromise( | ||
readFileP(join(inDir, file), { | ||
encoding: 'utf8' | ||
}) | ||
) | ||
.map(JSON.parse) | ||
.map(content => [qsUnescape(file), content]) | ||
) | ||
.mergeMap(([key, value]) => | ||
Observable.fromPromise(client.put(key).value(JSON.stringify(value, null, 4))) | ||
) | ||
.toPromise(); | ||
}; | ||
|
||
export default restore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import {tmpdir} from 'os'; | ||
import {join} from 'path'; | ||
import {promisify} from 'util'; | ||
import {readFile, readdir} from 'fs'; | ||
import test from 'ava'; | ||
import {Etcd3} from 'etcd3'; | ||
import dump from '../dump'; | ||
|
||
const readFileP = promisify(readFile); | ||
const readdirP = promisify(readdir); | ||
|
||
test('should create dump dir', async t => { | ||
const tmpPath = join(tmpdir(), `squirrel-test-dump-${Date.now()}`); | ||
|
||
const client = new Etcd3(); | ||
client.mock({ | ||
exec: (...argz) => | ||
Promise.resolve({ | ||
kvs: [ | ||
{ | ||
key: Buffer.from('foo'), | ||
value: Buffer.from('{"foo": "foo"}'), | ||
mod_revision: '1' | ||
}, | ||
{ | ||
key: Buffer.from('bar'), | ||
value: Buffer.from('{"bar": "bar"}'), | ||
mod_revision: '1' | ||
} | ||
] | ||
}) | ||
}); | ||
|
||
await dump(client, tmpPath); | ||
|
||
t.deepEqual(await readdirP(tmpPath), ['bar', 'foo']); | ||
|
||
t.deepEqual(await readFileP(join(tmpPath, 'foo'), {encoding: 'utf8'}), '{\n "foo": "foo"\n}'); | ||
t.deepEqual(await readFileP(join(tmpPath, 'bar'), {encoding: 'utf8'}), '{\n "bar": "bar"\n}'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {readFileSync} from 'fs'; | ||
import {join} from 'path'; | ||
import test from 'ava'; | ||
import createEtcd from '../etcd'; | ||
|
||
test('should create Etcd3 client', t => { | ||
const client = createEtcd(); | ||
|
||
t.truthy(client.pool.options.hosts); | ||
t.falsy(client.pool.options.auth); | ||
t.falsy(client.pool.options.credentials); | ||
}); | ||
|
||
test('should create Etcd3 client with options', t => { | ||
const hosts = 'https://localhost:1,https://localhost:2'; | ||
const username = 'root'; | ||
const password = 'admin'; | ||
const rootCertificate = join(__dirname, 'fixtures/etcd.ca'); | ||
|
||
const client = createEtcd({ | ||
hosts, | ||
username, | ||
password, | ||
rootCertificate | ||
}); | ||
|
||
t.deepEqual(client.pool.options.hosts, hosts.split(',')); | ||
t.deepEqual(client.pool.options.auth, { | ||
username, | ||
password | ||
}); | ||
t.deepEqual(client.pool.options.credentials, { | ||
rootCertificate: readFileSync(rootCertificate) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"bar": "bar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"foo": "foo" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-----BEGIN CERTIFICATE----- | ||
foo | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {join} from 'path'; | ||
import test from 'ava'; | ||
import {Etcd3} from 'etcd3'; | ||
import restore from '../restore'; | ||
|
||
test('should restore dump dir', async t => { | ||
t.plan(6); | ||
|
||
const tmpPath = join(__dirname, 'fixtures/dump'); | ||
|
||
const puts = { | ||
bar: { | ||
key: Buffer.from('bar'), | ||
value: Buffer.from('{\n "bar": "bar"\n}') | ||
}, | ||
foo: { | ||
key: Buffer.from('foo'), | ||
value: Buffer.from('{\n "foo": "foo"\n}') | ||
} | ||
}; | ||
|
||
const client = new Etcd3(); | ||
client.mock({ | ||
exec: (service, method, params) => { | ||
t.is(service, 'KV'); | ||
t.is(method, 'put'); | ||
const expected = puts[params.key.toString()]; | ||
t.deepEqual(params, expected); | ||
return Promise.resolve(); | ||
} | ||
}); | ||
|
||
await restore(client, tmpPath); | ||
}); |
Oops, something went wrong.