aboutsummaryrefslogtreecommitdiffstats
path: root/sync.py
diff options
context:
space:
mode:
Diffstat (limited to 'sync.py')
-rwxr-xr-xsync.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/sync.py b/sync.py
index bd26211..8388d25 100755
--- a/sync.py
+++ b/sync.py
@@ -156,13 +156,22 @@ def find_spec(s, url):
return urljoin(url, m[2])
+def handle_auth(s):
+ auth = get_config().get('auth')
+ if type(auth) == str:
+ # API-Key
+ s.headers.update({'Authorization': f'Api-Key {auth:s}'})
+ else:
+ # eg. HTTPBasicAuth('username', 'password')
+ s.auth = auth
+
def main():
open_db()
s = requests.Session()
retries = Retry(total=5, backoff_factor=1, status_forcelist=[ 502, 503, 504 ])
s.mount('https://', HTTPAdapter(max_retries=retries))
- s.auth = get_config()['auth']
+ handle_auth(s)
req_agent = s.headers.get('User-Agent')
s.headers.update({'User-Agent': f'peeringdb-simplesync/0.1 {req_agent:s}'})