Uncomment push_config function

This commit is contained in:
Paco 2021-05-21 10:36:04 +02:00
parent 51d6d19810
commit 5859028022

View file

@ -29,8 +29,8 @@ import sys
import yaml import yaml
import functools import functools
# from lexicon.config import ConfigResolver from lexicon.config import ConfigResolver
# from lexicon.client import Client from lexicon.client import Client
from moulinette import m18n, msettings, msignals from moulinette import m18n, msettings, msignals
from moulinette.core import MoulinetteError from moulinette.core import MoulinetteError
@ -873,104 +873,104 @@ def domain_registrar_set(domain, registrar, args):
# def domain_push_config(domain): def domain_push_config(domain):
# """ """
# Send DNS records to the previously-configured registrar of the domain. Send DNS records to the previously-configured registrar of the domain.
# """ """
# # Generate the records # Generate the records
# if domain not in domain_list()["domains"]: if domain not in domain_list()["domains"]:
# raise YunohostValidationError("domain_name_unknown", domain=domain) raise YunohostValidationError("domain_name_unknown", domain=domain)
# domains_settings = _get_domain_settings(domain, True) domains_settings = _get_domain_settings(domain, True)
# dns_conf = _build_dns_conf(domains_settings) dns_conf = _build_dns_conf(domains_settings)
# # Flatten the DNS conf # Flatten the DNS conf
# flatten_dns_conf = [] flatten_dns_conf = []
# for key in dns_conf: for key in dns_conf:
# list_of_records = dns_conf[key] list_of_records = dns_conf[key]
# for record in list_of_records: for record in list_of_records:
# # 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
# # They say it's trivial to implement it! # They say it's trivial to implement it!
# # And yet, it is still not done/merged # And yet, it is still not done/merged
# if record["type"] != "CAA": if record["type"] != "CAA":
# # Add .domain.tdl to the name entry # Add .domain.tdl to the name entry
# record["name"] = "{}.{}".format(record["name"], domain) record["name"] = "{}.{}".format(record["name"], domain)
# flatten_dns_conf.append(record) flatten_dns_conf.append(record)
# # Get provider info # Get provider info
# # TODO # TODO
# provider = { provider = {
# "name": "gandi", "name": "gandi",
# "options": { "options": {
# "api_protocol": "rest", "api_protocol": "rest",
# "auth_token": "vhcIALuRJKtoZiZyxfDYWLom" "auth_token": "vhcIALuRJKtoZiZyxfDYWLom"
# } }
# } }
# # 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": provider["name"], "provider_name": provider["name"],
# "domain": domain, # domain name "domain": domain, # domain name
# } }
# base_config[provider["name"]] = provider["options"] base_config[provider["name"]] = provider["options"]
# # Get types present in the generated records # Get types present in the generated records
# types = set() types = set()
# for record in flatten_dns_conf: for record in flatten_dns_conf:
# types.add(record["type"]) types.add(record["type"])
# # Fetch all types present in the generated records # Fetch all types present in the generated records
# distant_records = {} distant_records = {}
# for key in types: for key in types:
# record_config = { record_config = {
# "action": "list", "action": "list",
# "type": key, "type": key,
# } }
# final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config) final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config)
# # print('final_lexicon:', final_lexicon); # print('final_lexicon:', final_lexicon);
# client = Client(final_lexicon) client = Client(final_lexicon)
# distant_records[key] = client.execute() distant_records[key] = client.execute()
# for key in types: for key in types:
# for distant_record in distant_records[key]: for distant_record in distant_records[key]:
# print('distant_record:', distant_record); print('distant_record:', distant_record);
# for local_record in flatten_dns_conf: for local_record in flatten_dns_conf:
# print('local_record:', local_record); print('local_record:', local_record);
# # Push the records # Push the records
# for record in flatten_dns_conf: for record in flatten_dns_conf:
# # For each record, first check if one record exists for the same (type, name) couple # For each record, first check if one record exists for the same (type, name) couple
# it_exists = False it_exists = False
# # TODO do not push if local and distant records are exactly the same ? # TODO do not push if local and distant records are exactly the same ?
# # is_the_same_record = False # is_the_same_record = False
# for distant_record in distant_records[record["type"]]: for distant_record in distant_records[record["type"]]:
# if distant_record["type"] == record["type"] and distant_record["name"] == record["name"]: if distant_record["type"] == record["type"] and distant_record["name"] == record["name"]:
# it_exists = True it_exists = True
# # previous TODO # previous TODO
# # if distant_record["ttl"] = ... and distant_record["name"] ... # if distant_record["ttl"] = ... and distant_record["name"] ...
# # is_the_same_record = True # is_the_same_record = True
# # Finally, push the new record or update the existing one # Finally, push the new record or update the existing one
# record_config = { record_config = {
# "action": "update" if it_exists else "create", # create, list, update, delete "action": "update" if it_exists else "create", # create, list, update, delete
# "type": record["type"], # specify a type for record filtering, case sensitive in some cases. "type": record["type"], # specify a type for record filtering, case sensitive in some cases.
# "name": record["name"], "name": record["name"],
# "content": record["value"], "content": record["value"],
# # FIXME Delte TTL, doesn't work with Gandi. # FIXME Delte TTL, doesn't work with Gandi.
# # 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...
# # "ttl": record["ttl"], # "ttl": record["ttl"],
# } }
# final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config) final_lexicon = ConfigResolver().with_dict(dict_object=base_config).with_dict(dict_object=record_config)
# client = Client(final_lexicon) client = Client(final_lexicon)
# print('pushed_record:', record_config, "→", end=' ') print('pushed_record:', record_config, "", end=' ')
# results = client.execute() results = client.execute()
# print('results:', results); print('results:', results);
# # print("Failed" if results == False else "Ok") # print("Failed" if results == False else "Ok")
# def domain_config_fetch(domain, key, value): # def domain_config_fetch(domain, key, value):