diff --git a/package.json b/package.json index 0594954..07e7851 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "description": "Infrastructure to support LDAP based auth in TAK", "scripts": { "check": "tsx persist.ts", - "lint": "eslint cloudformation/", + "lint": "eslint persist.ts cloudformation/", "test": "echo \"Error: no test specified\" && exit 1" }, "engines": { diff --git a/persist.ts b/persist.ts index 3e22c7a..e9e0322 100644 --- a/persist.ts +++ b/persist.ts @@ -3,15 +3,54 @@ import YAML from 'yaml'; cron.schedule('0,10,20,30,40,50 * * * * *', async () => { try { - const res = await fetch('http://localhost:9997/v3/config/global/get', { - method: 'GET', - headers: { - Authorization: `Basic ${Buffer.from('management:' + process.env.MANAGEMENT_PASSWORD)}` - } - }) + const base = await globalConfig(); + const paths = await globalPaths(); + + base.paths = paths; - console.error(JSON.stringify(res)); + console.log(YAML.stringify(base)) } catch (err) { consoe.error(err); } }); + +async function globalPaths(): any { + let page = -1; + let res: any; + + const paths = []; + + do { + ++page; + + const url = new URL('http://localhost:9997/v3/config/paths/list'); + url.searchParams.append('itemsPerPage', '1000'); + url.searchParams.append('page', String(page)); + + const res = await fetch(url, { + method: 'GET', + headers: { + Authorization: `Basic ${Buffer.from('management:' + process.env.MANAGEMENT_PASSWORD).toString('base64')}` + } + }) + + const body = await res.json(); + + paths.push(...body.items); + } while (res.itemCount > page * 1000) + + return paths; +} + +async function globalConfig(): any { + const res = await fetch('http://localhost:9997/v3/config/global/get', { + method: 'GET', + headers: { + Authorization: `Basic ${Buffer.from('management:' + process.env.MANAGEMENT_PASSWORD).toString('base64')}` + } + }) + + const body = await res.json(); + + return body; +}