Skip to content

Commit 8414fc2

Browse files
[pre-commit.ci] pre-commit autoupdate (#225)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/Lucas-C/pre-commit-hooks.git: v1.5.4 → v1.5.5](https://github.com/Lucas-C/pre-commit-hooks.git/compare/v1.5.4...v1.5.5) - [github.com/python-jsonschema/check-jsonschema.git: 0.27.3 → 0.28.1](https://github.com/python-jsonschema/check-jsonschema.git/compare/0.27.3...0.28.1) - [github.com/adrienverge/yamllint.git: v1.33.0 → v1.35.1](https://github.com/adrienverge/yamllint.git/compare/v1.33.0...v1.35.1) - [github.com/PyCQA/flake8.git: 6.1.0 → 7.0.0](https://github.com/PyCQA/flake8.git/compare/6.1.0...7.0.0) - [github.com/PyCQA/flake8.git: 4.0.1 → 7.0.0](https://github.com/PyCQA/flake8.git/compare/4.0.1...7.0.0) - [github.com/PyCQA/pylint.git: v3.0.3 → v3.1.0](https://github.com/PyCQA/pylint.git/compare/v3.0.3...v3.1.0) * Bump WPS to v0.19.x series * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Merge separate flake8 runs back into one --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Sviatoslav Sydorenko <sviat@redhat.com>
1 parent 67a07eb commit 8414fc2

File tree

3 files changed

+61
-108
lines changed

3 files changed

+61
-108
lines changed

.pre-commit-config.yaml

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ repos:
1717
- --honor-noqa
1818

1919
- repo: https://github.com/Lucas-C/pre-commit-hooks.git
20-
rev: v1.5.4
20+
rev: v1.5.5
2121
hooks:
2222
- id: remove-tabs
2323

2424
- repo: https://github.com/python-jsonschema/check-jsonschema.git
25-
rev: 0.27.3
25+
rev: 0.28.1
2626
hooks:
2727
- id: check-github-actions
2828
- id: check-github-workflows
@@ -67,7 +67,7 @@ repos:
6767
- id: codespell
6868

6969
- repo: https://github.com/adrienverge/yamllint.git
70-
rev: v1.33.0
70+
rev: v1.35.1
7171
hooks:
7272
- id: yamllint
7373
files: \.(yaml|yml)$
@@ -78,36 +78,20 @@ repos:
7878
- --strict
7979

8080
- repo: https://github.com/PyCQA/flake8.git
81-
rev: 6.1.0
81+
rev: 7.0.0
8282
hooks:
8383
- id: flake8
84-
alias: flake8-no-wps
85-
name: flake8 WPS-excluded
8684
args:
8785
- --ignore
86+
# NOTE: WPS326: Found implicit string concatenation
87+
# NOTE: WPS332: Found walrus operator
8888
- >-
8989
D100,
9090
D101,
9191
D103,
9292
D107,
9393
E402,
9494
E501,
95-
additional_dependencies:
96-
- flake8-2020 ~= 1.7.0
97-
- flake8-pytest-style ~= 1.6.0
98-
99-
- repo: https://github.com/PyCQA/flake8.git
100-
# NOTE: This is kept at v4 for until WPS starts supporting flake v5.
101-
rev: 4.0.1 # enforce-version: 4.0.1
102-
hooks:
103-
- id: flake8
104-
alias: flake8-only-wps
105-
name: flake8 WPS-only
106-
args:
107-
- --ignore
108-
# NOTE: WPS326: Found implicit string concatenation
109-
# NOTE: WPS332: Found walrus operator
110-
- >-
11195
WPS102,
11296
WPS110,
11397
WPS111,
@@ -124,14 +108,14 @@ repos:
124108
WPS440,
125109
WPS441,
126110
WPS453,
127-
- --select
128-
- WPS
129111
additional_dependencies:
130-
- wemake-python-styleguide ~= 0.17.0
112+
- flake8-2020 ~= 1.7.0
113+
- flake8-pytest-style ~= 1.6.0
114+
- wemake-python-styleguide ~= 0.19.0
131115
language_version: python3.11 # flake8-commas doesn't work w/ Python 3.12
132116

133117
- repo: https://github.com/PyCQA/pylint.git
134-
rev: v3.0.3
118+
rev: v3.1.0
135119
hooks:
136120
- id: pylint
137121
args:
@@ -150,36 +134,4 @@ repos:
150134
- --output-format
151135
- colorized
152136

153-
- repo: local
154-
hooks:
155-
- id: enforced-flake8-version
156-
name: Verify that enforced flake8 version stays unchanged
157-
description: >-
158-
This is a sanity check and fixer that makes sure that
159-
the `flake8` version in this file remains matching the
160-
corresponding request in the `# enforce-version` comment.
161-
# Using Python here because using
162-
# shell test does not always work in CIs:
163-
entry: >-
164-
python -c 'import pathlib, re, sys;
165-
pre_commit_config = pathlib.Path(sys.argv[1]);
166-
cfg_txt = pre_commit_config.read_text();
167-
new_cfg_txt = re.sub(
168-
r"(?P<spaces>\s+)rev:\s(?:\d+\.\d+\.\d+)\s{0,2}"
169-
r"#\senforce-version:\s(?P<enforced_version>\d+\.\d+\.\d+)"
170-
r"[ \t\f\v]*",
171-
r"\g<spaces>rev: \g<enforced_version> "
172-
r"# enforce-version: \g<enforced_version>",
173-
cfg_txt,
174-
);
175-
cfg_txt != new_cfg_txt and
176-
pre_commit_config.write_text(new_cfg_txt)
177-
'
178-
pass_filenames: true
179-
language: system
180-
files: >-
181-
^\.pre-commit-config\.ya?ml$
182-
types:
183-
- yaml
184-
185137
...

oidc-exchange.py

Lines changed: 44 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import id # pylint: disable=redefined-builtin
1111
import requests
1212

13-
_GITHUB_STEP_SUMMARY = Path(os.getenv("GITHUB_STEP_SUMMARY"))
13+
_GITHUB_STEP_SUMMARY = Path(os.getenv('GITHUB_STEP_SUMMARY'))
1414

1515
# The top-level error message that gets rendered.
1616
# This message wraps one of the other templates/messages defined below.
@@ -45,7 +45,7 @@
4545
```
4646
4747
Learn more at https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings.
48-
"""
48+
""" # noqa: S105; not a password
4949

5050
# Specialization of the token retrieval failure case, when we know that
5151
# the failure cause is use within a third-party PR.
@@ -59,7 +59,7 @@
5959
To fix this, change your publishing workflow to use an event that
6060
forks of your repository cannot trigger (such as tag or release
6161
creation, or a manually triggered workflow dispatch).
62-
"""
62+
""" # noqa: S105; not a password
6363

6464
# Rendered if the package index refuses the given OIDC token.
6565
_SERVER_REFUSED_TOKEN_EXCHANGE_MESSAGE = """
@@ -71,7 +71,7 @@
7171
also indicate an internal error on GitHub or PyPI's part.
7272
7373
{rendered_claims}
74-
"""
74+
""" # noqa: S105; not a password
7575

7676
_RENDERED_CLAIMS = """
7777
The claims rendered below are **for debugging purposes only**. You should **not**
@@ -97,38 +97,38 @@
9797
9898
This strongly suggests a server configuration or downtime issue; wait
9999
a few minutes and try again.
100-
"""
100+
""" # noqa: S105; not a password
101101

102102
# Rendered if the package index's token response isn't a valid API token payload.
103103
_SERVER_TOKEN_RESPONSE_MALFORMED_MESSAGE = """
104104
Token response error: the index gave us an invalid response.
105105
106106
This strongly suggests a server configuration or downtime issue; wait
107107
a few minutes and try again.
108-
"""
108+
""" # noqa: S105; not a password
109109

110110

111111
def die(msg: str) -> NoReturn:
112-
with _GITHUB_STEP_SUMMARY.open("a", encoding="utf-8") as io:
112+
with _GITHUB_STEP_SUMMARY.open('a', encoding='utf-8') as io:
113113
print(_ERROR_SUMMARY_MESSAGE.format(message=msg), file=io)
114114

115115
# HACK: GitHub Actions' annotations don't work across multiple lines naively;
116116
# translating `\n` into `%0A` (i.e., HTML percent-encoding) is known to work.
117117
# See: https://github.com/actions/toolkit/issues/193
118-
msg = msg.replace("\n", "%0A")
119-
print(f"::error::Trusted publishing exchange failure: {msg}", file=sys.stderr)
118+
msg = msg.replace('\n', '%0A')
119+
print(f'::error::Trusted publishing exchange failure: {msg}', file=sys.stderr)
120120
sys.exit(1)
121121

122122

123123
def debug(msg: str):
124-
print(f"::debug::{msg.title()}", file=sys.stderr)
124+
print(f'::debug::{msg.title()}', file=sys.stderr)
125125

126126

127127
def get_normalized_input(name: str) -> str | None:
128-
name = f"INPUT_{name.upper()}"
128+
name = f'INPUT_{name.upper()}'
129129
if val := os.getenv(name):
130130
return val
131-
return os.getenv(name.replace("-", "_"))
131+
return os.getenv(name.replace('-', '_'))
132132

133133

134134
def assert_successful_audience_call(resp: requests.Response, domain: str):
@@ -140,81 +140,81 @@ def assert_successful_audience_call(resp: requests.Response, domain: str):
140140
# This index supports OIDC, but forbids the client from using
141141
# it (either because it's disabled, ratelimited, etc.)
142142
die(
143-
f"audience retrieval failed: repository at {domain} has trusted publishing disabled",
143+
f'audience retrieval failed: repository at {domain} has trusted publishing disabled',
144144
)
145145
case HTTPStatus.NOT_FOUND:
146146
# This index does not support OIDC.
147147
die(
148-
"audience retrieval failed: repository at "
149-
f"{domain} does not indicate trusted publishing support",
148+
'audience retrieval failed: repository at '
149+
f'{domain} does not indicate trusted publishing support',
150150
)
151151
case other:
152152
status = HTTPStatus(other)
153153
# Unknown: the index may or may not support OIDC, but didn't respond with
154154
# something we expect. This can happen if the index is broken, in maintenance mode,
155155
# misconfigured, etc.
156156
die(
157-
"audience retrieval failed: repository at "
158-
f"{domain} responded with unexpected {other}: {status.phrase}",
157+
'audience retrieval failed: repository at '
158+
f'{domain} responded with unexpected {other}: {status.phrase}',
159159
)
160160

161161

162162
def render_claims(token: str) -> str:
163-
_, payload, _ = token.split(".", 2)
163+
_, payload, _ = token.split('.', 2)
164164

165165
# urlsafe_b64decode needs padding; JWT payloads don't contain any.
166-
payload += "=" * (4 - (len(payload) % 4))
166+
payload += '=' * (4 - (len(payload) % 4))
167167
claims = json.loads(base64.urlsafe_b64decode(payload))
168168

169169
def _get(name: str) -> str: # noqa: WPS430
170-
return claims.get(name, "MISSING")
170+
return claims.get(name, 'MISSING')
171171

172172
return _RENDERED_CLAIMS.format(
173-
sub=_get("sub"),
174-
repository=_get("repository"),
175-
repository_owner=_get("repository_owner"),
176-
repository_owner_id=_get("repository_owner_id"),
177-
job_workflow_ref=_get("job_workflow_ref"),
178-
ref=_get("ref"),
173+
sub=_get('sub'),
174+
repository=_get('repository'),
175+
repository_owner=_get('repository_owner'),
176+
repository_owner_id=_get('repository_owner_id'),
177+
job_workflow_ref=_get('job_workflow_ref'),
178+
ref=_get('ref'),
179179
)
180180

181181

182182
def event_is_third_party_pr() -> bool:
183183
# Non-`pull_request` events cannot be from third-party PRs.
184-
if os.getenv("GITHUB_EVENT_NAME") != "pull_request":
184+
if os.getenv('GITHUB_EVENT_NAME') != 'pull_request':
185185
return False
186186

187-
event_path = os.getenv("GITHUB_EVENT_PATH")
187+
event_path = os.getenv('GITHUB_EVENT_PATH')
188188
if not event_path:
189189
# No GITHUB_EVENT_PATH indicates a weird GitHub or runner bug.
190-
debug("unexpected: no GITHUB_EVENT_PATH to check")
190+
debug('unexpected: no GITHUB_EVENT_PATH to check')
191191
return False
192192

193193
try:
194194
event = json.loads(Path(event_path).read_bytes())
195195
except json.JSONDecodeError:
196-
debug("unexpected: GITHUB_EVENT_PATH does not contain valid JSON")
196+
debug('unexpected: GITHUB_EVENT_PATH does not contain valid JSON')
197197
return False
198198

199199
try:
200-
return event["pull_request"]["head"]["repo"]["fork"]
200+
return event['pull_request']['head']['repo']['fork']
201201
except KeyError:
202202
return False
203203

204204

205-
repository_url = get_normalized_input("repository-url")
205+
repository_url = get_normalized_input('repository-url')
206206
repository_domain = urlparse(repository_url).netloc
207-
token_exchange_url = f"https://{repository_domain}/_/oidc/mint-token"
207+
token_exchange_url = f'https://{repository_domain}/_/oidc/mint-token'
208208

209209
# Indices are expected to support `https://{domain}/_/oidc/audience`,
210210
# which tells OIDC exchange clients which audience to use.
211-
audience_url = f"https://{repository_domain}/_/oidc/audience"
212-
audience_resp = requests.get(audience_url)
211+
audience_url = f'https://{repository_domain}/_/oidc/audience'
212+
audience_resp = requests.get(audience_url, timeout=5) # S113 wants a timeout
213213
assert_successful_audience_call(audience_resp, repository_domain)
214214

215-
oidc_audience = audience_resp.json()["audience"]
215+
oidc_audience = audience_resp.json()['audience']
216216

217-
debug(f"selected trusted publishing exchange endpoint: {token_exchange_url}")
217+
debug(f'selected trusted publishing exchange endpoint: {token_exchange_url}')
218218

219219
try:
220220
oidc_token = id.detect_credential(audience=oidc_audience)
@@ -229,7 +229,8 @@ def event_is_third_party_pr() -> bool:
229229
# Now we can do the actual token exchange.
230230
mint_token_resp = requests.post(
231231
token_exchange_url,
232-
json={"token": oidc_token},
232+
json={'token': oidc_token},
233+
timeout=5, # S113 wants a timeout
233234
)
234235

235236
try:
@@ -246,9 +247,9 @@ def event_is_third_party_pr() -> bool:
246247
# On failure, the JSON response includes the list of errors that
247248
# occurred during minting.
248249
if not mint_token_resp.ok:
249-
reasons = "\n".join(
250-
f"* `{error['code']}`: {error['description']}"
251-
for error in mint_token_payload["errors"]
250+
reasons = '\n'.join(
251+
f'* `{error["code"]}`: {error["description"]}'
252+
for error in mint_token_payload['errors']
252253
)
253254

254255
rendered_claims = render_claims(oidc_token)
@@ -260,12 +261,12 @@ def event_is_third_party_pr() -> bool:
260261
),
261262
)
262263

