Commit 443219ce authored by nanahira's avatar nanahira

types

parent 89697efe
......@@ -17,6 +17,11 @@
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.149.tgz",
"integrity": "sha512-ijGqzZt/b7BfzcK9vTrS6MFljQRPn5BFWOx8oE0GYxribu6uV+aA9zZuXI1zc/etK9E8nrgdoF2+LgUw7+9tJQ=="
},
"@types/mustache": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/@types/mustache/-/mustache-4.1.1.tgz",
"integrity": "sha512-Sm0NWeLhS2QL7NNGsXvO+Fgp7e3JLHCO6RS3RCnfjAnkw6Y1bsji/AGfISdQZDIR/AeOyzkrxRk9jBkl55zdJw=="
},
"@types/node": {
"version": "13.7.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-13.7.0.tgz",
......@@ -61,6 +66,11 @@
"integrity": "sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==",
"dev": true
},
"mustache": {
"version": "4.2.0",
"resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
"integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ=="
},
"source-map": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
......
......@@ -10,9 +10,11 @@
"dependencies": {
"@types/ip": "^1.1.0",
"@types/lodash": "^4.14.149",
"@types/mustache": "^4.1.1",
"csv-parse": "^4.8.5",
"ip": "^1.1.5",
"lodash": "^4.17.15",
"mustache": "^4.2.0",
"yaml": "^1.10.0"
},
"devDependencies": {
......
......@@ -17,7 +17,7 @@ async function generateOcpasswdLine(username: string, password: string) {
return res;
}
interface GatewayGroup {
interface GatewayGroup extends Record<string, any> {
id: number;
name: string;
locationPrefix: string;
......@@ -27,15 +27,17 @@ interface GatewayGroup {
destMark: number;
}
type CommonEntry = Record<string, any>;
class InventoryBuilder {
hosts: { [key: string]: any };
gateways: any;
hosts: { [key: string]: CommonEntry };
gateways: Record<string, CommonEntry>;
gatewayGroups: GatewayGroup[];
connections: string[];
routeLists: any;
routeLists: Record<string, string[]>;
resolveCache: Map<string, string>;
resolver: dns.Resolver;
vars: any;
vars: CommonEntry;
linksOnly: string[];
linksLimit: string[];
......@@ -78,7 +80,7 @@ class InventoryBuilder {
return resolvedIP;
}
async load(sheetName: string) {
async load(sheetName: string): Promise<Record<string, any>[]> {
const data = await fs.promises.readFile(path.join('data', `内网互联计划 - ${sheetName}.csv`));
// @ts-ignore
return (await util.promisify(parse)(data, { columns: true, cast: true })).filter(h => h.id);
......@@ -101,7 +103,7 @@ class InventoryBuilder {
async main() {
this.hosts = _.keyBy(await this.load('nextgen2'), 'name');
this.gateways = _.mapValues(_.groupBy(await this.loadGateways(), 'router'), g => _.keyBy(g, 'isp'));
this.gatewayGroups = await this.load('gateway groups');
this.gatewayGroups = await this.load('gateway groups') as GatewayGroup[];
//console.log(this.gateways);
this.connections = _.intersection(Object.keys(this.hosts), Object.keys(_.find(this.hosts)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment