Skip to content

Add/warn message #105

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

Open
wants to merge 7 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]
### Added
- Warning message regarding PyPI token revoke
- `generate_template_pyproject_toml` in `functions.py`
### Changed
- `batch_upload` method in `uploader.py`
- `upload` method in `uploader.py`
- `generate_template_setup_py` in `functions.py`
- package build command in `publish_pypi.yml`
Expand Down
3 changes: 3 additions & 0 deletions reserver/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
INVALID_INPUT_USER_PARAM = "Invalid input for user params."
UNEQUAL_PARAM_NAME_LENGTH_ERROR = "You should pass either one single file path to be used for the package parameters \
or per each package name, there should be a specific dedicated file path."

MAIN_PYPI_REVOKE_TOKEN_MESSAGE = "Security Tip: Please consider revoking your PyPI token from https://pypi.org/manage/account/token if no longer needed."
TEST_PYPI_REVOKE_TOKEN_MESSAGE = "Security Tip: Please consider revoking your test PyPI token from https://test.pypi.org/manage/account/token if no longer needed."
21 changes: 16 additions & 5 deletions reserver/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from .functions import generate_template_setup_py
from subprocess import check_output, CalledProcessError
from .params import UNEQUAL_PARAM_NAME_LENGTH_ERROR
from .params import MAIN_PYPI_REVOKE_TOKEN_MESSAGE, TEST_PYPI_REVOKE_TOKEN_MESSAGE
from .utils import has_named_parameter, remove_dir, read_json


Expand Down Expand Up @@ -46,33 +47,40 @@ def batch_upload(self, names, user_params_path=None):
reserved_successfully = 0
if user_params_path is None:
for name in names:
if self.upload(name):
if self.upload(name, show_warning=False):
reserved_successfully += 1
elif isinstance(user_params_path, str):
for name in names:
if self.upload(name, user_parameters=user_params_path):
if self.upload(name, user_parameters=user_params_path, show_warning=False):
reserved_successfully += 1
elif isinstance(user_params_path, list):
if len(user_params_path) == 1:
for name in names:
if self.upload(name, user_parameters=user_params_path[0]):
if self.upload(name, user_parameters=user_params_path[0], show_warning=False):
reserved_successfully += 1
elif len(user_params_path) == len(names):
for index, name in enumerate(names):
if self.upload(name, user_parameters=user_params_path[index]):
if self.upload(name, user_parameters=user_params_path[index], show_warning=False):
reserved_successfully += 1
else:
raise ReserverBaseError(UNEQUAL_PARAM_NAME_LENGTH_ERROR)

if reserved_successfully > 0:
message = TEST_PYPI_REVOKE_TOKEN_MESSAGE if self.test_pypi else MAIN_PYPI_REVOKE_TOKEN_MESSAGE
print(message)

return reserved_successfully

def upload(self, package_name, user_parameters=None):
def upload(self, package_name, user_parameters=None, show_warning=True):
"""
Upload a template package to pypi or test_pypi.

:param package_name: package name
:type package_name: str
:param user_parameters: json file or path to the .json file containing user-defined package parameters
:type user_parameters: str | dict
:param show_warning: Whether to show the PyPI token security warning
:type show_warning: bool
:return: True if the package is successfully reserved, False otherwise
"""
if not isinstance(user_parameters, dict) and user_parameters is not None:
Expand Down Expand Up @@ -135,4 +143,7 @@ def upload(self, package_name, user_parameters=None):
return False
else:
print("Congratulations! You have successfully reserved the PyPI package: ", package_name)
if show_warning:
message = TEST_PYPI_REVOKE_TOKEN_MESSAGE if self.test_pypi else MAIN_PYPI_REVOKE_TOKEN_MESSAGE
print(message)
return True