190 lines
12 KiB
JavaScript
190 lines
12 KiB
JavaScript
const DBCache = require('../webapp/db-cache.js');
|
|
const LOG = require('../../logger.js')('init-db');
|
|
|
|
let configs = [
|
|
{
|
|
url: 'https://127.0.0.1:3030',
|
|
publicKey:
|
|
'-----BEGIN PUBLIC KEY-----\n' +
|
|
'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAwhomANFrPRLVBCc96H7b\n' +
|
|
'gU6/6iWWljX05N6KivgxZ0FF/WovbwDWJ6xkm4qd9GsqVc2rvCZgqR7kdZmAITPR\n' +
|
|
'mU1c3JZ96qYu2qXQKpXrcEbxcIxVn3bY/GJCbXuUJWQoCHTehGC27zFUmk6TkuWj\n' +
|
|
'uOdV6KOXXIgA70/WThk9KkgdOXy+UF8n7rbpw9om3otJjtqZHdZBlbFwd+OP6wAp\n' +
|
|
'zcdron9pO55KvM0CvYC80BzwLNp9a3ym/r/GTLRXABaiLNBpZ/A8gtQAnjZVtUWJ\n' +
|
|
'fi4veHZHkCm9bXXTE2V8kTqOgxmNvFjqmezy6vz12T5BQyQkRJwjeY9WmEkNHSXM\n' +
|
|
'XrGvrcm8Hducdknrw20rki5sIHRObF0WwxL6a15UZXVoXxMEeH06GFdIJSjLjTF2\n' +
|
|
'0/Pbadj7Z8SoKyKWQxFB21MjX7gr+Da7HVFnH6lxLdoGlmYcxkOOeCYiv+9/aAMS\n' +
|
|
'Ebi/Vb6gfPPhMLU5WJ/+yx2OPP65CZolAdhYFJUw4REpHPjimcSt+3bz/o/1bvX0\n' +
|
|
'FYjOmkNooS+HMTjFYQ7rd77j8JNEHlUsU2Y1vCZi02cOgY/kfI+zk6gD9RzTKW57\n' +
|
|
'VdigzKQLVYxKd04KeNvoU0WpKf0h/opHXj3bgaX1gsZdml2xJM9+aIQyQDewU8Bb\n' +
|
|
'Izobr4Dn4kDfpIDrVAgMFxkCAwEAAQ==\n' +
|
|
'-----END PUBLIC KEY-----\n',
|
|
privateKey:
|
|
'-----BEGI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5EguO0U+adyPmGMjO4n4r2gfu0gjFfCexp5Myhqsnw\n' +
|
|
'uQKCAQAXTKkWEK9ZzrVtJketgFc0hYhhGJvkZkxUdv4FIcu+Em1h3F/alTiJWELx\n' +
|
|
'Nmhfp5pX+8+QoIZZCCh2DN/I1tvM+EQMe0fEsIQEmhjGMewvdzag7csiyY+ZfW/c\n' +
|
|
'79anhctd7FAnduEHPaf2qeKuZqmGIdujLopPWm5lRcJHNg1hEizB4j7GfNpIXLyu\n' +
|
|
'CgL9ZyBmFcvezH3ICVwLnOmlcAGd53YNxMnm1EIjE6fpi1nulhvhlROEe/916bSu\n' +
|
|
'q6NN56lB+Jjiy5knckBgmm0TIfCHOrzdNl2sSuuYu0snHLiosyaj/LLJx3XBkYJ8\n' +
|
|
'eV9exLNnmeJUxNAQY7m0wKVqU7va\n' +
|
|
'-----END PRIVATE KEY-----\n',
|
|
},
|
|
{
|
|
url: 'https://127.0.0.1:3030', // yep, can have two servers at the same address
|
|
publicKey:
|
|
'-----BEGIN PUBLIC KEY-----\n' +
|
|
'MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEA4TMSbTy+S+iSS2v3Alj0\n' +
|
|
'GW6uUtPkvAXg/MXSrnnQ/7Ut7zDdN+9A1MQ9/Xdc+N375FLAYfbDl7SnZKh/3f1D\n' +
|
|
'epfXkxj6xXWi5NWcU3AhZZI56Q4Dix/uWdCp+GtJJ7MQViLOb1YlsaCDVab1UKvQ\n' +
|
|
'oSC+jVboRgwSY9CAuqWwlWJsVzMJA62I4ZHbSK/tzPZcEu/QSqtBYeF0tI/wM5V6\n' +
|
|
'MJhyoOXbO2BsJ+iDdTM+A5FoV0kcFjrVBqIt+2xEjvMGH+krcSB1suxO2wgHZzRm\n' +
|
|
'jlVmEUZOc5JYRaMFMGlpN4VVIMUqE5orC0bPQOJ82DSIeRBECUixMlTeonwuOec6\n' +
|
|
'rSMlfSiC8b6wPA4pdQVJwvYRhDqgQfT8/2uywSI0+AbtF0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u+RSz/IveeLI15EL+JZ6/x+jvHp3y1j6itm\n' +
|
|
'2RwOcbL8uAEAQf4+OMkGMYCow0DYAvfNeMo1ScWvAoIBAQDaqjdkQC4nl4B+tikQ\n' +
|
|
'dqlMpzPDdf59GeZVU93NRmKDLFej4KqqUofBvnNle5ilb0EqSezHvxWL/TgsTkeX\n' +
|
|
'jsW9JbbxH9djWns57AjJ7PdNMf7pVBqk6HhHKlkiM9myJb3a2U+aeNsyxsHgQDGV\n' +
|
|
'qajApwqvp9LJPAfUsCGMdWi98pYrw6vgcU5WxB9piYLVRpGUNJI7kaEZHAM15p8q\n' +
|
|
'H5Q4q7V/SyIWI9c1cjmB/8ALN7JtvxLVBf6tqb/nn6LIYLLfbz3kYHJAKkbo9SDN\n' +
|
|
'IExIU5TBXVRzut4pczq9MSiTJlJw2N8TLTcQL8J5GBz2T/VAzai23ZbSsICne/7n\n' +
|
|
'yPG7AoIBAQCFZDxWSzSblKHB9+uBccb+k8GKV72SOsNG/XGabb5aziOJ6aCHGp3E\n' +
|
|
'pIOpx4VSy+esqQYnsvX6OPYaBOoASshBf5J/8WEe55o9wQ6MmZQyjLKp7yuVK/vS\n' +
|
|
'qRij7L0l+fyhWLVKupyPzHKX995IP+Crb+YtRHDB4pMBAvVYB8wikvfaCUEzn7JU\n' +
|
|
'NMOfm4oDwDjb/np41pXhfWdYd4QoBRbKLCxYO/lpAQu0lsjjgEXMaoEiaQZqLT4k\n' +
|
|
'SZbKWECdfZ9JItwp6bIRFJdvjXXmYI2Qu1s+oOQ3kc4BIH0JlBPIdq7PhAI1Y3hN\n' +
|
|
'E5RjXjp7uZ4G2HktIhMs2HXvowUtqg0S\n' +
|
|
'-----END PRIVATE KEY-----\n',
|
|
}
|
|
];
|
|
|
|
// for (let i = 0; i < 11; ++i) { // copy the last config 11 more times to test multiple connections to same server
|
|
// configs.push(configs[configs.length - 1]);
|
|
// }
|
|
|
|
(async () => {
|
|
try {
|
|
await DBCache.connect();
|
|
await DBCache.reset();
|
|
await DBCache.init();
|
|
} catch (e) {
|
|
LOG.error(e);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
await DBCache.queueTransaction(async () => {
|
|
for (let config of configs) {
|
|
let identityId = await DBCache.addIdentity(config.publicKey, config.privateKey);
|
|
|
|
LOG.debug('Added identity#' + identityId);
|
|
|
|
let guildId = await DBCache.addServer(config.url);
|
|
|
|
LOG.debug('Added server#' + guildId);
|
|
|
|
await DBCache.addServerIdentity(guildId, identityId);
|
|
}
|
|
|
|
});
|
|
} catch (e) {
|
|
LOG.error('Unable to setup cache', e);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
let serverConfigs = await DBCache.getServerConfigs();
|
|
LOG.info('Got server configs: ', { serverConfigs });
|
|
} catch (e) {
|
|
LOG.error('unable to get server configs', e);
|
|
return;
|
|
}
|
|
})(); |