263-
pypi_token = mint_token_payload.get("token")
264+
pypi_token = mint_token_payload.get('token')
264265
if pypi_token is None:
265266
die(_SERVER_TOKEN_RESPONSE_MALFORMED_MESSAGE)
266267

267268
# Mask the newly minted PyPI token, so that we don't accidentally leak it in logs.
268-
print(f"::add-mask::{pypi_token}", file=sys.stderr)
269+
print(f'::add-mask::{pypi_token}', file=sys.stderr)
269270

270271
# This final print will be captured by the subshell in `twine-upload.sh`.
271272
print(pypi_token)

print-hash.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
66

7-
print("Showing hash values of files to be uploaded:")
7+
print('Showing hash values of files to be uploaded:')
88

99
for file_object in packages_dir.iterdir():
1010
sha256 = hashlib.sha256()
11-
md5 = hashlib.md5()
11+
md5 = hashlib.md5() # noqa: S324; only use for reference
1212
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
1313

1414
print(file_object)
15-
print("")
15+
print('')
1616

1717
content = file_object.read_bytes()
1818

1919
sha256.update(content)
2020
md5.update(content)
2121
blake2_256.update(content)
2222

23-
print(f"SHA256: {sha256.hexdigest()}")
24-
print(f"MD5: {md5.hexdigest()}")
25-
print(f"BLAKE2-256: {blake2_256.hexdigest()}")
26-
print("")
23+
print(f'SHA256: {sha256.hexdigest()}')
24+
print(f'MD5: {md5.hexdigest()}')
25+
print(f'BLAKE2-256: {blake2_256.hexdigest()}')
26+
print('')

0 commit comments

Comments
 (0)