|
17 | 17 | import fnmatch
|
18 | 18 | import logging
|
19 | 19 | import os.path
|
| 20 | +import re |
20 | 21 | from typing import Dict, List, NamedTuple, cast
|
21 | 22 |
|
22 | 23 | import requests
|
@@ -148,6 +149,26 @@ def _split_inputs(
|
148 | 149 | return Inputs(dists, signatures, attestations_by_dist)
|
149 | 150 |
|
150 | 151 |
|
| 152 | +def _sanitize_url(url) -> str: |
| 153 | + """ |
| 154 | + Sanitize URLs, removing any user:password combinations and replacing them with |
| 155 | + asterisks. Returns the original URL if the string is a non-matching pattern. |
| 156 | +
|
| 157 | + :param url: |
| 158 | + str containing a URL to sanitize. |
| 159 | +
|
| 160 | + return: |
| 161 | + str either sanitized or as entered depending on pattern match. |
| 162 | + """ |
| 163 | + pattern = "(.*https?://)(\w+:\w+)@(\w+\..*)" |
| 164 | + m = re.match(pattern, url) |
| 165 | + if m: |
| 166 | + newurl = f"{m.group(1)}*****:*****@{m.group(3)}" |
| 167 | + return newurl |
| 168 | + else: |
| 169 | + return url |
| 170 | + |
| 171 | + |
151 | 172 | def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
|
152 | 173 | """Upload one or more distributions to a repository, and display the progress.
|
153 | 174 |
|
@@ -189,7 +210,7 @@ def upload(upload_settings: settings.Settings, dists: List[str]) -> None:
|
189 | 210 | # Determine if the user has passed in pre-signed distributions or any attestations.
|
190 | 211 | uploads, signatures, attestations_by_dist = _split_inputs(dists)
|
191 | 212 |
|
192 |
| - print(f"Uploading distributions to {repository_url}") |
| 213 | + print(f"Uploading distributions to {_sanitize_url(repository_url)}") |
193 | 214 |
|
194 | 215 | packages_to_upload = [
|
195 | 216 | _make_package(
|
|
0 commit comments