aboutsummaryrefslogtreecommitdiffstats
path: root/sync.py
diff options
context:
space:
mode:
authorAsbjørn Sloth Tønnesen <ast@fiberby.net>2021-05-25 18:25:58 +0000
committerAsbjørn Sloth Tønnesen <ast@fiberby.net>2021-05-25 18:38:35 +0000
commit1f5cebcc57313ecc446929af90a6383f91edbf4f (patch)
treea45665266464ccacc55c1d9fef9fcc0e08cdc6e0 /sync.py
parent966b99a1a0eb13d2aa88d656116fc3d9e9acd874 (diff)
downloadpeeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.tar.gz
peeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.tar.xz
peeringdb-simplesync-1f5cebcc57313ecc446929af90a6383f91edbf4f.zip
add support for api-keysHEADmaster
Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
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}'})