Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit916e576

Browse files
authored
Merge pull request#315 from webknjaz/refactoring/attestations-exist-bundle
💅 Bundle attestation existence check together
2 parentsdaa8997 +72d1032 commit916e576

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

‎attestations.py‎

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,47 @@ def collect_dists(packages_dir: Path) -> list[Path]:
6969
returndist_paths
7070

7171

72-
defattest_dist(dist_path:Path,signer:Signer)->None:
72+
defassert_attestations_do_not_pre_exist(
73+
dist_to_attestation_map:dict[Path,Path],
74+
)->None:
75+
existing_attestations= {
76+
f'*{dist !s} ->{dist_attestation !s}'
77+
fordist,dist_attestationindist_to_attestation_map.items()
78+
ifdist_attestation.exists()
79+
}
80+
ifnotexisting_attestations:
81+
return
82+
83+
existing_attestations_list='\n'.join(map(str,existing_attestations))
84+
error_message= (
85+
'The following distributions already have publish attestations:'
86+
f'{existing_attestations_list}',
87+
)
88+
die(error_message)
89+
90+
91+
defcompose_attestation_mapping(dist_paths:list[Path])->dict[Path,Path]:
92+
dist_to_attestation_map= {
93+
dist_path:dist_path.with_suffix(
94+
f'{dist_path.suffix}.publish.attestation',
95+
)
96+
fordist_pathindist_paths
97+
}
98+
7399
# We are the publishing step, so there should be no pre-existing publish
74100
# attestation. The presence of one indicates user confusion.
75-
attestation_path=Path(f'{dist_path}.publish.attestation')
76-
ifattestation_path.exists():
77-
die(f'{dist_path} already has a publish attestation:{attestation_path}')
101+
# Make sure there's nopublish attestations on disk.
102+
# We do this up-front to prevent partial signing.
103+
assert_attestations_do_not_pre_exist(dist_to_attestation_map)
78104

105+
returndist_to_attestation_map
106+
107+
108+
defattest_dist(
109+
dist_path:Path,
110+
attestation_path:Path,
111+
signer:Signer,
112+
)->None:
79113
dist=Distribution.from_file(dist_path)
80114
attestation=Attestation.sign(signer,dist)
81115

@@ -92,7 +126,9 @@ def get_identity_token() -> IdentityToken:
92126

93127

94128
defmain()->None:
95-
packages_dir=Path(sys.argv[1])
129+
dist_to_attestation_map=compose_attestation_mapping(
130+
collect_dists(Path(sys.argv[1])),
131+
)
96132

97133
try:
98134
identity=get_identity_token()
@@ -103,12 +139,10 @@ def main() -> None:
103139
# since permissions can't be to blame at this stage.
104140
die(_TOKEN_RETRIEVAL_FAILED_MESSAGE.format(identity_error=identity_error))
105141

106-
dist_paths=collect_dists(packages_dir)
107-
108-
withSigningContext.production().signer(identity,cache=True)ass:
109-
debug(f'attesting to dists:{dist_paths}')
110-
fordist_pathindist_paths:
111-
attest_dist(dist_path,s)
142+
withSigningContext.production().signer(identity,cache=True)assigner:
143+
debug(f'attesting to dists:{dist_to_attestation_map.keys()}')
144+
fordist_path,attestation_pathindist_to_attestation_map.items():
145+
attest_dist(dist_path,attestation_path,signer)
112146

113147

114148
if__name__=='__main__':

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp