Fixes TTL for domains + more constants

This commit is contained in:
Akshay Nair
2020-10-05 00:10:02 +05:30
parent b3059611c0
commit e3f11eea43
4 changed files with 27 additions and 20 deletions
+2 -1
View File
@@ -1,5 +1,5 @@
const R = require('ramda');
const { VALID_RECORD_TYPES, NC_DOMAIN } = require('../utils/constants');
const { VALID_RECORD_TYPES, NC_DOMAIN, TTL } = require('../utils/constants');
const { domainService: domain } = require('../utils/domain-service');
const { getDomains } = require('../utils/domain');
@@ -13,6 +13,7 @@ const toHostList = R.chain(data => {
HostName: data.name,
RecordType: recordType,
Address: url,
TTL,
}))
, rs);
+11 -1
View File
@@ -1,4 +1,14 @@
const path = require('path');
require('dotenv').config({ path: path.resolve('.env.sandbox') });
const { NC_USER, NC_API_KEY, NC_DOMAIN } = process.env;
module.exports = {
VALID_RECORD_TYPES: ['CNAME', 'A', 'ALIAS', 'URL'],
NC_DOMAIN: 'booboo.xyz',
NC_DOMAIN: NC_DOMAIN || 'booboo.xyz',
NC_USER: NC_USER || 'test',
NC_API_KEY: NC_API_KEY || 'fake_key',
ENV: 'sandbox',
TTL: 5*60,
IP_ADDRESS: '100.100.100.100',
};
+3 -7
View File
@@ -1,18 +1,14 @@
const R = require('ramda');
const Namecheap = require('@rqt/namecheap');
const { NC_DOMAIN, NC_USER, NC_API_KEY, ENV, IP_ADDRESS } = require('../utils/constants');
const path = require('path');
require('dotenv').config({ path: path.resolve('.env.sandbox') });
const IS_SANDBOX = true;
const { NC_USER, NC_API_KEY, NC_DOMAIN } = process.env;
const TTL = 5*60;
const IS_SANDBOX = ENV === 'sandbox';
const getDomainService = ({ Namecheap }) => {
const nc = new Namecheap({
user: NC_USER,
key: NC_API_KEY,
ip: '103.226.85.9',
ip: IP_ADDRESS,
sandbox: IS_SANDBOX,
});
+11 -11
View File
@@ -1,5 +1,5 @@
const { toHostList } = require('../scripts/register-domains');
const { NC_DOMAIN } = require('../utils/constants');
const { NC_DOMAIN, TTL } = require('../utils/constants');
describe('toHostList', () => {
it('should flatten domain data to list of hosts (without https)', () => {
@@ -10,11 +10,11 @@ describe('toHostList', () => {
]);
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' }
{ HostName: 'akshay', RecordType: 'CNAME', Address: 'phenax.github.io', TTL },
{ HostName: 'foobar', RecordType: 'CNAME', Address: 'v.io', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '1.2.3.4', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '5.6.3.2', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '1.2.31.1', TTL },
]);
});
@@ -26,12 +26,12 @@ describe('toHostList', () => {
]);
expect(res).toEqual([
{ HostName: 'akshay', RecordType: 'CNAME', Address: 'phenax.github.io' },
{ HostName: 'akshay', RecordType: 'CNAME', Address: 'phenax.github.io', TTL },
{ 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: 'foobar', RecordType: 'CNAME', Address: 'v.io', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '1.2.3.4', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '5.6.3.2', TTL },
{ HostName: 'xx', RecordType: 'A', Address: '1.2.31.1', TTL },
{ HostName: 'xx', RecordType: 'URL', Address: `https://xx.${NC_DOMAIN}` },
]);
});