def test_fqdn(): """ Tests fqdn """ domain = "foobar.baz" hostnames = [ "foo", "foo.foobar.baz", "foo.foobar.baz.", ] for hostname in hostnames: assert test.fqdn(hostname, domain, relative=False) == "foo.foobar.baz." assert test.fqdn(hostname, domain, relative=True) == "foo.foobar.baz" assert test.fqdn(hostname, domain) == "foo.foobar.baz"
def gdomain_del(browser: Browser, domain: str, hostname: str) -> None: """ Deletes the passed-in hostname from Google Domains WARNING: THIS SEEMS BRITTLE """ hostname = fqdn(hostname, domain) # find the right div for this hostname records = get_synthetic_records_div(browser) # xpath = "//div[contains(@class, 'H2OGROB-d-t')]" xpath = f"//div[contains(text(), '{hostname}')]/../.." divs = records.find_by_xpath(xpath) div = divs.first # click the delete button delete_button = get_element_by_substring("Delete", div.find_by_tag("button")) delete_button.click() # wait for the modal dialog wait_for_tag(browser, "h3", "Delete synthetic record?") # get the form element for the modal dialog modal_form = get_element_by_substring( "Delete synthetic record?", browser.find_by_tag("form") ) modal_button = get_element_by_substring("Delete", modal_form.find_by_tag("button")) modal_button.click() wait_for_success_notification(browser)
def api_del(browser: Browser, domain: str, hostname: str) -> None: """ Deletes the redirect """ hostname = fqdn(hostname, domain) entries = gdomain_ls(browser, domain) if hostname not in entries: print(f"Hostname not found: {hostname}. Doing nothing.") return gdomain_del(browser, domain, hostname) if is_verbose(): api_ls(browser, domain)
def gdomain_add(browser: Browser, domain: str, hostname: str, target: str) -> None: """ Adds a redirect from the hostname to the target url """ hostname = un_fqdn(fqdn(hostname, domain), domain) # make sure hostname is good records = get_synthetic_records_div(browser) get_element_by_placeholder(records, "Subdomain").fill(hostname) get_element_by_placeholder(records, "Destination URL").fill(target) records.find_by_text("Temporary redirect (302)").click() records.find_by_text("Forward path").click() records.find_by_text("Enable SSL").click() button = records.find_by_text("Add") button.click() wait_for_success_notification(browser)
def api_add(browser: Browser, domain: str, hostname: str, target: str) -> None: """ Adds the hostname-to-target redirect to Google Domains """ hostname = fqdn(hostname, domain) entries = gdomain_ls(browser, domain) # if its already here and pointed to the right place, do nothing if hostname in entries and entries[hostname] == target: print(f"{hostname} already exists. Doing nothing.") return # if its already here, and pointed to the wrong place. delete it if hostname in entries: gdomain_del(browser, domain, hostname) gdomain_add(browser, domain, hostname, target) if is_verbose(): api_ls(browser, domain)