Compare commits
No commits in common. "main" and "v1.0.0" have entirely different histories.
6 changed files with 25 additions and 105 deletions
29
install.sh
29
install.sh
|
@ -1,29 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
destination="/usr/local/bin"
|
|
||||||
while [ $# -gt 0 ]
|
|
||||||
do
|
|
||||||
case "$1" in
|
|
||||||
"--help"|"-h"|"-?")
|
|
||||||
usage
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
"--destination"|"-d")
|
|
||||||
shift
|
|
||||||
destination="${1}"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Ignoring unknwon parameter '${1}'"
|
|
||||||
shift
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ ! -e "${HOME}/.config/ovh_dns_ensure.conf" ]; then
|
|
||||||
touch "${HOME}/.config/ovh_dns_ensure.conf"
|
|
||||||
fi
|
|
||||||
chmod go-rwx "${HOME}/.config/ovh_dns_ensure.conf"
|
|
||||||
|
|
||||||
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
||||||
sed "s#__src_folder__#${script_dir}#g" "${script_dir}/wrapper.sh" > "${destination}/ovh_dns_ensure.sh"
|
|
||||||
chmod +x "${destination}/ovh_dns_ensure.sh"
|
|
|
@ -1,10 +1,9 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
if [ ! -d "$(dirname "${0}")/.venv" ]; then
|
||||||
if [ ! -d "${script_dir}/.venv" ]; then
|
python -m venv "$(dirname "${0}")/.venv"
|
||||||
python -m venv "$script_dir/.venv"
|
|
||||||
fi
|
fi
|
||||||
# shellcheck disable=1091
|
# shellcheck disable=1091
|
||||||
source "$script_dir/.venv/bin/activate"
|
source "$(dirname "${0}")/.venv/bin/activate"
|
||||||
pip install -r "$script_dir/requirements.txt" > /dev/null
|
pip install -r "$(dirname "${0}")/requirements.txt" > /dev/null
|
||||||
pip install "$script_dir/" > /dev/null
|
pip install "$(dirname "${0}")/" > /dev/null
|
||||||
ovh_dns_ensure.py "${@}"
|
ovh_dns_ensure.py "${@}"
|
||||||
|
|
0
ovh_dns_ensure/__init__.py
Executable file → Normal file
0
ovh_dns_ensure/__init__.py
Executable file → Normal file
68
ovh_dns_ensure/ovh_dns_ensure.py
Executable file → Normal file
68
ovh_dns_ensure/ovh_dns_ensure.py
Executable file → Normal file
|
@ -68,62 +68,45 @@ class OvhDnsEnsure:
|
||||||
)
|
)
|
||||||
self._log.debug(result)
|
self._log.debug(result)
|
||||||
elif self.current_state == 'different':
|
elif self.current_state == 'different':
|
||||||
if not self.config['allow_multiple']:
|
count = 0
|
||||||
for record in self.records:
|
for record in self.records:
|
||||||
|
if count > 0:
|
||||||
if not self.config['dummy']:
|
if not self.config['dummy']:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
'Deleting record %s',
|
'Deleting record %s',
|
||||||
record
|
record
|
||||||
)
|
)
|
||||||
result = self.ovh.delete(
|
result = self.ovh.delete(f"/domain/zone/{self.config['zone']}/record/{record}")
|
||||||
f"/domain/zone/{self.config['zone']}/record/{record}"
|
self._log.debug(result)
|
||||||
|
else:
|
||||||
|
self._log.debug(
|
||||||
|
'Changing record %s',
|
||||||
|
record
|
||||||
|
)
|
||||||
|
if not self.config['dummy']:
|
||||||
|
result = self.ovh.put(f"/domain/zone/{self.config['zone']}/record/{record}",
|
||||||
|
subDomain = self.config['subdomain'],
|
||||||
|
target = self.config['target'],
|
||||||
|
ttl = self.config['ttl'],
|
||||||
)
|
)
|
||||||
self._log.debug(result)
|
self._log.debug(result)
|
||||||
else:
|
count += 1
|
||||||
self._log.debug(
|
|
||||||
"Not deleting existing records since we were called with --allow-multiple."
|
|
||||||
)
|
|
||||||
self._log.debug(
|
|
||||||
"Creating new record..."
|
|
||||||
)
|
|
||||||
if not self.config['dummy']:
|
|
||||||
result = self.ovh.post(f"/domain/zone/{self.config['zone']}/record/",
|
|
||||||
subDomain = self.config['subdomain'],
|
|
||||||
fieldType = self.config['type'],
|
|
||||||
target = self.config['target'],
|
|
||||||
ttl = self.config['ttl'],
|
|
||||||
)
|
|
||||||
self._log.debug(result)
|
|
||||||
|
|
||||||
|
|
||||||
def _get_current_state(self):
|
def _get_current_state(self):
|
||||||
params = {
|
params = {
|
||||||
# "fieldType": self.config['type'],
|
"fieldType": self.config['type'],
|
||||||
"subDomain": self.config['subdomain']
|
"subDomain": self.config['subdomain']
|
||||||
}
|
}
|
||||||
self._log.debug(
|
|
||||||
"Getting all records with subdomain '%s'...",
|
|
||||||
# self.config['type'],
|
|
||||||
self.config['subdomain']
|
|
||||||
)
|
|
||||||
self.records = self.ovh.get(f"/domain/zone/{self.config['zone']}/record", **params)
|
self.records = self.ovh.get(f"/domain/zone/{self.config['zone']}/record", **params)
|
||||||
self.current_state = 'absent'
|
self.current_state = 'absent'
|
||||||
for record in self.records:
|
for record in self.records:
|
||||||
self._log.debug(
|
|
||||||
"Checking record: %s...",
|
|
||||||
record
|
|
||||||
)
|
|
||||||
data = self.ovh.get(f"/domain/zone/{self.config['zone']}/record/{record}")
|
data = self.ovh.get(f"/domain/zone/{self.config['zone']}/record/{record}")
|
||||||
if data['target'] == self.config['target'] and data['ttl'] == self.config['ttl']:
|
if data['target'] == self.config['target'] and data['ttl'] == self.config['ttl']:
|
||||||
self.current_state = 'same'
|
self.current_state = 'same'
|
||||||
self._log.debug(
|
self._log.debug('A record with the same type, TTL and target exists. %s', data)
|
||||||
'A record with the same type, TTL and target exists. %s',
|
|
||||||
data
|
|
||||||
)
|
|
||||||
if self.current_state == 'absent' and len(self.records) == 0:
|
if self.current_state == 'absent' and len(self.records) == 0:
|
||||||
self._log.debug(
|
self._log.debug("Doesn't exist a record with that type and target")
|
||||||
"Doesn't exist a record with that type and target"
|
|
||||||
)
|
|
||||||
elif self.current_state == 'absent' and len(self.records) > 0:
|
elif self.current_state == 'absent' and len(self.records) > 0:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
"There are %s records with same type but different target or TTL",
|
"There are %s records with same type but different target or TTL",
|
||||||
|
@ -217,10 +200,7 @@ class OvhDnsEnsure:
|
||||||
required=True,
|
required=True,
|
||||||
default='A',
|
default='A',
|
||||||
type=click.Choice(
|
type=click.Choice(
|
||||||
[
|
["A", "AAAA", "CAA", "CNAME", "DKIM", "DMARC", "DNAME", "LOC", "MX", "NAPTR", "NS", "PTR", "SPF", "SRV", "SSHFP", "TLSA", "TXT"],
|
||||||
"A", "AAAA", "CAA", "CNAME", "DKIM",
|
|
||||||
"DMARC", "DNAME", "LOC", "MX", "NAPTR",
|
|
||||||
"NS", "PTR", "SPF", "SRV", "SSHFP", "TLSA", "TXT"],
|
|
||||||
case_sensitive=False,
|
case_sensitive=False,
|
||||||
),
|
),
|
||||||
help='DNS record type'
|
help='DNS record type'
|
||||||
|
@ -281,14 +261,6 @@ class OvhDnsEnsure:
|
||||||
),
|
),
|
||||||
help='OVH Server to use.'
|
help='OVH Server to use.'
|
||||||
)
|
)
|
||||||
@click.option(
|
|
||||||
'--allow-multiple',
|
|
||||||
'-m',
|
|
||||||
is_flag=True,
|
|
||||||
default=False,
|
|
||||||
required=True,
|
|
||||||
help='OVH Consumer key. Better use the configuration file for safety.'
|
|
||||||
)
|
|
||||||
@click_config_file.configuration_option()
|
@click_config_file.configuration_option()
|
||||||
def __main__(**kwargs):
|
def __main__(**kwargs):
|
||||||
return OvhDnsEnsure(**kwargs)
|
return OvhDnsEnsure(**kwargs)
|
||||||
|
|
0
setup.py
Executable file → Normal file
0
setup.py
Executable file → Normal file
22
wrapper.sh
22
wrapper.sh
|
@ -1,22 +0,0 @@
|
||||||
#!/bin/bash
|
|
||||||
if [ -z "${HOME}" ]; then
|
|
||||||
if [ "$(whoami)" == "root" ]; then
|
|
||||||
HOME="/root"
|
|
||||||
else
|
|
||||||
HOME=$(grep "$(whoami)" /etc/passwd | awk 'BEGIN {FS=":"} {print($6)}')
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
CONFIG_FILE="${HOME}/.config/ovh_dns_ensure.conf"
|
|
||||||
cd "__src_folder__" || exit 1
|
|
||||||
if [ -r "${CONFIG_FILE}" ]; then
|
|
||||||
perms=$(stat -c %A "${CONFIG_FILE}")
|
|
||||||
if [ "${perms:4:6}" != '------' ]; then
|
|
||||||
echo "Permissions too open for config file '${CONFIG_FILE}' ($perms). Remove all permissions to group and others."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
config=(--config "${CONFIG_FILE}")
|
|
||||||
else
|
|
||||||
config=()
|
|
||||||
fi
|
|
||||||
"__src_folder__/ovh_dns_ensure.sh" "${config[@]}" "${@}"
|
|
Loading…
Reference in a new issue