Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Credential Logging #685

Merged
merged 4 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions twine/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
import getpass
import logging
import warnings
from typing import Callable
from typing import Optional
Expand All @@ -11,6 +12,8 @@
from twine import exceptions
from twine import utils

logger = logging.getLogger(__name__)


class CredentialInput:
def __init__(
Expand Down Expand Up @@ -73,12 +76,20 @@ def get_password_from_keyring(self) -> Optional[str]:
return None

def username_from_keyring_or_prompt(self) -> str:
return self.get_username_from_keyring() or self.prompt("username", input)
username_from_keyring = self.get_username_from_keyring()
if username_from_keyring:
logger.info("Username set via Keyring")
return username_from_keyring
bhrutledge marked this conversation as resolved.
Show resolved Hide resolved

return self.prompt("username", input)

def password_from_keyring_or_prompt(self) -> str:
return self.get_password_from_keyring() or self.prompt(
"password", getpass.getpass
)
password_from_keyring = self.get_password_from_keyring()
if password_from_keyring:
logger.info("Password set via Keyring")
return password_from_keyring

return self.prompt("password", getpass.getpass)

def prompt(self, what: str, how: Callable[..., str]) -> str:
return how(f"Enter your {what}: ")
Expand Down
6 changes: 6 additions & 0 deletions twine/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import sys
from typing import Any
from typing import Dict
Expand Down Expand Up @@ -39,6 +40,8 @@
TEST_WAREHOUSE = "https://test.pypi.org/"
WAREHOUSE_WEB = "https://pypi.org/"

logger = logging.getLogger(__name__)


class ProgressBar(tqdm.tqdm):
def update_to(self, n: int) -> None:
Expand Down Expand Up @@ -67,6 +70,9 @@ def __init__(
self.session.auth = (
(username or "", password or "") if username or password else None
)
logger.info("Password is : placeholder")
bhrutledge marked this conversation as resolved.
Show resolved Hide resolved
logger.info(f"Username is : {username}")

self.session.headers["User-Agent"] = self._make_user_agent_string()
for scheme in ("http://", "https://"):
self.session.mount(scheme, self._make_adapter_with_retries())
Expand Down
2 changes: 2 additions & 0 deletions twine/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ def get_userpass_value(
:rtype: unicode
"""
if cli_value is not None:
logger.info(f"{key} set via CLI")
bhrutledge marked this conversation as resolved.
Show resolved Hide resolved
return cli_value
elif config.get(key) is not None:
logger.info(f"{key} set via .pypirc config file")
bhrutledge marked this conversation as resolved.
Show resolved Hide resolved
return config[key]
elif prompt_strategy:
return prompt_strategy()
Expand Down