From 0331ba4c7b764aaae0e88574f2fde739f4859d71 Mon Sep 17 00:00:00 2001 From: Nicolas Dandrimont Date: Tue, 13 Sep 2016 16:05:04 +0200 Subject: [PATCH] lister: Support multiple credentials --- bin/ghlister | 15 +++++++++++++++ swh/lister/github/lister.py | 6 ++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/ghlister b/bin/ghlister index da4c5d9..20665fe 100755 --- a/bin/ghlister +++ b/bin/ghlister @@ -100,6 +100,21 @@ def read_conf(args): else: conf['cache_json'] = False + if 'credentials' in conf: + credentials = conf['credentials'].split() + conf['credentials'] = [] + for user_pair in credentials: + username, password = user_pair.split(':') + conf['credentials'].append({ + 'username': username, + 'password': password, + }) + else: + conf['credentials'] = [{ + 'username': conf['username'], + 'password': conf['password'], + }] + return conf diff --git a/swh/lister/github/lister.py b/swh/lister/github/lister.py index 9bbde6a..05c85cb 100644 --- a/swh/lister/github/lister.py +++ b/swh/lister/github/lister.py @@ -7,6 +7,7 @@ import gzip import logging import os +import random import re import requests import time @@ -130,10 +131,7 @@ def fetch(conf, mk_session, min_id=None, max_id=None): max_id = float('inf') next_id = min_id - cred = {} - for key in ['username', 'password']: - if key in conf: - cred[key] = conf[key] + cred = random.choice(conf['credentials']) while min_id <= next_id <= max_id: logging.info('listing repos starting at %d' % next_id)