How to use the pygerrit2.HTTPBasicAuthFromNetrc function in pygerrit2

To help you get started, we’ve selected a few pygerrit2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dpursehouse / pygerrit2 / unittests.py View on Github external
def test_basic_auth_from_netrc_fails(self):
        """Test that an exception is raised when credentials are not found."""
        with self.assertRaises(ValueError) as exc:
            HTTPBasicAuthFromNetrc(url="http://review.example.com")
        assert str(exc.exception) == "netrc missing or no credentials found in netrc"
github dpursehouse / pygerrit2 / unittests.py View on Github external
def test_basic_auth_from_netrc(self):
        """Test that the HTTP basic auth is taken from netrc."""
        with patch("pygerrit2.rest.auth._get_netrc_auth") as mock_netrc:
            mock_netrc.return_value = ("netrcuser", "netrcpass")
            auth = HTTPBasicAuthFromNetrc(url="http://review.example.com")
            assert auth.username == "netrcuser"
            assert auth.password == "netrcpass"
github dpursehouse / pygerrit2 / example.py View on Github external
"--kerberos-auth may not be used together with "
                "--username, --password, --basic-auth or --netrc"
            )
        auth = HTTPKerberosAuth(mutual_authentication=OPTIONAL)
    elif options.username and options.password:
        if options.netrc:
            logging.warning("--netrc option ignored")
        if options.digest_auth:
            auth = HTTPDigestAuth(options.username, options.password)
        else:
            auth = HTTPBasicAuth(options.username, options.password)
    elif options.netrc:
        if options.digest_auth:
            auth = HTTPDigestAuthFromNetrc(url=options.gerrit_url)
        else:
            auth = HTTPBasicAuthFromNetrc(url=options.gerrit_url)
    else:
        auth = None

    rest = GerritRestAPI(url=options.gerrit_url, auth=auth)

    try:
        query = ["status:open"]
        if auth:
            query += ["owner:self"]
        else:
            query += ["limit:10"]
        changes = rest.get("/changes/?q=%s" % "%20".join(query))
        logging.info("%d changes", len(changes))
        for change in changes:
            logging.info(change["change_id"])
    except RequestException as err: