diff options
author | Asbjørn Sloth Tønnesen <ast@fiberby.net> | 2021-05-25 18:25:58 +0000 |
---|---|---|
committer | Asbjørn Sloth Tønnesen <ast@fiberby.net> | 2021-05-25 18:38:35 +0000 |
commit | 1f5cebcc57313ecc446929af90a6383f91edbf4f (patch) | |
tree | a45665266464ccacc55c1d9fef9fcc0e08cdc6e0 /sync.py | |
parent | 966b99a1a0eb13d2aa88d656116fc3d9e9acd874 (diff) | |
download | peeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.tar.gz peeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.tar.xz peeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.zip |
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Diffstat (limited to 'sync.py')
-rwxr-xr-x | sync.py | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -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}'}) |