forked from kuzzleio/kourou
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport-mappings.ts
42 lines (32 loc) · 1.05 KB
/
export-mappings.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import fs from 'fs'
import path from 'path'
import { flags } from '@oclif/command'
import { Kommand } from '../../common'
import { kuzzleFlags } from '../../support/kuzzle'
export default class UserExportMappings extends Kommand {
static description = 'Exports users collection mappings to JSON.'
static flags = {
help: flags.help({}),
path: flags.string({
description: 'Dump directory',
default: 'users'
}),
...kuzzleFlags,
protocol: flags.string({
description: 'Kuzzle protocol (http or websocket)',
default: 'ws'
})
}
async runSafe() {
const filename = path.join(this.flags.path, 'users-collection-mappings.json')
this.logInfo(`Exporting users collection mappings in ${filename} ...`)
fs.mkdirSync(this.flags.path, { recursive: true })
const mapping = await this.sdk.security.getUserMapping()
const dump = {
type: 'usersMappings',
content: mapping
}
fs.writeFileSync(filename, JSON.stringify(dump, null, 2))
this.logOk('Users collection mappings dumped')
}
}