bitbucket: Pick random credentials in configuration and improve logging

Use random credentials from the list in configuration and improve related
logging messages.
This commit is contained in:
Antoine Lambert 2021-01-25 14:04:09 +01:00
parent ce87a8f7b2
commit 59c9abb916

View file

@ -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")