From e3f11eea43aa4d1fe7fb302c2a039fa2d2c1e902 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 5 Oct 2020 00:10:02 +0530 Subject: [PATCH] Fixes TTL for domains + more constants --- scripts/register-domains.js | 3 ++- utils/constants.js | 12 +++++++++++- utils/domain-service.js | 10 +++------- utils/register.test.js | 22 +++++++++++----------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/scripts/register-domains.js b/scripts/register-domains.js index 0d53b5e67..8b1771f4f 100644 --- a/scripts/register-domains.js +++ b/scripts/register-domains.js @@ -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); diff --git a/utils/constants.js b/utils/constants.js index bd2de0d05..18ff9dd24 100644 --- a/utils/constants.js +++ b/utils/constants.js @@ -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', }; diff --git a/utils/domain-service.js b/utils/domain-service.js index a3d997a8d..2de6a2e07 100644 --- a/utils/domain-service.js +++ b/utils/domain-service.js @@ -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, }); diff --git a/utils/register.test.js b/utils/register.test.js index da83e55aa..cd4a74551 100644 --- a/utils/register.test.js +++ b/utils/register.test.js @@ -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}` }, ]); });