Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

All RR-Types , non-verbose #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ A small cli-client for the InternetX AutoDNS API to update a record with an IP a

## Usage

### Verbosity

log to syslog/logger( attention , your password as well )

```
$ DEBUGSYSLOG=true ./autodns-cli update foo.example.org 127.0.0.1
```
log to STDERR
```
$ DEBUGSTDERR=true ./autodns-cli update foo.example.org 127.0.0.1
```

### Configuration

You need to start this with:
Expand All @@ -21,14 +33,27 @@ $ export AUTODNS_CONTEXT=4
$ export MY_ZONE=example.org
```

or alternatively
```
MY_ZONE=example.org AUTODNS_CONTEXT=4 AUTODNS_USER=your_login AUTODNS_PASSWORD=your_password ./autodns-cli update foo.example.org 127.0.0.1
```


Bonus points: Create an `.autodns-cli.rc` with the above.

### Updating/Creating a record
### Updating/Creating a DNS record ( resource record in autodns )

## BE CAREFUL AS the domain parameter might be prefixed ( e.g mydomainentry.mydomain.com)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
## BE CAREFUL AS the domain parameter might be prefixed ( e.g mydomainentry.mydomain.com)
> **BE CAREFUL** AS the domain parameter might be prefixed ( e.g mydomainentry.mydomain.com)


Then run with:

```
$ ./autodns-cli update foo.example.org 127.0.0.1
$ ./autodns-cli update domain.com 127.0.0.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this was intended?

```
OR specify the type as last argument

```
$ ./autodns-cli update _amazonses.subdomain "ASDOIJQWDQWDASD+24hjdsf23/" TXT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool!

```

### Deleting a record
Expand Down
11 changes: 7 additions & 4 deletions autodns-cli
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ declare -r prog=$(basename "$0")
declare -r endpoint=https://api.autodns.com/v1
declare -r ttl=120

if [ -f './.autodns-cli.rc' ]; then
if [ -f '~/.autodns-cli.rc' ]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make it possibly load either? I am not sure what the best load order would be, maybe home first, then local second?

# shellcheck disable=SC1091
source ./.autodns-cli.rc
source ~/.autodns-cli.rc
fi

source ./func.sh
source ./commands.sh
#source ./func.sh
#source ./commands.sh

source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/func.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼 Cheers!

source $( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/commands.sh

subcommand=$1
case $subcommand in
Expand Down
15 changes: 11 additions & 4 deletions commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ sub_show() {
sub_update() {
local domain=$1
local ip=$2
local rrtype=$3


if [ -z "$domain" ]; then
echo "Please provide a domain."
Expand All @@ -82,6 +84,11 @@ sub_update() {
exit 1
fi

if [ -z "$rrtype" ]; then
echo "resource type not set, using A"
rrtype=A
fi

if [ -z ${MY_ZONE+x} ]; then
echo "Missing \$MY_ZONE"
exit 1
Expand All @@ -101,10 +108,10 @@ sub_update() {

_log "Zone data: $data"

local a_record=$(_create_record "$domain" "$ip")
_log "New record: $a_record"
local new_record=$(_create_record "$domain" "$ip" )
_log "New record: $new_record"

local obj=$(_create_object "$a_record" "$ip" "$ttl")
local obj=$(_create_object "$new_record" "$ip" "$ttl" "$rrtype")
_log "Created object: $obj"

local payload=$(_update_zone "$data" "$obj")
Expand All @@ -123,4 +130,4 @@ sub_update() {

echo "Success!"
exit 0
}
}
7 changes: 4 additions & 3 deletions func.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function _log() {
local msg=$1
logger -t "$prog" -i "${prog}: ${msg}"
if [[ "$DEBUGSYSLOG" = "true" ]] ;then logger -t "$prog" -i "${prog}: ${msg}";fi
if [[ "$DEBUGSTDERR" = "true" ]] ;then echo "$msg" >&2 ;fi
}

# autodns calls
Expand Down Expand Up @@ -169,8 +170,8 @@ function _create_object() {
local record=$1
local record_ip=$2
local record_ttl=$3

printf '{ "name": "%s", "ttl": %d, "type": "A", "value": "%s" }' "$record" "$record_ttl" "$record_ip"
local rrtype=$4
printf '{ "name": "%s", "ttl": %d, "type": "'$rrtype'", "value": "%s" }' "$record" "$record_ttl" "$record_ip"
}

# Adds a record (JSON object) to a zone (JSON object)
Expand Down