From 59c9abb9162b9ccb71d201631ec751014c6f5ea1 Mon Sep 17 00:00:00 2001 From: Antoine Lambert Date: Mon, 25 Jan 2021 14:04:09 +0100 Subject: [PATCH] bitbucket: Pick random credentials in configuration and improve logging Use random credentials from the list in configuration and improve related logging messages. --- swh/lister/bitbucket/lister.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/swh/lister/bitbucket/lister.py b/swh/lister/bitbucket/lister.py index 4feea74..f550003 100644 --- a/swh/lister/bitbucket/lister.py +++ b/swh/lister/bitbucket/lister.py @@ -6,6 +6,7 @@ from dataclasses import asdict, dataclass from datetime import datetime import logging +import random from typing import Any, Dict, Iterator, List, Optional from urllib import parse @@ -82,13 +83,11 @@ class BitbucketLister(Lister[BitbucketListerState, List[Dict[str, Any]]]): ) if len(self.credentials) > 0: - if len(self.credentials) > 1: - logger.warning( - "Bitbucket lister support only one username:password" - " pair as of now. Will use the first one." - ) - cred = self.credentials[0] + cred = random.choice(self.credentials) + logger.warning("Using Bitbucket credentials from user %s", cred["username"]) self.set_credentials(cred["username"], cred["password"]) + else: + logger.warning("No credentials set in configuration, using anonymous mode") def state_from_dict(self, d: Dict[str, Any]) -> BitbucketListerState: last_repo_cdate = d.get("last_repo_cdate")