[ref][add] refactored code to use clap and added basic calls

This commit is contained in:
2022-10-02 01:00:48 -05:00
parent 29f8b6692e
commit df6c8744ed
15 changed files with 1191 additions and 520 deletions

89
README.md Normal file
View File

@@ -0,0 +1,89 @@
<h1 align="center">nscli</h1>
<h4 align="center">
A quickly hacked together CLI Client for the <a href="https://www.namesilo.com/api-reference">NameSilo API</a>.
</h4>
Letsencrypt allows for wildcard and certificates for servers that are not accessible on the web, through a DNS Challenge. This tool makes automation possible for domains on the NameSilo registrar. It does not cover the entirety of the NameSilo API.
<p align="center">
<strong>
<a href="#getting-started">Getting started</a>
• <a href="#letsencrypt">LetsEncrypt</a>
• <a href="#roadmap">Roadmap</a>
</strong>
</p>
## Getting Started
### Build
```
# compile
cargo build --package nscli --release
# run
./target/release/nscli --help
# development
cargo run --package nscli --bin nscli -- help
```
### Command Line Interface
The command line interface of `nscli` is build with [clap](https://docs.rs/clap/latest/clap/):
```
Usage: nscli [OPTIONS] <COMMAND>
Commands:
listdomains A list of all active domains within your account
getdomaininfo Get essential information on a domain within your account
dnslistrecords View all DNS records associated with your domain
dnsaddrecord Add a new DNS resource record or update existing
dnsupdaterecord Update an existing DNS resource record
dnsdeleterecord Delete an existing DNS resource record
dnsrecordid [Custom] Get DNS record id if it exists
help Print this message or the help of the given subcommand(s)
Options:
-a, --api-key <FILE> [default: .api_key]
-h, --help Print help information
Process finished with exit code 0
```
> **Note:** As duplicate resource records are out of scope for this tool, the following commands deviate from their NameSilo API counterpart:
> - `dnsaddrecord`: does not create duplicate entries, but instead updates a matching record if it already exists
> - `dnsdeleterecord`: takes a subdomain and record type as parameter and will delete the first matching one
> - `dnsrecordid`: is not part of the NameSilo API
## LetsEncrypt
The [pre and post validation hook](https://eff-certbot.readthedocs.io/en/stable/using.html#hooks) of `certbot` can be used to add `nscli` to the certification process.
```bash
certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /path/to/pre.sh --manual-cleanup-hook /path/to/post.sh -d example.com
```
```bash
#!/bin/bash
# pre hook example
./nscli dnsaddrecord --domain $CERTBOT_DOMAIN \
--rrtype txt \
--rrhost _acme-challenge \
--rrvalue $CERTBOT_VALIDATION
# wait for the change to propagate
sleep 60
```
```bash
#!/bin/bash
# post hook example
./nscli dnsdeleterecord --domain $CERTBOT_DOMAIN \
--rrtype txt \
--rrhost _acme-challenge
```
## Roadmap
* Add optional `rrid` param to `dnsdeleterecord`
* Properly parse response `xml` and make output available in digestible form on `stdout`
* Add more API calls