Skip to content

Commit cda7a2c

Browse files
authored
Merge pull request #10 from sonatype-nexus-community/feat/programatic-authentication
feat: support providing authentication directly over loading from configuration file
2 parents e261200 + 1bda4a9 commit cda7a2c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

ossindex/ossindex.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,19 @@ class OssIndex:
5858
_oss_max_coordinates_per_request: int = 128
5959
_oss_index_authentication: Optional[requests.auth.HTTPBasicAuth] = None
6060

61-
def __init__(self, *, enable_cache: bool = True, cache_location: Optional[str] = None) -> None:
61+
def __init__(self, *, enable_cache: bool = True, cache_location: Optional[str] = None,
62+
username: Optional[str] = None, password: Optional[str] = None) -> None:
6263
self._caching_enabled = enable_cache
6364
if self._caching_enabled:
6465
logger.info('OssIndex caching is ENABLED')
6566
self._setup_cache(cache_location=cache_location)
66-
self._attempt_config_load()
67+
68+
if username and password:
69+
logger.debug('Using supplied credentials for OSS Index')
70+
self._oss_index_authentication = requests.auth.HTTPBasicAuth(username, password)
71+
else:
72+
logger.debug('Attempting to load credentials for OSS Index from configuration file')
73+
self._attempt_config_load()
6774

6875
def has_ossindex_authentication(self) -> bool:
6976
return self._oss_index_authentication is not None

0 commit comments

Comments
 (0)