diff --git a/swh/lister/gogs/lister.py b/swh/lister/gogs/lister.py --- a/swh/lister/gogs/lister.py +++ b/swh/lister/gogs/lister.py @@ -50,10 +50,15 @@ Gogs API documentation: https://github.com/gogs/docs-api - The API is protected behind authentication so credentials/API tokens - are mandatory. It supports pagination and provides next page URL - through the 'next' value of the 'Link' header. The default value for - page size ('limit') is 10 but the maximum allowed value is 50. + The API may be protected behind authentication so credentials/API tokens can be + provided. + + The lister supports pagination and provides next page URL through the 'next' value + of the 'Link' header. The default value for page size ('limit') is 10 but the + maximum allowed value is 50. + + Api can usually be found at the location: https:///api/v1/repos/search + """ LISTER_NAME = "gogs" @@ -90,17 +95,15 @@ username = cred.get("username") self.api_token = cred["password"] logger.info("Using authentication credentials from user %s", username) - else: - # Raises an error on Gogs, or a warning on Gitea - self.on_anonymous_mode() self.session.headers.update({"Accept": "application/json"}) if self.api_token: self.session.headers["Authorization"] = f"token {self.api_token}" - - def on_anonymous_mode(self): - raise ValueError("No credentials or API token provided") + else: + logger.warning( + "No authentication token set in configuration, using anonymous mode" + ) def state_from_dict(self, d: Dict[str, Any]) -> GogsListerState: return GogsListerState(**d) @@ -153,7 +156,6 @@ while next_link is not None: repos = self.extract_repos(body) - assert len(links) > 0, "API changed: no Link header found" if "next" in links: next_link = links["next"]["url"] else: diff --git a/swh/lister/gogs/tests/test_lister.py b/swh/lister/gogs/tests/test_lister.py --- a/swh/lister/gogs/tests/test_lister.py +++ b/swh/lister/gogs/tests/test_lister.py @@ -139,16 +139,16 @@ def test_gogs_auth_instance( swh_scheduler, requests_mock, trygogs_p1, trygogs_p2, trygogs_p3_empty ): - """Covers token authentication, token from credentials, + """Covers without authentication, token authentication, token from credentials, instance inference from URL.""" api_token = "secret" instance = "try_gogs" # Test lister initialization without api_token or credentials: - with pytest.raises(ValueError, match="No credentials or API token provided"): - kwargs1 = dict(url=TRY_GOGS_URL, instance=instance) - GogsLister(scheduler=swh_scheduler, **kwargs1) + kwargs1 = dict(url=TRY_GOGS_URL, instance=instance) + lister = GogsLister(scheduler=swh_scheduler, **kwargs1) + assert "Authorization" not in lister.session.headers # Test lister initialization using api_token: kwargs2 = dict(url=TRY_GOGS_URL, api_token=api_token, instance=instance)