diff --git a/.env b/.env index f87d42da0..26270e769 100644 --- a/.env +++ b/.env @@ -1,4 +1,5 @@ -NC_USER=xxx -NC_API_KEY=xxxxxxxxxxxxxxx -NC_DOMAIN=domain.com -IP_ADDRESS=100.100.100.100 +DOMAIN_USER=username +DOMAIN_API_KEY=apikey +DOMAIN_API_HOST=api-example.com +DOMAIN_API_PORT=2087 +DOMAIN_DOMAIN=example.com diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml index e8519241f..6ff9fe1cd 100644 --- a/.github/workflows/checks.yml +++ b/.github/workflows/checks.yml @@ -8,7 +8,11 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: borales/actions-yarn@v2.0.0 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + - name: Installing dependencies + uses: borales/actions-yarn@v2.0.0 with: cmd: install - name: Running tests diff --git a/.github/workflows/publish-records.yml b/.github/workflows/publish-records.yml index 17bb7bdc0..f7b49f627 100644 --- a/.github/workflows/publish-records.yml +++ b/.github/workflows/publish-records.yml @@ -10,10 +10,11 @@ jobs: env: CI: '1' ENV: production - NC_USER: ${{ secrets.NC_USER }} - NC_API_KEY: ${{ secrets.NC_API_KEY }} - NC_DOMAIN: ${{ secrets.NC_DOMAIN }} - IP_ADDRESS: ${{ secrets.IP_ADDRESS }} + DOMAIN_USER: ${{ secrets.DOMAIN_USER }} + DOMAIN_API_KEY: ${{ secrets.DOMAIN_API_KEY }} + DOMAIN_API_HOST: ${{ secrets.DOMAIN_API_HOST }} + DOMAIN_API_PORT: ${{ secrets.DOMAIN_API_PORT }} + DOMAIN_DOMAIN: ${{ secrets.DOMAIN_DOMAIN }} steps: - uses: actions/checkout@v2 - uses: borales/actions-yarn@v2.0.0 diff --git a/API.md b/API.md index 47d125c53..746f953f1 100644 --- a/API.md +++ b/API.md @@ -17,8 +17,7 @@ "email": "any@email" }, "record": { - "CNAME": "github-username.github.io", - "URL": "https://your-domain.is-a.dev" + "CNAME": "github-username.github.io" } } ``` @@ -63,12 +62,11 @@ This is a link to your website repository or your github account. This is purely ### record (required) This is where you specify how you want to link to your server/webpage. -Currently, only `CNAME`, `ALIAS`, `A`, `URL` record types are supported. +Currently, only `CNAME`, `A`, `URL` record types are supported. Here's a few different use cases for the given record types - -* **CNAME/ALIAS** -Replace CNAME with ALIAS for alias record type +* **CNAME** ```json { "record": { @@ -100,13 +98,3 @@ Replace CNAME with ALIAS for alias record type } ``` -* **Force HTTPS on your CNAME (or ALIAS or A) record** -```json -{ - "record": { - "CNAME": "username.github.io", - "URL": "https://your-domain.is-a.dev" - } -} -``` - diff --git a/domains/aashutosh.json b/domains/aashutosh.json new file mode 100644 index 000000000..2399d7be0 --- /dev/null +++ b/domains/aashutosh.json @@ -0,0 +1,11 @@ +{ + "description": "Aashutosh Rathi's Space on Web", + "owner": { + "username": "aashutoshrathi", + "email": "me@aashutosh.dev" + }, + "record": { + "CNAME": "aashutosh.dev", + "URL": "https://aashutosh.is-a.dev" + } +} diff --git a/domains/abhay.json b/domains/abhay.json new file mode 100644 index 000000000..1e722675c --- /dev/null +++ b/domains/abhay.json @@ -0,0 +1,12 @@ +{ + "description": "Abhay's portfolio website", + "repo": "https://github.com/daggron/daggron.github.io", + "owner": { + "username": "Daggron", + "email": "returnofking04@gmail.com" + }, + "record": { + "CNAME": "codeinator.me", + "URL": "https://abhay.is-a.dev" + } +} \ No newline at end of file diff --git a/domains/abhishek.json b/domains/abhishek.json new file mode 100644 index 000000000..22545cd82 --- /dev/null +++ b/domains/abhishek.json @@ -0,0 +1,12 @@ +{ + "description": "Abhishek's personal website", + "repo": "https://github.com/nullpointxr", + "owner": { + "username": "nullpointxr", + "email": "abhishek.sankar.in@protonmail.com" + }, + "record": { + "CNAME": "nullpointxr.github.io", + "URL": "https://abhishek.is-a.dev" + } +} diff --git a/domains/abishek.json b/domains/abishek.json new file mode 100644 index 000000000..3fde17249 --- /dev/null +++ b/domains/abishek.json @@ -0,0 +1,12 @@ +{ + "description": "Abishek's portfolio website", + "repo": "https://github.com/vj-abishek/vj-abishek.github.io", + "owner": { + "username": "vj-abishek", + "email": "abigosearch@gmail.com" + }, + "record": { + "CNAME": "vj-abishek.github.io", + "URL": "https://abishek.is-a.dev" + } +} diff --git a/domains/adarshs.json b/domains/adarshs.json new file mode 100644 index 000000000..47670879b --- /dev/null +++ b/domains/adarshs.json @@ -0,0 +1,12 @@ +{ + "description": "The portfolio of Adarsh S", + "repo": "https://github.com/adarshsuresh07", + "owner": { + "username": "adarshsuresh07", + "email": "adarshsuresh@cet.ac.in" + }, + "record": { + "CNAME":"adarshsuresh07.github.io", + "URL": "https://adarshs.is-a.dev" + } +} diff --git a/domains/akshay-ashok.json b/domains/akshay-ashok.json new file mode 100644 index 000000000..132781ef9 --- /dev/null +++ b/domains/akshay-ashok.json @@ -0,0 +1,12 @@ +{ + "description": "Akshay Ashok has a is a dev domain", + "repo": "https://github.com/Akshay090/akshay090.github.io", + "owner": { + "username": "Akshay090", + "email": "aks28id@gmail.com" + }, + "record": { + "CNAME": "akshay090.github.io", + "URL": "https://akshay-ashok.is-a.dev" + } +} diff --git a/domains/alan.json b/domains/alan.json new file mode 100644 index 000000000..eb0a1bd31 --- /dev/null +++ b/domains/alan.json @@ -0,0 +1,12 @@ +{ + "description": "Alan's personal developer website", + "repo": "https://github.com/schirrel", + "owner": { + "username": "schirrel", + "email": "alan@schirrel.dev" + }, + "record": { + "CNAME": "schirrel.dev", + "URL": "https://alan.is-a.dev" + } +} diff --git a/domains/alestor123.json b/domains/alestor123.json new file mode 100644 index 000000000..b9ae0804e --- /dev/null +++ b/domains/alestor123.json @@ -0,0 +1,12 @@ +{ + "description": "A Mortal Web Developer With Immortal Dreams", + "repo": "https://github.com/alestor123/alestor123.github.io", + "owner": { + "username": "alestor123", + "email": "alestoraldous@gmail.com" + }, + "record": { + "CNAME": "alestor123.github.io", + "URL": "https://alestor123.is-a.dev" + } +} diff --git a/domains/alexjoseph.json b/domains/alexjoseph.json new file mode 100644 index 000000000..01c7cc49e --- /dev/null +++ b/domains/alexjoseph.json @@ -0,0 +1,12 @@ +{ + "description": "This is my first githib page", + "repo": "https://github.com/alexkjoseph/alexkjoseph.github.io", + "owner": { + "username": "alexkjoseph", + "email": "aj71563@gmail.com" + }, + "record": { + "CNAME": "alexkjoseph.github.io", + "URL": "https://alexjoseph.is-a.dev" + } +} diff --git a/domains/anoop.json b/domains/anoop.json new file mode 100644 index 000000000..53c1c378c --- /dev/null +++ b/domains/anoop.json @@ -0,0 +1,12 @@ +{ + "description": "Anoop's blog", + "repo": "https://gitlab.com/anoopmsivadas/anoopmsivadas.gitlab.io", + "owner": { + "username": "anoopmsivadas", + "email": "anoopms@disroot.org" + }, + "record": { + "CNAME": "anoopmsivadas.gitlab.io", + "URL": "https://anoop.is-a.dev" + } +} diff --git a/domains/arya.json b/domains/arya.json new file mode 100644 index 000000000..7510a71e2 --- /dev/null +++ b/domains/arya.json @@ -0,0 +1,12 @@ +{ + "description": "Arya Vinodan's Website", + "repo": "https://github.com/aryavinodan", + "owner": { + "username": "aryavinodan", + "email": "aryavinodan2000@gmail.com" + }, + "record": { + "CNAME": "aryavinodan2000.github.io", + "URL": "https://arya.is-a.dev" + } +} diff --git a/domains/ashish.json b/domains/ashish.json new file mode 100644 index 000000000..a1d6e2498 --- /dev/null +++ b/domains/ashish.json @@ -0,0 +1,12 @@ +{ + "description": "Ashish's personal developer website", + "repo": "https://github.com/ashiishme", + "owner": { + "username": "ashiishme", + "email": "contact@ashiish.me" + }, + "record": { + "CNAME": "ashiish.me", + "URL": "https://ashish.is-a.dev" + } +} diff --git a/domains/bhadra.json b/domains/bhadra.json new file mode 100644 index 000000000..69b9a8fd1 --- /dev/null +++ b/domains/bhadra.json @@ -0,0 +1,12 @@ +{ + "description": "Personal Website", + "repo": "https://github.com/BhadraJayakumarSandhya/BhadraJayakumarSandhya.github.io", + "owner": { + "username": "BhadraJayakumarSandhya", + "email": "tomjerryparu@gmail.com" + }, + "record": { + "CNAME": "BhadraJayakumarSandhya.github.io", + "URL": "https://bhadra.is-a.dev" + } +} diff --git a/domains/bradley.json b/domains/bradley.json index d2137d61b..29a3966c1 100644 --- a/domains/bradley.json +++ b/domains/bradley.json @@ -5,6 +5,6 @@ "email": "bradley73@gmail.com" }, "record": { - "ALIAS": "bradleyholbrook.com" + "CNAME": "bradleyholbrook.com" } } diff --git a/domains/brandon.json b/domains/brandon.json new file mode 100644 index 000000000..b533a756a --- /dev/null +++ b/domains/brandon.json @@ -0,0 +1,12 @@ +{ + "description": "Brandons's personal developer website", + "repo": "https://github.com/b-hexsoul", + "owner": { + "username": "b-hexsoul", + "email": "brandon.hexsel@gmail.com" + }, + "record": { + "CNAME": "b-hexsoul.github.io", + "URL": "https://brandon.is-a.dev" + } +} diff --git a/domains/dan-habot.json b/domains/dan-habot.json new file mode 100644 index 000000000..c58d894fd --- /dev/null +++ b/domains/dan-habot.json @@ -0,0 +1,12 @@ +{ + "description": "Fullstack web & mobile dev, quality assurance, automation, reverse engineering, and flexible", + "repo": "https://github.com/danhab99/danhab99.github.io", + "owner": { + "username": "danhab99", + "email": "dan.habot@gmail.com" + }, + "record": { + "CNAME": "danhab99.github.io", + "URL": "https://dan-habot.is-a.dev" + } +} diff --git a/domains/dino.json b/domains/dino.json new file mode 100644 index 000000000..af974a8de --- /dev/null +++ b/domains/dino.json @@ -0,0 +1,12 @@ +{ + "description": "Vitor Dino is a front-end developer and ui designer", + "repo": "https://github.com/vitordino", + "owner": { + "username": "vitordino", + "email": "me@vitordino.com" + }, + "record": { + "CNAME": "vitordino.com", + "URL": "https://dino.is-a.dev" + } +} diff --git a/domains/eric.json b/domains/eric.json new file mode 100644 index 000000000..ab4967530 --- /dev/null +++ b/domains/eric.json @@ -0,0 +1,12 @@ +{ + "description": "Eric's website and blog", + "repo": "https://github.com/yurrriq", + "owner": { + "username": "yurrriq", + "email": "eric@ericb.me" + }, + "record": { + "CNAME": "yurrriq.github.io", + "URL": "https://eric.is-a.dev" + } +} diff --git a/domains/ezedinff.json b/domains/ezedinff.json new file mode 100644 index 000000000..8a10dd6df --- /dev/null +++ b/domains/ezedinff.json @@ -0,0 +1,12 @@ +{ + "description": "Ezedin's personal developer website", + "repo": "https://github.com/ezedinff", + "owner": { + "username": "ezedinff", + "email": "ezedin.fedlu@gmail.com" + }, + "record": { + "CNAME": "black-horse-coder-blog.vercel.app", + "URL": "https://ezedin.is-a.dev" + } +} diff --git a/domains/farzan.json b/domains/farzan.json new file mode 100644 index 000000000..535308431 --- /dev/null +++ b/domains/farzan.json @@ -0,0 +1,12 @@ +{ + "description": "Farzan F A is a Dev", + "repo": "https://github.com/Farzanfa/Farzanfa.github.io", + "owner": { + "username": "farzanfa", + "email": "farzanfa007@gmail.com" + }, + "record": { + "CNAME": "Farzanfa.github.io", + "URL": "https://farzan.is-a.dev" + } +} diff --git a/domains/gaurav.json b/domains/gaurav.json new file mode 100644 index 000000000..4a5f346c0 --- /dev/null +++ b/domains/gaurav.json @@ -0,0 +1,12 @@ +{ + "description": "Gaurav Tewari", + "repo": "https://github.com/tewarig/tewarig.github.io", + "owner": { + "username": "Gaurav", + "email": "gauravtewari111@gmail.com" + }, + "record": { + "CNAME": "tewarig.github.io", + "URL": "https://gaurav.is-a.dev" + } +} diff --git a/domains/georgekaran.json b/domains/georgekaran.json new file mode 100644 index 000000000..ae89517f2 --- /dev/null +++ b/domains/georgekaran.json @@ -0,0 +1,11 @@ +{ + "description": "George Karan - Personal Page", + "repo": "https://github.com/georgekaran", + "owner": { + "username": "georgekaran", + "email": "georgekaran12@gmail.com" + }, + "record": { + "URL": "https://georgekaran.com" + } +} diff --git a/domains/gkr.json b/domains/gkr.json new file mode 100644 index 000000000..fed031e3c --- /dev/null +++ b/domains/gkr.json @@ -0,0 +1,9 @@ +{ + "owner": { + "username": "gautamkrishnar", + "email": "hello@gautamkrishnar.com" + }, + "record": { + "A": ["185.224.138.125"] + } +} diff --git a/domains/gokul.json b/domains/gokul.json new file mode 100644 index 000000000..7032658d2 --- /dev/null +++ b/domains/gokul.json @@ -0,0 +1,12 @@ +{ + "description": "Personal Page", + "repo": "https://github.com/gkdskp/gkdskp.github.io", + "owner": { + "username": "gkdskp", + "email": "gokuldskp@gmail.com" + }, + "record": { + "CNAME": "gkdskp.github.io", + "URL": "https://gokul.is-a.dev" + } +} diff --git a/domains/govind.json b/domains/govind.json new file mode 100644 index 000000000..32732a21d --- /dev/null +++ b/domains/govind.json @@ -0,0 +1,12 @@ +{ + "description": "Govind's personal developer website", + "repo": "https://github.com/govind-shenoy", + "owner": { + "username": "govind-shenoy", + "email": "govindvshenoy@gmail.com" + }, + "record": { + "CNAME": "govind-shenoy.github.io", + "URL": "https://govind.is-a.dev" + } +} diff --git a/domains/jacob.json b/domains/jacob.json new file mode 100644 index 000000000..230214cee --- /dev/null +++ b/domains/jacob.json @@ -0,0 +1,12 @@ +{ + "description": "My cool dev", + "repo": "https://github.com/jacob13400/jacob13400.github.io", + "owner": { + "username": "jacob13400", + "email": "jacob13400@gmail.com" + }, + "record": { + "CNAME": "jacob13400.github.io", + "URL": "https://jacob.is-a.dev" + } +} diff --git a/domains/justin.json b/domains/justin.json new file mode 100644 index 000000000..c2fb26afa --- /dev/null +++ b/domains/justin.json @@ -0,0 +1,12 @@ +{ + "description": "My personal Page", + "repo": "https://github.com/justinjohnymathew/justinjohnymathew.github.io", + "owner": { + "username": "justinjohnymathew", + "email": "justinjohny.jj@gmail.com" + }, + "record": { + "CNAME": "justinjohnymathew.github.io", + "URL": "https://justin.is-a.dev" + } +} diff --git a/domains/kiss.json b/domains/kiss.json new file mode 100644 index 000000000..9f04710c2 --- /dev/null +++ b/domains/kiss.json @@ -0,0 +1,10 @@ +{ + "owner": { + "username": "filipekiss", + "email": "filipe@kiss.ink" + }, + "record": { + "CNAME": "filipe.kiss.ink", + "URL": "https://kiss.is-a.dev" + } +} diff --git a/domains/mark.json b/domains/mark.json new file mode 100644 index 000000000..8c79922a8 --- /dev/null +++ b/domains/mark.json @@ -0,0 +1,12 @@ + +{ + "description": "Makr Davydov is a Developer!", + "repo": "https://github.com/markrity", + "owner": { + "username": "markrity", + "email": "markrity@gmail.com" + }, + "record": { + "URL": "https://www.linkedin.com/in/davydovmark/" + } +} diff --git a/domains/matheus.json b/domains/matheus.json new file mode 100644 index 000000000..d5f7196f5 --- /dev/null +++ b/domains/matheus.json @@ -0,0 +1,12 @@ +{ + "description": "Matheus Costa's personal developer website", + "repo": "https://github.com/mthcsta/mthcsta.github.io", + "owner": { + "username": "mthcsta", + "email": "matheuscosta.dev@yahoo.com" + }, + "record": { + "CNAME": "mthcsta.github.io", + "URL": "https://matheus.is-a.dev" + } +} diff --git a/domains/mpy.json b/domains/mpy.json new file mode 100644 index 000000000..474c3889b --- /dev/null +++ b/domains/mpy.json @@ -0,0 +1,12 @@ +{ + "description": "Mike Perry Y Attara's personal website", + "repo": "https://github.com/mikeattara", + "owner": { + "username": "mikeattara", + "email": "mpyebattara@gmail.com" + }, + "record": { + "CNAME": "mikeattara.github.io", + "URL": "https://mpy.is-a.dev" + } +} \ No newline at end of file diff --git a/domains/nimish.json b/domains/nimish.json new file mode 100644 index 000000000..a8b343dec --- /dev/null +++ b/domains/nimish.json @@ -0,0 +1,12 @@ +{ + "description": "Nimish's Engineering Diary", + "repo": "https://github.com/nimish-gupta/blog", + "owner": { + "username": "nimish-gupta", + "email": "gnimish03@gmail.com" + }, + "record": { + "CNAME": "nimish-gupta.dev", + "URL": "https://nimish.is-a.dev" + } +} diff --git a/domains/owain.json b/domains/owain.json new file mode 100644 index 000000000..09020668a --- /dev/null +++ b/domains/owain.json @@ -0,0 +1,11 @@ +{ + "description": "Owain's Website", + "owner": { + "username": "owjothegreat", + "email": "owain.jones74@gmail.com" + }, + "record": { + "CNAME": "0wain.xyz", + "URL": "https://owain.is-a.dev" + } +} diff --git a/domains/proghead00.json b/domains/proghead00.json new file mode 100644 index 000000000..e647ed5d9 --- /dev/null +++ b/domains/proghead00.json @@ -0,0 +1,12 @@ +{ + "description": "Susnata's is.a.dev domain!", + "repo": "https://github.com/proghead00/proghead00.github.io", + "owner": { + "username": "proghead00", + "email": "susnata00@gmail.com" + }, + "record": { + "CNAME": "proghead00.github.io", + "URL": "https://proghead00.is-a.dev" + } +} diff --git a/domains/reed.json b/domains/reed.json new file mode 100644 index 000000000..5f70ceda1 --- /dev/null +++ b/domains/reed.json @@ -0,0 +1,11 @@ +{ + "repo": "https://github.com/reed-jones", + "owner": { + "username": "reed-jones", + "email": "reedjones@reedjones.com" + }, + "record": { + "CNAME": "reedjones.com", + "URL": "https://reed.is-a.dev" + } +} diff --git a/domains/roy.json b/domains/roy.json new file mode 100644 index 000000000..678134f47 --- /dev/null +++ b/domains/roy.json @@ -0,0 +1,12 @@ +{ + "description": "Roy's portfolio website", + "repo": "https://github.com/rcrj/rcrj.github.io", + "owner": { + "username": "rcrj", + "email": "rcrj95@gmail.com" + }, + "record": { + "CNAME": "rcrj.github.io", + "URL": "https://roy.is-a.dev" + } +} diff --git a/domains/rwithik.json b/domains/rwithik.json new file mode 100644 index 000000000..6615c5d68 --- /dev/null +++ b/domains/rwithik.json @@ -0,0 +1,12 @@ +{ + "description": "Rwithik's Website", + "repo": "https://github.com/rwithik/rwithik.github.io", + "owner": { + "username": "rwithik", + "email": "rwithik@gmail.com" + }, + "record": { + "CNAME": "rwithik.github.io", + "URL": "https://rwithik.is-a.dev" + } +} diff --git a/domains/saisandeepvaddi.json b/domains/saisandeepvaddi.json new file mode 100644 index 000000000..584f761ae --- /dev/null +++ b/domains/saisandeepvaddi.json @@ -0,0 +1,10 @@ +{ + "description": "Sai Sandeep Vaddi's website", + "owner": { + "username": "saisandeepvaddi", + "email": "saisandeepvaddi@gmail.com" + }, + "record": { + "A": ["104.198.14.52"] + } +} diff --git a/domains/savio.json b/domains/savio.json new file mode 100644 index 000000000..0bdea966a --- /dev/null +++ b/domains/savio.json @@ -0,0 +1,12 @@ + { + "description": "Savio Martin is a Dev", + "repo": "https://github.com/saviomartin/register", + "owner": { + "username": "saviomartin", + "email": "saviomartin2020@gmail.com" + }, + "record": { + "CNAME": "saviomartin.github.io", + "URL": "https://savio.is-a.dev" + } +} diff --git a/domains/shenjunru.json b/domains/shenjunru.json new file mode 100644 index 000000000..d521ea054 --- /dev/null +++ b/domains/shenjunru.json @@ -0,0 +1,12 @@ +{ + "description": "Shen Junru is a Dev", + "repo": "https://github.com/shenjunru/is-a-dev", + "owner": { + "username": "shenjunru", + "email": "shenjunru@gmail.com" + }, + "record": { + "CNAME": "shenjunru.github.io", + "URL": "https://shenjunru.is-a.dev" + } +} diff --git a/domains/shibiliya.json b/domains/shibiliya.json new file mode 100644 index 000000000..4c3104986 --- /dev/null +++ b/domains/shibiliya.json @@ -0,0 +1,12 @@ +{ + "description": "Shibiliya's personal developer website", + "repo": "https://github.com/duaboola", + "owner": { + "username": "duaboola", + "email": "ismailshibiliya@gmail.com" + }, + "record": { + "CNAME": "duaboola.github.io", + "URL": "https://shibiliya.is-a.dev" + } +} diff --git a/domains/steven.json b/domains/steven.json new file mode 100644 index 000000000..1e798e941 --- /dev/null +++ b/domains/steven.json @@ -0,0 +1,12 @@ +{ + "description": "Steven Frohlich's portfolio", + "repo": "https://github.com/StevenRonnyFrohlich/StevenRonnyFrohlich.github.io", + "owner": { + "username": "StevenRonnyFrohlich", + "email": "steve.r.frohlich@gmail.com" + }, + "record": { + "CNAME": "StevenRonnyFrohlich.github.io", + "URL": "https://steven.is-a.dev" + } +} diff --git a/domains/vaskian.json b/domains/vaskian.json new file mode 100644 index 000000000..f3d371e95 --- /dev/null +++ b/domains/vaskian.json @@ -0,0 +1,11 @@ +{ + "description": "Vaskian is a Dev", + "repo": "https://github.com/Nami2012", + "owner": { + "username": "Nami2012", + "email": "namithasadeeshbabu@gmail.com" + }, + "record": { + "URL": "https://vaskian.me/" + } +} diff --git a/domains/vivekkumar.json b/domains/vivekkumar.json new file mode 100644 index 000000000..c7048deaa --- /dev/null +++ b/domains/vivekkumar.json @@ -0,0 +1,13 @@ +{ + "description": "Vivek's portfolio website", + "repo": "https://github.com/VivekKumarNeu/VivekKumarNeu.github.io", + "owner": { + "username": "vivekkumarneu", + "email": "vivek-kumar@live.in" + }, + "record": { + "CNAME": "VivekKumarNeu.github.io", + "URL": "https://vivekkumar.is-a.dev" + } + } + \ No newline at end of file diff --git a/domains/yujia.json b/domains/yujia.json new file mode 100644 index 000000000..4d56109d9 --- /dev/null +++ b/domains/yujia.json @@ -0,0 +1,12 @@ +{ + "description": "Yujia's Magic", + "repo": "https://github.com/YujiaY", + "owner": { + "username": "YujiaY", + "email": "aujackyuan@gmail.com" + }, + "record": { + "CNAME": "YujiaY.github.io", + "URL": "https://yujia.is-a.dev" + } +} \ No newline at end of file diff --git a/package.json b/package.json index e7f7277a1..055959d8c 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,9 @@ "author": "Akshay Nair ", "license": "GPL-3.0", "dependencies": { - "@rqt/namecheap": "^2.4.2", "dotenv": "^8.2.0", "jest": "^26.4.2", + "node-fetch": "^2.6.1", "ramda": "^0.27.1" } } diff --git a/scripts/register-domains.js b/scripts/register-domains.js index 73186f79a..00626092f 100644 --- a/scripts/register-domains.js +++ b/scripts/register-domains.js @@ -10,27 +10,27 @@ const toHostList = R.chain(data => { return R.chain(([recordType, urls]) => (Array.isArray(urls) ? urls : [urls]).map(url => ({ - HostName: data.name, - RecordType: recordType, - Address: url, - TTL, + name: data.name, + type: recordType, + address: (recordType === 'CNAME' ? `${url}`.toLowerCase() : `${url}`).replace(/\/$/g, ''), + ttl: TTL, })) , rs); }); -const registerDomains = async ({ domainService, getDomains }) => { +const registerDomains = async ({ domainService, getDomains, log = () => {} }) => { const domains = await getDomains().then(toHostList); if (domains.length === 0) return Promise.reject(new Error('Nothing to register')); - console.log(`Publishing ${domains.length} records...`); + log(`${domains.length} records found`); return domainService.updateHosts(domains); }; const main = async () => { console.log(`Running in ${ENV} mode`); - const result = await registerDomains({ domainService: dc, getDomains: gd }); + const result = await registerDomains({ domainService: dc, getDomains: gd, log: console.log }); console.log(result); }; diff --git a/scripts/reply.js b/scripts/reply.js index e1ae2d25c..b4fad71ae 100644 --- a/scripts/reply.js +++ b/scripts/reply.js @@ -1,6 +1,6 @@ const getInstructions = () => ` -The changes you have made will soon be reflected!! +The changes have been published!! It should reflect in less than 24 hours. ## Here\'s what you need to do next @@ -16,7 +16,7 @@ If your domain points to a server you own, add \`domain-name.is-a.dev\` to your ## Need support with your domain? -If you are having trouble setting up your domain, [create an issue](https://github.com/is-a-dev/register/issues/new/choose) and pick the \`support\` template. Describe any issue you are facing there. I\'ll try my best to get back to you asap! +If you are having trouble setting up your domain, [create an issue](https://github.com/is-a-dev/register/issues/new/choose). I\'ll try my best to get back to you asap! ## Love/Hate the service? diff --git a/tests/cpanel.test.js b/tests/cpanel.test.js new file mode 100644 index 000000000..f92ce51d3 --- /dev/null +++ b/tests/cpanel.test.js @@ -0,0 +1,143 @@ +const R = require('ramda'); +const { CpanelClient } = require('../utils/lib/cpanel'); + +const mockFetch = (expectRequest, decorate = R.identity) => (reqUrl, request) => { + expectRequest(reqUrl, request); + return Promise.resolve({ + json: async () => decorate(request), + }); +}; + +describe('Cpanel client', () => { + describe('fetchzonerecords', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/json-api/cpanel?customonly=1&domain=a.b&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=fetchzone_records&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.zone.fetch(); + }); + + it('should make the correct request with query', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/json-api/cpanel?customonly=1&domain=foobar.boeey&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=fetchzone_records&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.zone.fetch({ domain: 'foobar.boeey' }); + }); + }); + + describe('addzonerecord', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/json-api/cpanel?domain=a.b&name=googo&type=CNAME&cname=beey&ttl=2020&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=ZoneEdit&cpanel_jsonapi_func=add_zone_record&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.zone.add({ + name: 'googo', + type: 'boyee', + cname: 'beey', + type: 'CNAME', + ttl: 2020, + }); + }); + }); + + describe('fetchredirections', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/execute/Mime/list_redirects?cpanel_jsonapi_user=boy&cpanel_jsonapi_module=Mime&cpanel_jsonapi_func=list_redirects&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.redirection.fetch(); + }); + }); + describe('addredirection', () => { + it('should make the correct request', async () => { + const fetch = mockFetch((url, request) => { + expect(url).toBe('https://example.com:2000/execute/Mime/add_redirect?domain=googo&destination=https%3A%2F%2Foodf.com&cpanel_jsonapi_user=boy&cpanel_jsonapi_module=Mime&cpanel_jsonapi_func=add_redirect&cpanel_jsonapi_apiversion=2'); + expect(request).toEqual({ + headers: { + Authorization: 'cpanel boy:boybyebye', + }, + rejectUnauthorized: false, + }); + }); + + const cpanel = CpanelClient({ + host: 'example.com', + port: 2000, + username: 'boy', + apiKey: 'boybyebye', + domain: 'a.b', + dependencies: { fetch }, + }); + + await cpanel.redirection.add({ + domain: 'googo', + destination: 'https://oodf.com' + }); + }); + }); +}); + diff --git a/tests/domain-service.test.js b/tests/domain-service.test.js index 08e49e9b6..19154db6e 100644 --- a/tests/domain-service.test.js +++ b/tests/domain-service.test.js @@ -1,118 +1,255 @@ const R = require('ramda'); -const { getDomainService } = require('../utils/domain-service'); +const { getDomainService, diffRecords } = require('../utils/domain-service'); +const {DOMAIN_DOMAIN} = require('../utils/constants'); -const getNc = ({ onSet, onGet } = {}) => ({ - dns: { - setHosts: (_, list) => onSet(list), - getHosts: (_) => onGet(), +const getCpanel = ({ zone, addZone, editZone, redir, addRedir, editRedir } = {}) => ({ + zone: { + fetch: (_) => zone(), + add: (rec) => addZone(rec), + edit: (rec) => editZone(rec), + }, + redirection: { + fetch: (_) => redir(), + add: (rec) => addRedir(rec), + edit: (rec) => editRedir(rec), }, }); -describe('Domain service', () => { - describe('getHosts', () => { - it('should resolve with a list of hosts', async () => { - const hosts = [ - { Name: 'xx', Type: 'CNAME', Address: 'fck.com.' }, - { Name: 'xx', Type: 'A', Address: '111.1.1212.1' }, - ]; - const onGet = async () => ({ hosts }) - const mockDomainService = getDomainService({ nc: getNc({ onGet }) }); - const list = await mockDomainService.getHosts(); +describe('diffRecords', () => { + it('should show added record', () => { + const oldRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '111.1.1212.1' }, + ]; + const newRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '111.1.1212.1' }, + { name: 'boo', type: 'CNAME', address: 'x.com' }, + ]; - expect(list).toEqual([ - { HostName: 'xx', RecordType: 'CNAME', Address: 'fck.com' }, - { HostName: 'xx', RecordType: 'A', Address: '111.1.1212.1' }, - ]); + const result = diffRecords(oldRecords, newRecords); + expect(result).toEqual({ + edit: [], + add: [ + { name: 'boo', type: 'CNAME', address: 'x.com' }, + ], }); }); - describe('setHosts', () => { + it('should show edited records', () => { + const oldRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '111.1.1212.1' }, + ]; + const newRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '69.69.69.69' }, + ]; + + const result = diffRecords(oldRecords, newRecords); + expect(result).toEqual({ + edit: [ + { name: 'xa', type: 'A', address: '69.69.69.69' }, + ], + add: [], + }); + }); + + it('should show added records with the same name and record type', () => { + const oldRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '69.69.69.69' }, + ]; + const newRecords = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xa', type: 'A', address: '69.69.69.69' }, + { name: 'xa', type: 'A', address: '69.69.4.20' }, + ]; + + const result = diffRecords(oldRecords, newRecords); + expect(result).toEqual({ + edit: [], + add: [ + { name: 'xa', type: 'A', address: '69.69.4.20' }, + ], + }); + }); +}); + +describe('Domain service', () => { + const addZone = jest.fn(async () => ({})); + const editZone = jest.fn(async () => ({})); + const addRedir = jest.fn(async () => ({})); + const editRedir = jest.fn(async () => ({})); + + const mockDS = ({ zones, redirections }) => getDomainService({ cpanel: getCpanel({ + zone: async () => zones, + redir: async () => redirections, + addZone, + addRedir, + editZone, + editRedir, + }) }); + + const getRecordCalls = recfn => recfn.mock.calls.map(R.head).map(R.pick(['name', 'type', 'address', 'redirect', 'domain'])); + + beforeEach(() => { + addZone.mockClear(); + editZone.mockClear(); + addRedir.mockClear(); + editRedir.mockClear(); + }); + + describe('getHosts', () => { it('should resolve with a list of hosts', async () => { - const records = [ { x: 'y' }, { z: 'a' } ]; + const zones = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xx', type: 'A', address: '111.1.1212.1' }, + ]; + const redirections = []; + const zone = async () => zones; + const redir = async () => redirections; + const mockDomainService = getDomainService({ cpanel: getCpanel({ zone, redir }) }); + const list = await mockDomainService.getHosts(); - const onSet = jest.fn((list) => { - expect(list).toBe(records); - return Promise.resolve(null); - }); + expect(list).toEqual([ + { name: 'xx', type: 'CNAME', address: 'fck.com' }, + { name: 'xx', type: 'A', address: '111.1.1212.1' }, + ]); + }); - const mockDomainService = getDomainService({ nc: getNc({ onSet }) }); - await mockDomainService.setHosts(records); - expect(onSet).toBeCalledTimes(1); + it('should resolve with a redirections', async () => { + const zones = [ + { name: 'xx', type: 'CNAME', address: 'fck.com.' }, + { name: 'xx', type: 'A', address: '111.1.1212.1' }, + ]; + const redirections = [ + { domain: 'foo.booboo.xyz', destination: 'https://google.com' }, + { domain: 'foo1.booboo.xyz', destination: 'https://duck.com' }, + ]; + const zone = async () => zones; + const redir = async () => redirections; + const mockDomainService = getDomainService({ cpanel: getCpanel({ zone, redir }) }); + const list = await mockDomainService.getHosts(); + + expect(list).toEqual([ + { name: 'xx', type: 'CNAME', address: 'fck.com' }, + { name: 'xx', type: 'A', address: '111.1.1212.1' }, + { name: 'foo', type: 'URL', address: 'https://google.com' }, + { name: 'foo1', type: 'URL', address: 'https://duck.com' }, + ]); }); }); describe('updateHosts', () => { it('should append new hosts with existing ones and set it', async () => { - const records = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'goo' }, + const zones = [ + { someid: 1, name: 'a', type: 'CNAME', address: 'boo' }, + { someid: 2, name: 'b', type: 'CNAME', address: 'goo' }, ]; + const redirections = []; - const onGet = () => Promise.resolve({ hosts: records }); - const onSet = jest.fn(async () => ({})); - - const mockDomainService = getDomainService({ nc: getNc({ onSet, onGet }) }); + const mockDomainService = mockDS({ zones, redirections }); await mockDomainService.updateHosts([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'goo' }, - { HostName: 'c', RecordType: 'A', Address: '12.131321.213' }, + { name: 'a', type: 'CNAME', address: 'boo' }, + { name: 'b', type: 'CNAME', address: 'goo' }, + { name: 'c', type: 'A', address: '12.131321.213' }, ]); - const [hosts] = onSet.mock.calls[0]; + expect(addZone).toBeCalledTimes(1); + expect(getRecordCalls(addZone)).toEqual([ + { name: 'c', type: 'A', address: '12.131321.213' }, + ]); + expect(editZone).toBeCalledTimes(0); + }); - expect(hosts.map(R.pick(['HostName', 'RecordType', 'Address']))).toEqual([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'goo' }, - { HostName: 'c', RecordType: 'A', Address: '12.131321.213' }, + it('should update matching host and set it', async () => { + const zones = [ + { someid: 1, name: 'a', type: 'CNAME', address: 'boo' }, + { someid: 2, name: 'b', type: 'CNAME', address: 'goo' }, + ]; + const redirections = []; + + const mockDomainService = mockDS({ zones, redirections }); + await mockDomainService.updateHosts([ + { name: 'a', type: 'CNAME', address: 'boo' }, + { name: 'b', type: 'CNAME', address: 'googoogaga' }, + ]); + + expect(addZone).toBeCalledTimes(0); + expect(editZone).toBeCalledTimes(1); + expect(getRecordCalls(editZone)).toEqual([ + { name: 'b', type: 'CNAME', address: 'googoogaga' }, ]); }); it('should update matching host and set it', async () => { - const records = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'goo' }, + const zones = [ + { someid: 1, name: 'a', type: 'CNAME', address: 'boo' }, + { someid: 2, name: 'b', type: 'CNAME', address: 'goo' }, + { someid: 2, name: 'b', type: 'CNAME', address: 'xaa' }, ]; + const redirections = []; - const onGet = () => Promise.resolve({ hosts: records }); - const onSet = jest.fn(async () => ({})); - - const mockDomainService = getDomainService({ nc: getNc({ onSet, onGet }) }); + const mockDomainService = mockDS({ zones, redirections }); await mockDomainService.updateHosts([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'googoogaga' }, + { name: 'a', type: 'CNAME', address: 'boo' }, + { name: 'b', type: 'CNAME', address: 'googoogaga' }, + { name: 'b', type: 'CNAME', address: 'farboo' }, ]); - const [hosts] = onSet.mock.calls[0]; - - expect(hosts.map(R.pick(['HostName', 'RecordType', 'Address']))).toEqual([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'googoogaga' }, + expect(addZone).toBeCalledTimes(0); + expect(editZone).toBeCalledTimes(2); + expect(getRecordCalls(editZone)).toEqual([ + { name: 'b', type: 'CNAME', address: 'googoogaga' }, + { name: 'b', type: 'CNAME', address: 'farboo' }, ]); }); - it('should update matching host and set it', async () => { - const records = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'goo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'xaa' }, + it('should workout this complex example', async () => { + const zones = [ + { someid: 1, name: 'a', type: 'CNAME', address: 'world' }, + { someid: 2, name: 'b', type: 'A', address: '1' }, + { someid: 2, name: 'b', type: 'A', address: '2' }, + { someid: 2, name: 'c', type: 'CNAME', address: 'hello.com' }, + ]; + const redirections = [ + { domain: `b.${DOMAIN_DOMAIN}`, destination: 'https://foobar.com' }, + { domain: `c.${DOMAIN_DOMAIN}`, destination: 'https://goobar.com' }, + { domain: `x.${DOMAIN_DOMAIN}`, destination: 'https://example.com' }, ]; - const onGet = () => Promise.resolve({ hosts: records }); - const onSet = jest.fn(async () => ({})); - - const mockDomainService = getDomainService({ nc: getNc({ onSet, onGet }) }); + const mockDomainService = mockDS({ zones, redirections }); await mockDomainService.updateHosts([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'googoogaga' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'farboo' }, + { name: 'a', type: 'CNAME', address: 'boo' }, + { name: 'b', type: 'A', address: '1' }, + { name: 'b', type: 'A', address: '2' }, + { name: 'b', type: 'A', address: '3' }, + { name: 'b', type: 'URL', address: 'https://wowow.com' }, + { name: 'c', type: 'CNAME', address: 'hello.com' }, + { name: 'c', type: 'URL', address: 'https://goobar.com' }, + { name: 'd', type: 'CNAME', address: 'helo.com' }, + { name: 'd', type: 'URL', address: 'https://hhh.com' }, + { name: 'x', type: 'URL', address: 'https://example69.com' }, ]); - const [hosts] = onSet.mock.calls[0]; - - expect(hosts.map(R.pick(['HostName', 'RecordType', 'Address']))).toEqual([ - { HostName: 'a', RecordType: 'CNAME', Address: 'boo' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'googoogaga' }, - { HostName: 'b', RecordType: 'CNAME', Address: 'farboo' }, + expect(addZone).toBeCalledTimes(2); + expect(editZone).toBeCalledTimes(1); + expect(addRedir).toBeCalledTimes(1); + expect(editRedir).toBeCalledTimes(2); + expect(getRecordCalls(addZone)).toEqual([ + { name: 'b', type: 'A', address: '3' }, + { name: 'd', type: 'CNAME', address: 'helo.com' } + ]); + expect(getRecordCalls(editZone)).toEqual([ + { name: 'a', type: 'CNAME', address: 'boo' }, + ]); + expect(getRecordCalls(addRedir)).toEqual([ + { domain: `d.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://hhh.com' }, + ]); + expect(getRecordCalls(editRedir)).toEqual([ + { domain: `b.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://wowow.com' }, + { domain: `x.${DOMAIN_DOMAIN}`, type: 'permanent', redirect: 'https://example69.com' }, ]); }); }); diff --git a/tests/domains.test.js b/tests/domains.test.js index 37c59575e..7f219fec4 100644 --- a/tests/domains.test.js +++ b/tests/domains.test.js @@ -1,7 +1,14 @@ const R = require('ramda'); +const fs = require('fs'); const { getDomains, validateDomainData } = require('../utils/domain'); +const { DOMAINS_PATH } = require('../utils/constants'); describe('Domains', () => { + it('should all be json', async () => { + const files = await fs.promises.readdir(DOMAINS_PATH, {}); + expect(files.filter(f => !/\.json$/g.test(f)).length).toBe(0); + }); + it('should be valid', (done) => { getDomains() .then(R.map(data => { diff --git a/tests/register.test.js b/tests/register.test.js index 23d1ffd43..0a87f2f4e 100644 --- a/tests/register.test.js +++ b/tests/register.test.js @@ -1,11 +1,18 @@ +const R = require('ramda'); const { toHostList, registerDomains } = require('../scripts/register-domains'); -const { TTL } = require('../utils/constants'); +const { TTL, DOMAIN_DOMAIN } = require('../utils/constants'); const { getDomainService } = require('../utils/domain-service'); -const getNc = ({ onSet, onGet } = {}) => ({ - dns: { - setHosts: (_, list) => onSet(list), - getHosts: (_) => onGet(), +const getCpanel = ({ zone, addZone, editZone, redir, addRedir, editRedir } = {}) => ({ + zone: { + fetch: (_) => zone(), + add: (rec) => addZone(rec), + edit: (rec) => editZone(rec), + }, + redirection: { + fetch: (_) => redir(), + add: (rec) => addRedir(rec), + edit: (rec) => editRedir(rec), }, }); @@ -18,113 +25,80 @@ describe('toHostList', () => { ]); expect(res).toEqual([ - { 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 }, + { name: 'akshay', type: 'CNAME', address: 'phenax.github.io', ttl: TTL }, + { name: 'foobar', type: 'CNAME', address: 'v.io', ttl: TTL }, + { name: 'xx', type: 'A', address: '1.2.3.4', ttl: TTL }, + { name: 'xx', type: 'A', address: '5.6.3.2', ttl: TTL }, + { name: 'xx', type: 'A', address: '1.2.31.1', ttl: TTL }, ]); }); }); describe('registerDomains', () => { + const addZone = jest.fn(async () => ({})); + const editZone = jest.fn(async () => ({})); + const addRedir = jest.fn(async () => ({})); + const editRedir = jest.fn(async () => ({})); + + const mockDS = ({ zones, redirections }) => getDomainService({ cpanel: getCpanel({ + zone: async () => zones, + redir: async () => redirections, + addZone, + addRedir, + editZone, + editRedir, + }) }); + + beforeEach(() => { + addZone.mockClear(); + editZone.mockClear(); + addRedir.mockClear(); + editRedir.mockClear(); + }); + it('should register the new set of hosts generated from domains list', async () => { const localHosts = [ { name: 'a', record: { CNAME: 'hello' } }, { name: 'b', record: { CNAME: 'xaa' } }, ]; const remoteHosts = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'goo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'xaa' }, + { someididk: 1, name: 'a', type: 'CNAME', address: 'hello' }, + { someididk: 2, name: 'b', type: 'CNAME', address: 'goo' }, + { someididk: 2, name: 'b', type: 'CNAME', address: 'xaa' }, ]; + const remoteRedirections = []; - const onSet = jest.fn(async () => ({})); - - const domainService = getDomainService({ nc: getNc({ onSet, onGet: async () => ({ hosts: remoteHosts }) }) }); + const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections }); await registerDomains({ getDomains: async () => localHosts, domainService }); - expect(onSet).toBeCalledTimes(1); - - const [hosts] = onSet.mock.calls[0]; - expect(hosts).toEqual([ - { HostId: 1, Address: 'hello', HostName: 'a', RecordType: 'CNAME', TTL }, - { HostId: 2, Address: 'xaa', HostName: 'b', RecordType: 'CNAME', TTL }, - ]); + expect(addZone).toBeCalledTimes(0); + expect(editZone).toBeCalledTimes(0); + expect(addRedir).toBeCalledTimes(0); + expect(editRedir).toBeCalledTimes(0); }); it('should add the new set hosts', async () => { const localHosts = [ - { name: 'a', record: { CNAME: 'boo' } }, - { name: 'b', record: { CNAME: 'xaa' } }, - { name: 'c', record: { CNAME: 'yello' } }, + { name: 'a', record: { CNAME: 'boo', URL: 'z' } }, + { name: 'b', record: { CNAME: 'xaa', URL: 'x' } }, + { name: 'c', record: { CNAME: 'yello', URL: 'https://google.com' } }, ]; const remoteHosts = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'xaa' }, + { someididk: 1, name: 'a', type: 'CNAME', address: 'boo' }, + { someididk: 2, name: 'b', type: 'CNAME', address: 'xaa' }, + ]; + const remoteRedirections = [ + { domain: `b.${DOMAIN_DOMAIN}`, destination: 'x' }, + { domain: `a.${DOMAIN_DOMAIN}`, destination: 'y' }, ]; - const onSet = jest.fn(async () => ({})); - - const domainService = getDomainService({ nc: getNc({ onSet, onGet: async () => ({ hosts: remoteHosts }) }) }); + const domainService = mockDS({ zones: remoteHosts, redirections: remoteRedirections }); await registerDomains({ getDomains: async () => localHosts, domainService }); - expect(onSet).toBeCalledTimes(1); - - const [hosts] = onSet.mock.calls[0]; - expect(hosts).toEqual([ - { HostId: 1, Address: 'boo', HostName: 'a', RecordType: 'CNAME', TTL }, - { HostId: 2, Address: 'xaa', HostName: 'b', RecordType: 'CNAME', TTL }, - { Address: 'yello', HostName: 'c', RecordType: 'CNAME', TTL }, - ]); - }); - - it('should remove unlisted hosts', async () => { - const localHosts = [ - { name: 'a', record: { CNAME: 'boo' } }, - ]; - const remoteHosts = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'xaa' }, - ]; - - const onSet = jest.fn(async () => ({})); - - const domainService = getDomainService({ nc: getNc({ onSet, onGet: async () => ({ hosts: remoteHosts }) }) }); - await registerDomains({ getDomains: async () => localHosts, domainService }); - - expect(onSet).toBeCalledTimes(1); - - const [hosts] = onSet.mock.calls[0]; - expect(hosts).toEqual([ - { HostId: 1, Address: 'boo', HostName: 'a', RecordType: 'CNAME', TTL }, - ]); - }); - - it('should change record type from cname to a', async () => { - const localHosts = [ - { name: 'a', record: { CNAME: 'boo' } }, - { name: 'b', record: { A: ['1', '2', '3'] } }, - ]; - const remoteHosts = [ - { HostId: 1, Name: 'a', Type: 'CNAME', Address: 'boo' }, - { HostId: 2, Name: 'b', Type: 'CNAME', Address: 'xaa' }, - ]; - - const onSet = jest.fn(async () => ({})); - - const domainService = getDomainService({ nc: getNc({ onSet, onGet: async () => ({ hosts: remoteHosts }) }) }); - await registerDomains({ getDomains: async () => localHosts, domainService }); - - expect(onSet).toBeCalledTimes(1); - - const [hosts] = onSet.mock.calls[0]; - expect(hosts).toEqual([ - { HostId: 1, Address: 'boo', HostName: 'a', RecordType: 'CNAME', TTL }, - { Address: '1', HostName: 'b', RecordType: 'A', TTL }, - { Address: '2', HostName: 'b', RecordType: 'A', TTL }, - { Address: '3', HostName: 'b', RecordType: 'A', TTL }, - ]); + expect(addZone).toBeCalledTimes(1); + expect(editZone).toBeCalledTimes(0); + expect(addRedir).toBeCalledTimes(1); + expect(editRedir).toBeCalledTimes(1); }); }); diff --git a/utils/constants.js b/utils/constants.js index 89a9b627f..086bb0f29 100644 --- a/utils/constants.js +++ b/utils/constants.js @@ -1,21 +1,26 @@ const path = require('path'); -const { ENV = 'sandbox', CI } = process.env; +const { ENV = 'test', CI } = process.env; if (!CI) { require('dotenv').config({ path: path.resolve(`.env.${ENV}`) }); } -const { NC_USER, NC_API_KEY, NC_DOMAIN, IP_ADDRESS } = process.env; +const { DOMAIN_USER, DOMAIN_API_KEY, DOMAIN_DOMAIN, DOMAIN_API_HOST, DOMAIN_API_PORT } = process.env; const IS_TEST = ENV === 'test'; +const DOMAINS_PATH = require('path').resolve('domains'); + module.exports = { ENV, - VALID_RECORD_TYPES: ['CNAME', 'A', 'ALIAS', 'URL'], - NC_DOMAIN: NC_DOMAIN || 'booboo.xyz', - NC_USER: IS_TEST ? 'testuser' : NC_USER, - NC_API_KEY: IS_TEST ? 'testkey' : NC_API_KEY, - IP_ADDRESS, - TTL: 5*60, + IS_TEST, + VALID_RECORD_TYPES: ['CNAME', 'A', 'URL'], + DOMAIN_DOMAIN: DOMAIN_DOMAIN || 'booboo.xyz', + DOMAIN_USER: IS_TEST ? 'testuser' : DOMAIN_USER, + DOMAIN_API_KEY: IS_TEST ? 'testkey' : DOMAIN_API_KEY, + DOMAIN_API_HOST: IS_TEST ? 'example.com' : DOMAIN_API_HOST, + DOMAIN_API_PORT: IS_TEST ? 6969 : DOMAIN_API_PORT, + DOMAINS_PATH, + TTL: 5*60*60, }; diff --git a/utils/domain-service.js b/utils/domain-service.js index 0831f3cb2..f78652740 100644 --- a/utils/domain-service.js +++ b/utils/domain-service.js @@ -1,72 +1,146 @@ const R = require('ramda'); -const Namecheap = require('@rqt/namecheap'); -const { NC_DOMAIN, NC_USER, NC_API_KEY, ENV, IP_ADDRESS } = require('../utils/constants'); +const { cpanel } = require('./lib/cpanel'); +const { DOMAIN_DOMAIN, IS_TEST } = require('./constants'); -const IS_SANDBOX = ENV === 'sandbox'; +const log = IS_TEST ? () => {} : console.log; -const getDomainService = ({ nc }) => { +const recordToRedirection = ({ name, address }) => ({ + domain: `${name}.${DOMAIN_DOMAIN}`, + redirect: address, + type: 'permanent', + redirect_wildcard: 1, + redirect_www: 0, +}); +const recordToZone = ({ name, type, address, ...rec }) => ({ + ...rec, //line + name, + type, + address, + ...(type === 'CNAME' ? { cname: address } : {}), +}); + +const cleanName = name => `${name}`.replace(new RegExp(`\.${DOMAIN_DOMAIN}\.?$`), '').toLowerCase(); + +const zoneToRecord = ({ name, type, cname, address, record, ...host }) => ({ + ...host, + name: cleanName(name), + type: `${type}`, + address: `${cname || address || record}`.replace(/\.$/g, '').toLowerCase(), +}); +const redirectionToRecord = ({ domain, destination }) => ({ + name: cleanName(domain), + type: 'URL', + address: `${destination}`.replace(/\/$/g, ''), +}); + +const getHostKey = host => `${host.name}##${host.type}`; + +const toHostMap = hosts => hosts.reduce((acc, host) => { + const key = getHostKey(host); + return { ...acc, [key]: [ ...(acc[key] || []), host ] }; +}, {}); + +const diffRecords = (oldRecords, newRecords) => { + const remoteHostMap = toHostMap(oldRecords); + const localHostMap = toHostMap(newRecords); + + return R.toPairs(localHostMap).reduce((acc, [key, local]) => { + const remote = remoteHostMap[key]; + + if (remote) { + let adds = []; + let edits = []; + + const diff = R.differenceWith((a, b) => a.address === b.address, local, remote); + + if (diff.length === local.length - remote.length) { + adds = diff; + } else { + edits = diff; + } + + return { ...acc, add: acc.add.concat(adds), edit: acc.edit.concat(edits) }; + } + + return { ...acc, add: acc.add.concat(local) }; + }, { add: [], edit: [] }); +}; + +const lazyTask = fn => data => () => fn(data); + +const batchLazyTasks = count => tasks => tasks.reduce((batches, task) => { + if (batches.length === 0) return [[task]]; + + const full = R.init(batches); + const last = R.last(batches); + + if (last.length >= count) return [...batches, [task]]; + return [...full, [...last, task]]; +}, []); + +const executeBatch = (batches) => batches.reduce((promise, batch, index) => { + return promise.then(async () => { + log('>>> Running batch number:', index + 1, `(size: ${batch.length})`); + + const values = await Promise.all(batch.map(fn => fn().catch(e => console.error(e)))); + + const results = values.map(R.pathOr({}, ['cpanelresult', 'data', 0])); + const failed = results.filter(x => (x.result || {}).status != 1); + + log(`${values.length - failed.length}/${values.length}`); + failed.length && log(failed); + + return null; + }); +}, Promise.resolve()); + +const getDomainService = ({ cpanel }) => { let hostList = []; + const fetchZoneRecords = () => cpanel.zone.fetch().then(R.map(zoneToRecord)); + const fetchRedirections = () => cpanel.redirection.fetch().then(R.map(redirectionToRecord)); + + const addZoneRecord = lazyTask(R.compose(cpanel.zone.add, recordToZone)); + const editZoneRecord = lazyTask(R.compose(cpanel.zone.edit, recordToZone)); + const addRedirection = lazyTask(R.compose(cpanel.redirection.add, recordToRedirection)); + const editRedirection = lazyTask(R.compose(cpanel.redirection.edit, recordToRedirection)); + const getHosts = async () => { if (hostList.length) return hostList; - const list = await nc.dns.getHosts(NC_DOMAIN) - .then(R.propOr([], 'hosts')) - .then(R.map(host => R.omit(['Name', 'Type'], { - ...host, - HostName: host.Name, - RecordType: host.Type, - Address: `${host.Address}`.replace(/\.$/g, ''), - }))); + const list = await Promise.all([fetchZoneRecords(), fetchRedirections()]).then(R.flatten); hostList = list; return list; }; - const setHosts = hosts => nc.dns.setHosts(NC_DOMAIN, hosts); + const BATCH_SIZE = 1; - const getHostKey = host => `${host.HostName}--${host.RecordType}`; - const toHostMap = hosts => hosts.reduce((acc, host) => { - const key = getHostKey(host); - return { ...acc, [key]: [ ...(acc[key] || []), host ] }; - }, {}); + const addRecords = R.compose(batchLazyTasks(BATCH_SIZE), R.filter(Boolean), R.map(R.cond([ + [ R.propEq('name', 'www'), () => null ], + [ R.propEq('type', 'URL'), addRedirection ], + [ R.T, addZoneRecord ], + ]))); + const editRecords = R.compose(batchLazyTasks(BATCH_SIZE), R.map(R.cond([ + [ R.propEq('type', 'URL'), editRedirection ], + [ R.T, editZoneRecord ], + ]))); const updateHosts = async hosts => { - const hostList = await getHosts(); - const remoteHostMap = toHostMap(hostList); - const localHostMap = toHostMap(hosts); + const remoteHostList = await getHosts(); + const { add, edit } = diffRecords(remoteHostList, hosts); - const newHostList = R.toPairs(localHostMap).reduce((acc, [key, local]) => { - const remote = remoteHostMap[key]; - - if (remote) { - return acc.concat(local.map((localItem, index) => R.merge(remote[index], localItem))); - } - - return [...acc, ...local]; - }, []); - - return setHosts(newHostList); + await executeBatch(addRecords(add).concat(editRecords(edit))); + return { additions: add.length, edits: edit.length }; }; - return { getHosts, setHosts, updateHosts }; + return { getHosts, updateHosts }; }; -if (!NC_API_KEY) { - console.error('NC_API_KEY cannot be empty'); - process.exit(1); -} - -const nc = new Namecheap({ - user: NC_USER, - key: NC_API_KEY, - ip: IP_ADDRESS, - sandbox: IS_SANDBOX, -}); - -const domainService = getDomainService({ nc }); +const domainService = getDomainService({ cpanel }); module.exports = { getDomainService, domainService, + diffRecords, }; diff --git a/utils/domain.js b/utils/domain.js index 089bde425..f7819f02a 100644 --- a/utils/domain.js +++ b/utils/domain.js @@ -1,9 +1,7 @@ const fs = require('fs'); const path = require('path'); const R = require('ramda'); -const { VALID_RECORD_TYPES } = require('./constants'); - -const DOMAINS_PATH = path.resolve('domains'); +const { VALID_RECORD_TYPES, DOMAINS_PATH } = require('./constants'); const log = m => x => console.log(m, x) || x; @@ -38,7 +36,7 @@ const validateDomainData = validate({ R.equals('@'), R.allPass([ R.compose(between(2, 100), R.length), - str => str && str.match(/^[A-Za-z0-9\-]+$/ig), + str => str && str.match(/^[a-z0-9\-]+$/ig), ]) ]), }, @@ -62,7 +60,6 @@ const validateDomainData = validate({ R.compose(R.isEmpty, R.flip(R.difference)(VALID_RECORD_TYPES), R.keys), R.cond([ [R.prop('CNAME'), validateNameRecord('CNAME')], - [R.prop('ALIAS'), validateNameRecord('ALIAS')], [R.prop('A'), R.propSatisfies(R.is(Array), 'A')], [R.prop('URL'), R.propSatisfies(R.is(String), 'URL')], [R.T, R.T], diff --git a/utils/lib/cpanel.js b/utils/lib/cpanel.js new file mode 100644 index 000000000..c29c10145 --- /dev/null +++ b/utils/lib/cpanel.js @@ -0,0 +1,87 @@ +const R = require('ramda'); +const fetch = require('node-fetch'); +const qs = require('qs'); +const { DOMAIN_API_HOST, DOMAIN_API_PORT, DOMAIN_USER, DOMAIN_API_KEY, DOMAIN_DOMAIN } = require('../constants'); + +const CpanelClient = (options) => { + // TODO: Make defaultQuery functional + const api = ({ basePath = '', action = '' }) => (module, func, defaultQuery = {}) => (q = {}) => { + const query = { + ...defaultQuery, + ...q, + cpanel_jsonapi_user: options.username, + cpanel_jsonapi_module: module, + cpanel_jsonapi_func: func, + cpanel_jsonapi_apiversion: 2, + }; + + const request = { + headers: { + Authorization: `cpanel ${options.username}:${options.apiKey}`, + }, + rejectUnauthorized: false, + }; + + const path = `${basePath}/${action}?${qs.stringify(query)}`; + const reqUrl = `https://${options.host}:${options.port}/${path}`; + + const { fetch } = options.dependencies; + return fetch(reqUrl, request).then(res => res.json()); + }; + + const api2 = api({ basePath: 'json-api', action: 'cpanel' }); + const uapi = (module, func, defaultQuery) => + api({ basePath: 'execute', action: `${module}/${func}` })(module, func, defaultQuery); + + return { + zone: { + // { customonly, domain } + // -> { cpanelresult: { data[{ class, ttl, name, line, Line, cname, type, record }] } } + fetch: R.compose( + p => p.then(R.pathOr([], ['cpanelresult', 'data'])), + api2('ZoneEdit', 'fetchzone_records', { customonly: 1, domain: options.domain }) + ), + + // { name, type(A|CNAME), cname, address, ttl } + // -> {} + add: api2('ZoneEdit', 'add_zone_record', { domain: options.domain }), + + // { name, type(A|CNAME), cname, address, ttl } + // -> {} + edit: api2('ZoneEdit', 'edit_zone_record', { domain: options.domain }), + }, + redirection: { + // {} + // -> { domain, destination } + fetch: R.compose( + p => p.then(R.pathOr([], ['data'])), + uapi('Mime', 'list_redirects'), + ), + + // { domain, redirect, type(permanent|tmp), redirect_wildcard(0|1), redirect(0|1|2) } + // -> {} + add: uapi('Mime', 'add_redirect'), + edit: uapi('Mime', 'add_redirect'), // NOTE: adding new updates exisiting + }, + }; +}; + +if (!DOMAIN_API_KEY) { + console.error('Api key cannot be empty'); + process.exit(1); +} + +const cpanel = CpanelClient({ + host: DOMAIN_API_HOST, + port: DOMAIN_API_PORT, + username: DOMAIN_USER, + apiKey: DOMAIN_API_KEY, + domain: DOMAIN_DOMAIN, + dependencies: { fetch }, +}); + +module.exports = { + cpanel, + CpanelClient, +}; + diff --git a/yarn.lock b/yarn.lock index 2cb029d01..fb8f6f11e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -458,11 +458,6 @@ "@types/yargs" "^15.0.0" chalk "^4.0.0" -"@rqt/namecheap@^2.4.2": - version "2.4.2" - resolved "https://registry.yarnpkg.com/@rqt/namecheap/-/namecheap-2.4.2.tgz#8537eea6efbe7ac4fd449e3aee5f2c1d80986fcf" - integrity sha512-RfrK7ywOraz0nR/BlQt8fJQDcOfI9cLSTpa6l9JS9ER0HJ6t1FQ8Pxmplj/lVQv8rkczuVADdZVC3HlL98Q31w== - "@sinonjs/commons@^1.7.0": version "1.8.1" resolved "https://registry.yarnpkg.com/@sinonjs/commons/-/commons-1.8.1.tgz#e7df00f98a203324f6dc7cc606cad9d4a8ab2217" @@ -2468,6 +2463,11 @@ nice-try@^1.0.4: resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366" integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ== +node-fetch@^2.6.1: + version "2.6.1" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.1.tgz#045bd323631f76ed2e2b55573394416b639a0052" + integrity sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw== + node-int64@^0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b"