mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Various changes to try to implement a proper dry-run + proper list of stuff to create/update/delete
This commit is contained in:
parent
e4783aa00a
commit
d2dea2e94e
1 changed files with 23 additions and 20 deletions
|
@ -468,11 +468,26 @@ def domain_registrar_push(operation_logger, domain, dry_run=False):
|
||||||
if not registrar_settings:
|
if not registrar_settings:
|
||||||
raise YunohostValidationError("registrar_is_not_set", domain=domain)
|
raise YunohostValidationError("registrar_is_not_set", domain=domain)
|
||||||
|
|
||||||
# Generate the records
|
# Convert the generated conf into a format that matches what we'll fetch using the API
|
||||||
dns_conf = _build_dns_conf(domain)
|
# Makes it easier to compare "wanted records" with "current records on remote"
|
||||||
|
dns_conf = []
|
||||||
|
for records in _build_dns_conf(domain).values():
|
||||||
|
for record in records:
|
||||||
|
|
||||||
# Flatten the DNS conf
|
# Make sure we got "absolute" values instead of @
|
||||||
dns_conf = [record for records_for_category in dns_conf.values() for record in records_for_category]
|
name = f"{record['name']}.{domain}" if record["name"] != "@" else f".{domain}"
|
||||||
|
type_ = record["type"]
|
||||||
|
content = record["value"]
|
||||||
|
|
||||||
|
if content == "@" and record["type"] == "CNAME":
|
||||||
|
content = domain + "."
|
||||||
|
|
||||||
|
dns_conf.append({
|
||||||
|
"name": name,
|
||||||
|
"type": type_,
|
||||||
|
"ttl": record["ttl"],
|
||||||
|
"content": content
|
||||||
|
})
|
||||||
|
|
||||||
# FIXME Lexicon does not support CAA records
|
# FIXME Lexicon does not support CAA records
|
||||||
# See https://github.com/AnalogJ/lexicon/issues/282 and https://github.com/AnalogJ/lexicon/pull/371
|
# See https://github.com/AnalogJ/lexicon/issues/282 and https://github.com/AnalogJ/lexicon/pull/371
|
||||||
|
@ -480,18 +495,6 @@ def domain_registrar_push(operation_logger, domain, dry_run=False):
|
||||||
# And yet, it is still not done/merged
|
# And yet, it is still not done/merged
|
||||||
dns_conf = [record for record in dns_conf if record["type"] != "CAA"]
|
dns_conf = [record for record in dns_conf if record["type"] != "CAA"]
|
||||||
|
|
||||||
# We need absolute names? FIXME: should we add a trailing dot needed here ?
|
|
||||||
# Seems related to the fact that when fetching current records, they'll contain '.domain.tld' instead of @
|
|
||||||
# and we want to check if it already exists or not (c.f. create/update)
|
|
||||||
for record in dns_conf:
|
|
||||||
if record["name"] == "@":
|
|
||||||
record["name"] = f".{domain}"
|
|
||||||
else:
|
|
||||||
record["name"] = f"{record['name']}.{domain}"
|
|
||||||
|
|
||||||
if record["type"] == "CNAME" and record["value"] == "@":
|
|
||||||
record["value"] = domain + "."
|
|
||||||
|
|
||||||
# Construct the base data structure to use lexicon's API.
|
# Construct the base data structure to use lexicon's API.
|
||||||
base_config = {
|
base_config = {
|
||||||
"provider_name": registrar_settings["name"],
|
"provider_name": registrar_settings["name"],
|
||||||
|
@ -499,13 +502,11 @@ def domain_registrar_push(operation_logger, domain, dry_run=False):
|
||||||
registrar_settings["name"]: registrar_settings["options"]
|
registrar_settings["name"]: registrar_settings["options"]
|
||||||
}
|
}
|
||||||
|
|
||||||
operation_logger.start()
|
|
||||||
|
|
||||||
# Fetch all types present in the generated records
|
# Fetch all types present in the generated records
|
||||||
current_remote_records = []
|
current_remote_records = []
|
||||||
|
|
||||||
# Get unique types present in the generated records
|
# Get unique types present in the generated records
|
||||||
types = {record["type"] for record in dns_conf}
|
types = ["A", "AAAA", "MX", "TXT", "CNAME", "SRV"]
|
||||||
|
|
||||||
for key in types:
|
for key in types:
|
||||||
print("fetcing type: " + key)
|
print("fetcing type: " + key)
|
||||||
|
@ -525,6 +526,8 @@ def domain_registrar_push(operation_logger, domain, dry_run=False):
|
||||||
if dry_run:
|
if dry_run:
|
||||||
return {"current_records": current_remote_records, "dns_conf": dns_conf, "changes": changes}
|
return {"current_records": current_remote_records, "dns_conf": dns_conf, "changes": changes}
|
||||||
|
|
||||||
|
operation_logger.start()
|
||||||
|
|
||||||
# Push the records
|
# Push the records
|
||||||
for record in dns_conf:
|
for record in dns_conf:
|
||||||
|
|
||||||
|
@ -547,7 +550,7 @@ def domain_registrar_push(operation_logger, domain, dry_run=False):
|
||||||
# See https://github.com/AnalogJ/lexicon/issues/726 (similar issue)
|
# See https://github.com/AnalogJ/lexicon/issues/726 (similar issue)
|
||||||
# But I think there is another issue with Gandi. Or I'm misusing the API...
|
# But I think there is another issue with Gandi. Or I'm misusing the API...
|
||||||
if base_config["provider_name"] == "gandi":
|
if base_config["provider_name"] == "gandi":
|
||||||
del record_to_push["ttle"]
|
del record_to_push["ttl"]
|
||||||
|
|
||||||
print("pushed_record:", record_to_push)
|
print("pushed_record:", record_to_push)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue