Skip to content
Snippets Groups Projects
Commit 023dd3b7 authored by ale's avatar ale
Browse files

resolve shard names to IPs

parent a31232ac
No related branches found
No related tags found
No related merge requests found
import socket
import threading
from flask import Flask, request, abort, make_response from flask import Flask, request, abort, make_response
from authserv.app_common import do_auth from authserv.app_common import do_auth
...@@ -5,6 +7,16 @@ app = Flask(__name__) ...@@ -5,6 +7,16 @@ app = Flask(__name__)
_default_port_map = {'imap': 143, 'pop3': 110} _default_port_map = {'imap': 143, 'pop3': 110}
_dns_cache = {}
_dns_cache_lock = threading.Lock()
def _shard_to_ip(shard):
hostname = '%s-vpn' % shard
with _dns_cache_lock:
if hostname not in _dns_cache:
_dns_cache[hostname] = socket.gethostbyname(hostname)
return _dns_cache[hostname]
@app.route('/', methods=('GET',)) @app.route('/', methods=('GET',))
def do_nginx_http_auth(): def do_nginx_http_auth():
...@@ -32,7 +44,7 @@ def do_nginx_http_auth(): ...@@ -32,7 +44,7 @@ def do_nginx_http_auth():
response = make_response('') response = make_response('')
if auth_status == 'OK': if auth_status == 'OK':
response.headers['Auth-Status'] = 'OK' response.headers['Auth-Status'] = 'OK'
response.headers['Auth-Server'] = shard response.headers['Auth-Server'] = _shard_to_ip(shard)
response.headers['Auth-Port'] = str( response.headers['Auth-Port'] = str(
app.config.get('NGINX_AUTH_PORT_MAP', _default_port_map)[protocol]) app.config.get('NGINX_AUTH_PORT_MAP', _default_port_map)[protocol])
else: else:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment