Skip to content

Commit

Permalink
Merge Paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ingalls committed Oct 30, 2024
1 parent 41dde52 commit 9bc33c4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
53 changes: 46 additions & 7 deletions persist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 9bc33c4

Please sign in to comment.