How to use the twine.auth.Resolver function in twine

To help you get started, we’ve selected a few twine 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 pypa / twine / tests / test_auth.py View on Github external
        @staticmethod
        def get_credential(system, user):
            return cred(
                "real_user", "real_user@{system} sekure pa55word".format(**locals())
            )

        @staticmethod
        def get_password(system, user):
            cred = MockKeyring.get_credential(system, user)
            if user != cred.username:
                raise RuntimeError("unexpected username")
            return cred.password

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    res = auth.Resolver(config, cred())
    assert res.username == "real_user"
    assert res.password == "real_user@system sekure pa55word"
github pypa / twine / tests / test_auth.py View on Github external
def test_empty_password_bypasses_prompt(monkeypatch, entered_password, config):
    config.update(password="")
    pw = auth.Resolver(config, cred("user")).password
    assert pw == ""
github pypa / twine / tests / test_auth.py View on Github external
def test_get_password_keyring_overrides_prompt(monkeypatch, config):
    class MockKeyring:
        @staticmethod
        def get_password(system, user):
            return "{user}@{system} sekure pa55word".format(**locals())

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    pw = auth.Resolver(config, cred("user")).password
    assert pw == "user@system sekure pa55word"
github pypa / twine / tests / test_auth.py View on Github external
def test_get_username_keyring_missing_get_credentials_prompts(
    entered_username, keyring_missing_get_credentials, config
):
    assert auth.Resolver(config, cred()).username == "entered user"
github pypa / twine / tests / test_auth.py View on Github external
def test_no_password_defers_to_prompt(monkeypatch, entered_password, config):
    config.update(password=None)
    pw = auth.Resolver(config, cred("user")).password
    assert pw == "entered pw"
github pypa / twine / tests / test_auth.py View on Github external
def test_get_password_runtime_error_suppressed(
    entered_password, keyring_no_backends, recwarn, config
):
    assert auth.Resolver(config, cred("user")).password == "entered pw"
    assert len(recwarn) == 1
    warning = recwarn.pop(UserWarning)
    assert "fail!" in str(warning)
github pypa / twine / tests / test_auth.py View on Github external
def test_get_password_keyring_defers_to_prompt(monkeypatch, entered_password, config):
    class MockKeyring:
        @staticmethod
        def get_password(system, user):
            return

    monkeypatch.setattr(auth, "keyring", MockKeyring)

    pw = auth.Resolver(config, cred("user")).password
    assert pw == "entered pw"
github pypa / twine / twine / settings.py View on Github external
This defaults to ``False``
        """
        self.config_file = config_file
        self.comment = comment
        self.verbose = verbose
        self.disable_progress_bar = disable_progress_bar
        self.skip_existing = skip_existing
        self._handle_repository_options(
            repository_name=repository_name, repository_url=repository_url,
        )
        self._handle_package_signing(
            sign=sign, sign_with=sign_with, identity=identity,
        )
        # _handle_certificates relies on the parsed repository config
        self._handle_certificates(cacert, client_cert)
        self.auth = auth.Resolver.choose(not non_interactive)(
            self.repository_config, auth.CredentialInput(username, password),
        )
github pypa / twine / twine / auth.py View on Github external
warnings.warn(str(exc))
        return None

    def username_from_keyring_or_prompt(self) -> str:
        return self.get_username_from_keyring() or self.prompt("username", input)

    def password_from_keyring_or_prompt(self) -> str:
        return self.get_password_from_keyring() or self.prompt(
            "password", getpass.getpass
        )

    def prompt(self, what: str, how: Callable[..., str]) -> str:
        return how(f"Enter your {what}: ")


class Private(Resolver):
    def prompt(self, what: str, how: Optional[Callable[..., str]] = None) -> str:
        raise exceptions.NonInteractive(f"Credential not found for {what}.")