From 1f5cebcc57313ecc446929af90a6383f91edbf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Sloth=20T=C3=B8nnesen?= Date: Tue, 25 May 2021 18:25:58 +0000 Subject: add support for api-keys MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Asbjørn Sloth Tønnesen --- sync.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'sync.py') 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}'}) -- cgit v1.2.1