mirror of
https://gitlab.wikimedia.org/ladsgroup/Phabricator-maintenance-bot
synced 2024-11-25 05:22:39 +01:00
Merge pull request #13 from urbanecm/simplify-dns
new_wikis_handler: Simplify DNS checkbox's logic
This commit is contained in:
commit
78cde6376b
1 changed files with 10 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
import socket
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
@ -22,18 +23,12 @@ def get_file_from_gerrit(path):
|
||||||
return base64.b64decode(requests.get(url).text).decode('utf-8')
|
return base64.b64decode(requests.get(url).text).decode('utf-8')
|
||||||
|
|
||||||
|
|
||||||
def handle_non_special_wikis(parts, language_code):
|
def hostname_resolves(hostname):
|
||||||
if language_code != parts[0]:
|
try:
|
||||||
return
|
socket.gethostbyname(hostname)
|
||||||
dns_file = get_file_from_gerrit('operations/dns/+/master/templates/helpers/langlist.tmpl')
|
except socket.error:
|
||||||
return f"'{language_code}'" in dns_file
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
def handle_special_wiki_dns(parts):
|
|
||||||
dns_file = get_file_from_gerrit('operations/dns/+/master/templates/wikimedia.org')
|
|
||||||
name = parts[0]
|
|
||||||
return f"\n{name}" in dns_file
|
|
||||||
|
|
||||||
|
|
||||||
def handle_special_wiki_apache(parts):
|
def handle_special_wiki_apache(parts):
|
||||||
apache_file = get_file_from_gerrit('operations/puppet/+/production/modules/mediawiki/manifests/web/prod_sites.pp')
|
apache_file = get_file_from_gerrit('operations/puppet/+/production/modules/mediawiki/manifests/web/prod_sites.pp')
|
||||||
|
@ -84,15 +79,10 @@ def hande_task(phid):
|
||||||
if len(parts) != 3 or parts[2] != 'org':
|
if len(parts) != 3 or parts[2] != 'org':
|
||||||
return
|
return
|
||||||
|
|
||||||
if parts[1] == 'wikimedia':
|
special = parts[1] == 'wikimedia'
|
||||||
dns = handle_special_wiki_dns(parts)
|
dns_url = gerrit_path + 'operations/dns/+/master/templates/wikimedia.org' if special else gerrit_path + 'operations/dns/+/master/templates/helpers/langlist.tmpl'
|
||||||
special = True
|
|
||||||
dns_url = gerrit_path + 'operations/dns/+/master/templates/wikimedia.org'
|
|
||||||
|
|
||||||
else:
|
dns = hostname_resolves(url)
|
||||||
dns = handle_non_special_wikis(parts, language_code)
|
|
||||||
dns_url = gerrit_path + 'operations/dns/+/master/templates/helpers/langlist.tmpl'
|
|
||||||
special = False
|
|
||||||
if not dns:
|
if not dns:
|
||||||
add_text(' [] [[{}|DNS]]'.format(dns_url))
|
add_text(' [] [[{}|DNS]]'.format(dns_url))
|
||||||
if special:
|
if special:
|
||||||
|
|
Loading…
Reference in a new issue