Njalla has since released an official API which renders this code obsolete
and overly complex. Head over to https://github.com/Sighery/gonjalla
for a Golang package based on the official API, and to help implement
more methods.
go-njalla-dns-scraper
Go program to scrape, and offer an API for Njalla's DNS records
configuration interface.
Njalla is a privacy-aware domain service. I've recently started to use it and
I quite like them. However, they don't currently provide any official API to
interface with domains' DNS records.
This is useful (and maybe even needed) for when you want to set up things like
Let's Encrypt SSL certificates with maybe Certbot. These
certificates are short-lived, for now three months, as they
explain and cover in their FAQ. They also mention that if it wasn't for
many DNS provides not offering programmatic ways to update DNS records (which
is needed for one of the ways of setting and renewing SSL certificates),
they'd make them even more short-lived.
One way of verifying domain ownership, and getting the SSL certificates, is to
set DNS TXT records with given codes generated by Let's Encrypt/Certbot.
Alternatively, you can also use HTTP to verify the domain ownership, but this
doesn't work (or it requires more work, rather) for wildcard SSL certificates,
which are used to issue SSL certificates to the main domain and all its
subdomains.
Certbot is used to automate all this work. It has plugins that integrate with
other DNS providers and take care of both setting the initial SSL certificate,
and then renewing them with the help of a CRON schedule.
However, since Njalla doesn't provide an API, and it doesn't implement
RFC 2136, there's currently no way to programmatically add, update, and
remove DNS records so I could automate all this work.
Credits
Even though Njalla doesn't currently provide an official API, there's a
NodeJS package that scrapes Njalla's website and exposes an API. I've
shamelessly copied most of the code logic when porting it over to Go here.
My utmost thanks to @romualdr for doing all the work of going through the
Njalla website, figuring out how it works, and translating all the needed
requests for the API into code. I can quickly progress in this port only
because they've already done all that time-consuming research work.
Motivations and Reasoning
A big motivator for this is because I'm lazy and I want to automate renewing
the SSL certificates. However, why Go?
I don't know Go. I believe this will become clear to anyone who just
glances at the current code. And the NodeJS package works (mostly) just
fine. So why would I decide to reinvent the wheel, on a language I don't know?
That is because I want to have my infrastructure as code, managed by
some infrastructure-as-code tool like Terraform. For now I'm leaning
towards using Terraform, which allows you to create your own providers that
then you can use in your Terraform infrastructure code. Only catch is that
Terraform is written in Go, and therefore the providers must be written in Go
as well.
Issues and Missing Features
I've already achieved parity with the NodeJS version. It's currently somewhat
of a library as well. The current code is not pretty. It makes use of quite a
few hacks because I don't know Go, and I don't know how to do some dynamic
changes I need in a static way that Go will like.
Currently there's also no CLI client. Although I plan on adding, or trying to,
add one soon enough.