feat(xo-server/xo.exportConfig): entries param
Can be used to export a subset of the config, example: ``` xo.exportConfig entries=["acls"] ``` This will only export `acls` entries and dependencies (`groups` and `users`).
This commit is contained in:
@@ -14,7 +14,7 @@ clean.permission = 'admin'
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
export async function exportConfig({ passphrase }) {
|
||||
export async function exportConfig({ entries, passphrase }) {
|
||||
let suffix = '/config.json'
|
||||
if (passphrase !== undefined) {
|
||||
suffix += '.enc'
|
||||
@@ -28,7 +28,7 @@ export async function exportConfig({ passphrase }) {
|
||||
'content-type': 'application/json',
|
||||
})
|
||||
|
||||
return this.exportConfig({ passphrase })
|
||||
return this.exportConfig({ entries, passphrase })
|
||||
},
|
||||
undefined,
|
||||
{ suffix }
|
||||
@@ -39,6 +39,7 @@ export async function exportConfig({ passphrase }) {
|
||||
exportConfig.permission = 'admin'
|
||||
|
||||
exportConfig.params = {
|
||||
entries: { type: 'array', items: { type: 'string' }, optional: true },
|
||||
passphrase: { type: 'string', optional: true },
|
||||
}
|
||||
|
||||
|
||||
@@ -14,19 +14,32 @@ export default class ConfigManagement {
|
||||
this._managers = { __proto__: null }
|
||||
}
|
||||
|
||||
addConfigManager(id, exporter, importer, dependencies) {
|
||||
addConfigManager(id, exporter, importer, dependencies = []) {
|
||||
const managers = this._managers
|
||||
if (id in managers) {
|
||||
throw new Error(`${id} is already taken`)
|
||||
}
|
||||
|
||||
this._depTree.add(id, dependencies)
|
||||
this._managers[id] = { exporter, importer }
|
||||
this._managers[id] = { dependencies, exporter, importer }
|
||||
}
|
||||
|
||||
async exportConfig({ passphrase } = {}) {
|
||||
async exportConfig({ entries, passphrase } = {}) {
|
||||
let managers = this._managers
|
||||
if (entries !== undefined) {
|
||||
const subset = { __proto__: null }
|
||||
entries.forEach(function addEntry(entry) {
|
||||
if (!(entry in subset)) {
|
||||
const manager = managers[entry]
|
||||
subset[entry] = manager
|
||||
manager.dependencies.forEach(addEntry)
|
||||
}
|
||||
})
|
||||
managers = subset
|
||||
}
|
||||
|
||||
let config = JSON.stringify(
|
||||
await mapValues(this._managers, ({ exporter }, key) => exporter())::pAll()
|
||||
await mapValues(managers, ({ exporter }, key) => exporter())::pAll()
|
||||
)
|
||||
|
||||
if (passphrase !== undefined) {
|
||||
|
||||
Reference in New Issue
Block a user