mirror of
https://github.com/tiennm99/is-a-dev.git
synced 2026-09-08 22:20:16 +00:00
Adds domain data to host list conversion
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
const R = require('ramda');
|
||||
const { VALID_RECORD_TYPES, NC_DOMAIN } = require('../utils/constants');
|
||||
const { domainService: domain } = require('../utils/domain-service');
|
||||
const { getDomains } = require('../utils/domain');
|
||||
|
||||
const getRecords = R.compose(R.toPairs, R.pick(VALID_RECORD_TYPES));
|
||||
|
||||
const toHostList = R.chain(data => {
|
||||
const rs = getRecords(data.record);
|
||||
|
||||
const records = R.chain(([recordType, urls]) =>
|
||||
urls.map(url => ({
|
||||
HostName: data.name,
|
||||
RecordType: recordType,
|
||||
Address: url,
|
||||
}))
|
||||
, rs);
|
||||
|
||||
return !data.forceHttps ? records : records.concat([
|
||||
{ HostName: data.name, RecordType: 'URL', Address: `https://${data.name}.${NC_DOMAIN}` },
|
||||
]);
|
||||
});
|
||||
|
||||
const registerDomains = async ({ domainService, getDomains }) => {
|
||||
const domains = await getDomains().then(toHostList);
|
||||
};
|
||||
|
||||
const main = () => {
|
||||
console.log('Running cli');
|
||||
};
|
||||
|
||||
if (require.main === module) {
|
||||
main();
|
||||
} else {
|
||||
module.exports = { toHostList, registerDomains };
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
VALID_RECORD_TYPES: ['CNAME', 'A', 'ALIAS', 'URL'],
|
||||
NC_DOMAIN: 'booboo.xyz',
|
||||
};
|
||||
@@ -34,9 +34,7 @@ const getDomainService = ({ Namecheap }) => {
|
||||
return list;
|
||||
};
|
||||
|
||||
const setHosts = hosts => {
|
||||
return nc.dns.setHosts(NC_DOMAIN, hosts);
|
||||
};
|
||||
const setHosts = hosts => nc.dns.setHosts(NC_DOMAIN, hosts);
|
||||
|
||||
const getHostKey = host => `${host.HostName}--${host.RecordType}`;
|
||||
const toHostMap = hosts => hosts.reduce((acc, host) => {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
const { toHostList } = require('../scripts/register-domains');
|
||||
const { NC_DOMAIN } = require('../utils/constants');
|
||||
|
||||
describe('toHostList', () => {
|
||||
it('should flatten domain data to list of hosts (without https)', () => {
|
||||
const res = toHostList([
|
||||
{ name: 'akshay', forceHttps: false, record: { CNAME: ['phenax.github.io'] } },
|
||||
{ name: 'foobar', forceHttps: false, record: { CNAME: ['v.io'] } },
|
||||
{ name: 'xx', forceHttps: false, record: { A: ['1.2.3.4', '5.6.3.2', '1.2.31.1'] } },
|
||||
]);
|
||||
|
||||
expect(res).toEqual([
|
||||
{ HostName: 'akshay', RecordType: 'CNAME', Address: 'phenax.github.io' },
|
||||
{ HostName: 'foobar', RecordType: 'CNAME', Address: 'v.io' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '1.2.3.4' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '5.6.3.2' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '1.2.31.1' }
|
||||
]);
|
||||
});
|
||||
|
||||
it('should flatten domain data to list of hosts (with https)', () => {
|
||||
const res = toHostList([
|
||||
{ name: 'akshay', forceHttps: true, record: { CNAME: ['phenax.github.io'] } },
|
||||
{ name: 'foobar', forceHttps: false, record: { CNAME: ['v.io'] } },
|
||||
{ name: 'xx', forceHttps: true, record: { A: ['1.2.3.4', '5.6.3.2', '1.2.31.1'] } },
|
||||
]);
|
||||
|
||||
expect(res).toEqual([
|
||||
{ HostName: 'akshay', RecordType: 'CNAME', Address: 'phenax.github.io' },
|
||||
{ HostName: 'akshay', RecordType: 'URL', Address: `https://akshay.${NC_DOMAIN}` },
|
||||
{ HostName: 'foobar', RecordType: 'CNAME', Address: 'v.io' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '1.2.3.4' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '5.6.3.2' },
|
||||
{ HostName: 'xx', RecordType: 'A', Address: '1.2.31.1' },
|
||||
{ HostName: 'xx', RecordType: 'URL', Address: `https://xx.${NC_DOMAIN}` },
|
||||
]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user