Skip to content

Commit

Permalink
feat: rename --unsafe-s3-website option to --index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
mdwint committed Jan 1, 2024
1 parent 15e348b commit 04f83f6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [PEP 440](https://www.python.org/dev/peps/pep-0440/)
### Changed

- Moved default command to `s3pypi upload`.
- Renamed `--unsafe-s3-website` option to `--index.html`.

### Removed

Expand Down
22 changes: 12 additions & 10 deletions s3pypi/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,12 @@ def build_s3_args(p: ArgumentParser) -> None:
action="store_true",
help="Don't use authentication when communicating with S3.",
)
p.add_argument("--s3-endpoint-url", help="Optional custom S3 endpoint URL.")
p.add_argument(
"--s3-endpoint-url", metavar="URL", help="Optional custom S3 endpoint URL."
)
p.add_argument(
"--s3-put-args",
metavar="ARGS",
type=string_dict,
default={},
help=(
Expand All @@ -84,13 +87,12 @@ def build_s3_args(p: ArgumentParser) -> None:
),
)
p.add_argument(
"--unsafe-s3-website",
"--index.html",
dest="index_html",
action="store_true",
help=(
"Store the index as an S3 object named `<package>/index.html` instead of `<package>/`. "
"This option is provided for backwards compatibility with S3 website endpoints, "
"the use of which is discouraged because they require the bucket to be publicly accessible. "
"It's recommended to instead use a private S3 bucket with a CloudFront Origin Access Identity."
"Store index pages with suffix `/index.html` instead of `/`. "
"This provides compatibility with custom HTTPS proxies or S3 website endpoints."
),
)
p.add_argument(
Expand Down Expand Up @@ -125,13 +127,13 @@ def main(*raw_args: str) -> None:
s3=core.S3Config(
bucket=args.bucket,
prefix=args.prefix,
profile=args.profile,
region=args.region,
no_sign_request=args.no_sign_request,
endpoint_url=args.s3_endpoint_url,
put_kwargs=args.s3_put_args,
unsafe_s3_website=args.unsafe_s3_website,
no_sign_request=args.no_sign_request,
index_html=args.index_html,
lock_indexes=args.lock_indexes,
profile=args.profile,
region=args.region,
),
)

Expand Down
10 changes: 5 additions & 5 deletions s3pypi/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
class S3Config:
bucket: str
prefix: Optional[str] = None
profile: Optional[str] = None
region: Optional[str] = None
no_sign_request: bool = False
endpoint_url: Optional[str] = None
put_kwargs: Dict[str, str] = field(default_factory=dict)
unsafe_s3_website: bool = False
no_sign_request: bool = False
index_html: bool = False
lock_indexes: bool = False
profile: Optional[str] = None
region: Optional[str] = None


class S3Storage:
Expand All @@ -37,7 +37,7 @@ def __init__(self, cfg: S3Config):
config = BotoConfig(signature_version=botocore.session.UNSIGNED) # type: ignore

self.s3 = session.resource("s3", endpoint_url=cfg.endpoint_url, config=config)
self.index_name = self._index if cfg.unsafe_s3_website else ""
self.index_name = self._index if cfg.index_html else ""
self.cfg = cfg

self.lock = (
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def test_index_storage_roundtrip(s3_bucket):
(S3Config(""), "foo", "bar", "foo/bar"),
(S3Config("", prefix="P"), "/", index, "P/"),
(S3Config("", prefix="P"), "foo", "bar", "P/foo/bar"),
(S3Config("", prefix="P", unsafe_s3_website=True), "/", index, "P/index.html"),
(S3Config("", unsafe_s3_website=True), "/", index, "index.html"),
(S3Config("", prefix="P", index_html=True), "/", index, "P/index.html"),
(S3Config("", index_html=True), "/", index, "index.html"),
],
)
def test_s3_key(cfg, directory, filename, expected_key):
Expand Down

0 comments on commit 04f83f6

Please sign in to comment.