Skip to content

Commit 0a8eb49

Browse files
authored
Merge pull request #62 from gopythongo/feature/publish-acquire-by-hash
expose the AcquireByHash (-acquire-by-hash) option of the publish API [copy of #61]
2 parents 92f7716 + 354438d commit 0a8eb49

File tree

2 files changed

+43
-25
lines changed

2 files changed

+43
-25
lines changed

aptly_api/parts/publish.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
('architectures', Sequence[str]),
1818
('label', str),
1919
('origin', str),
20+
('acquire_by_hash', bool),
2021
])
2122

2223

@@ -36,6 +37,7 @@ def endpoint_from_response(api_response: Union[Dict[str, str], Dict[str, List[st
3637
architectures=cast(List[str], api_response["Architectures"]),
3738
label=cast(str, api_response["Label"]),
3839
origin=cast(str, api_response["Origin"]),
40+
acquire_by_hash=cast(bool, api_response["AcquireByHash"]),
3941
)
4042

4143
@staticmethod
@@ -64,7 +66,8 @@ def publish(self, *, source_kind: str = "local",
6466
origin: Optional[str] = None, force_overwrite: bool = False,
6567
sign_skip: bool = False, sign_batch: bool = True, sign_gpgkey: Optional[str] = None,
6668
sign_keyring: Optional[str] = None, sign_secret_keyring: Optional[str] = None,
67-
sign_passphrase: Optional[str] = None, sign_passphrase_file: Optional[str] = None) -> PublishEndpoint:
69+
sign_passphrase: Optional[str] = None, sign_passphrase_file: Optional[str] = None,
70+
acquire_by_hash: Optional[bool] = None) -> PublishEndpoint:
6871
"""
6972
Example:
7073
@@ -101,6 +104,8 @@ def publish(self, *, source_kind: str = "local",
101104
body["Origin"] = origin
102105
if force_overwrite:
103106
body["ForceOverwrite"] = True
107+
if acquire_by_hash is not None:
108+
body["AcquireByHash"] = acquire_by_hash
104109

105110
sign_dict = {} # type: Dict[str, Union[bool,str]]
106111
if sign_skip:

aptly_api/tests/publish.py

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def __init__(self, *args: Any) -> None:
2121

2222
def test_list(self, *, rmock: requests_mock.Mocker) -> None:
2323
rmock.get("http://test/api/publish",
24-
text='[{"Architectures":["amd64"],"Distribution":"mn-nightly","Label":"",'
24+
text='[{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"mn-nightly","Label":"",'
2525
'"Origin":"","Prefix":"nightly/stretch","SkipContents":false,'
2626
'"SourceKind":"local","Sources":[{"Component":"main","Name":"maurusnet"}],'
2727
'"Storage":"s3:maurusnet"}]')
@@ -39,14 +39,15 @@ def test_list(self, *, rmock: requests_mock.Mocker) -> None:
3939
}],
4040
architectures=['amd64'],
4141
label='',
42-
origin=''
42+
origin='',
43+
acquire_by_hash=False
4344
)
4445
]
4546
)
4647

4748
def test_update(self, *, rmock: requests_mock.Mocker) -> None:
4849
rmock.put("http://test/api/publish/s3%3Aaptly-repo%3Atest_xyz__1/test",
49-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"",'
50+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"",'
5051
'"Origin":"","Prefix":"test/xyz_1","SkipContents":false,'
5152
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
5253
'"Storage":"s3:aptly-repo"}')
@@ -69,13 +70,14 @@ def test_update(self, *, rmock: requests_mock.Mocker) -> None:
6970
}],
7071
architectures=['amd64'],
7172
label='',
72-
origin=''
73+
origin='',
74+
acquire_by_hash=False
7375
)
7476
)
7577

7678
def test_update_passphrase_file(self, *, rmock: requests_mock.Mocker) -> None:
7779
rmock.put("http://test/api/publish/s3%3Aaptly-repo%3Atest_xyz__1/test",
78-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"",'
80+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"",'
7981
'"Origin":"","Prefix":"test/xyz_1","SkipContents":false,'
8082
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
8183
'"Storage":"s3:aptly-repo"}')
@@ -98,13 +100,14 @@ def test_update_passphrase_file(self, *, rmock: requests_mock.Mocker) -> None:
98100
}],
99101
architectures=['amd64'],
100102
label='',
101-
origin=''
103+
origin='',
104+
acquire_by_hash=False
102105
)
103106
)
104107

105108
def test_update_no_sign(self, *, rmock: requests_mock.Mocker) -> None:
106109
rmock.put("http://test/api/publish/s3%3Aaptly-repo%3Atest_xyz__1/test",
107-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"",'
110+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"",'
108111
'"Origin":"","Prefix":"test/xyz_1","SkipContents":false,'
109112
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
110113
'"Storage":"s3:aptly-repo"}')
@@ -125,13 +128,14 @@ def test_update_no_sign(self, *, rmock: requests_mock.Mocker) -> None:
125128
}],
126129
architectures=['amd64'],
127130
label='',
128-
origin=''
131+
origin='',
132+
acquire_by_hash=False
129133
)
130134
)
131135

132136
def test_update_snapshots(self, *, rmock: requests_mock.Mocker) -> None:
133137
rmock.put("http://test/api/publish/s3%3Aaptly-repo%3Atest_xyz__1/test",
134-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"",'
138+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"",'
135139
'"Origin":"","Prefix":"test/xyz_1","SkipContents":false,'
136140
'"SourceKind":"snapshot","Sources":[{"Component":"main","Name":"aptly-repo-1"}],'
137141
'"Storage":"s3:aptly-repo"}')
@@ -158,13 +162,14 @@ def test_update_snapshots(self, *, rmock: requests_mock.Mocker) -> None:
158162
}],
159163
architectures=['amd64'],
160164
label='',
161-
origin=''
165+
origin='',
166+
acquire_by_hash=False
162167
)
163168
)
164169

165170
def test_publish(self, *, rmock: requests_mock.Mocker) -> None:
166171
rmock.post("http://test/api/publish/s3%3Amyendpoint%3Atest_a__1",
167-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"test",'
172+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"test",'
168173
'"Origin":"origin","Prefix":"test/a_1","SkipContents":false,'
169174
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
170175
'"Storage":"s3:myendpoint"}')
@@ -174,7 +179,8 @@ def test_publish(self, *, rmock: requests_mock.Mocker) -> None:
174179
prefix='s3:myendpoint:test/a_1', distribution='test', label='test', origin='origin',
175180
sign_batch=True, sign_gpgkey='A16BE921', sign_passphrase='*********',
176181
force_overwrite=True, sign_keyring="/etc/gpg-managed-keyring/pubring.pub",
177-
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg"
182+
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg",
183+
acquire_by_hash=False
178184
),
179185
PublishEndpoint(
180186
storage='s3:myendpoint',
@@ -184,13 +190,14 @@ def test_publish(self, *, rmock: requests_mock.Mocker) -> None:
184190
sources=[{'Component': 'main', 'Name': 'aptly-repo'}],
185191
architectures=['amd64'],
186192
label='test',
187-
origin='origin'
193+
origin='origin',
194+
acquire_by_hash=False
188195
)
189196
)
190197

191198
def test_publish_passphrase_file(self, *, rmock: requests_mock.Mocker) -> None:
192199
rmock.post("http://test/api/publish/s3%3Amyendpoint%3Atest_a__1",
193-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"test",'
200+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"test",'
194201
'"Origin":"origin","Prefix":"test/a_1","SkipContents":false,'
195202
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
196203
'"Storage":"s3:myendpoint"}')
@@ -200,7 +207,8 @@ def test_publish_passphrase_file(self, *, rmock: requests_mock.Mocker) -> None:
200207
prefix='s3:myendpoint:test/a_1', distribution='test', label='test', origin='origin',
201208
sign_batch=True, sign_gpgkey='A16BE921', sign_passphrase_file='/root/passphrase.txt',
202209
force_overwrite=True, sign_keyring="/etc/gpg-managed-keyring/pubring.pub",
203-
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg"
210+
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg",
211+
acquire_by_hash=False
204212
),
205213
PublishEndpoint(
206214
storage='s3:myendpoint',
@@ -210,21 +218,23 @@ def test_publish_passphrase_file(self, *, rmock: requests_mock.Mocker) -> None:
210218
sources=[{'Component': 'main', 'Name': 'aptly-repo'}],
211219
architectures=['amd64'],
212220
label='test',
213-
origin='origin'
221+
origin='origin',
222+
acquire_by_hash=False
214223
)
215224
)
216225

217226
def test_publish_no_sign(self, *, rmock: requests_mock.Mocker) -> None:
218227
rmock.post("http://test/api/publish/s3%3Amyendpoint%3Atest_a__1",
219-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"test",'
228+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"test",'
220229
'"Origin":"origin","Prefix":"test/a_1","SkipContents":false,'
221230
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
222231
'"Storage":"s3:myendpoint"}')
223232
self.assertEqual(
224233
self.papi.publish(
225234
sources=[{'Name': 'aptly-repo'}], architectures=['amd64'],
226235
prefix='s3:myendpoint:test/a_1', distribution='test', label='test', origin='origin',
227-
sign_skip=True
236+
sign_skip=True,
237+
acquire_by_hash=False
228238
),
229239
PublishEndpoint(
230240
storage='s3:myendpoint',
@@ -234,13 +244,14 @@ def test_publish_no_sign(self, *, rmock: requests_mock.Mocker) -> None:
234244
sources=[{'Component': 'main', 'Name': 'aptly-repo'}],
235245
architectures=['amd64'],
236246
label='test',
237-
origin='origin'
247+
origin='origin',
248+
acquire_by_hash=False
238249
)
239250
)
240251

241252
def test_publish_default_key(self, *, rmock: requests_mock.Mocker) -> None:
242253
rmock.post("http://test/api/publish/s3%3Amyendpoint%3Atest_a__1",
243-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"test",'
254+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"test",'
244255
'"Origin":"origin","Prefix":"test/a_1","SkipContents":false,'
245256
'"SourceKind":"local","Sources":[{"Component":"main","Name":"aptly-repo"}],'
246257
'"Storage":"s3:myendpoint"}')
@@ -250,7 +261,7 @@ def test_publish_default_key(self, *, rmock: requests_mock.Mocker) -> None:
250261
prefix='s3:myendpoint:test/a_1', distribution='test', label='test', origin='origin',
251262
sign_batch=True, sign_passphrase='*********',
252263
force_overwrite=True, sign_keyring="/etc/gpg-managed-keyring/pubring.pub",
253-
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg"
264+
sign_secret_keyring="/etc/gpg-managed-keyring/secring.gpg",
254265
),
255266
PublishEndpoint(
256267
storage='s3:myendpoint',
@@ -260,13 +271,14 @@ def test_publish_default_key(self, *, rmock: requests_mock.Mocker) -> None:
260271
sources=[{'Component': 'main', 'Name': 'aptly-repo'}],
261272
architectures=['amd64'],
262273
label='test',
263-
origin='origin'
274+
origin='origin',
275+
acquire_by_hash=False
264276
)
265277
)
266278

267279
def test_update_snapshot_default_key(self, *, rmock: requests_mock.Mocker) -> None:
268280
rmock.put("http://test/api/publish/s3%3Aaptly-repo%3Atest_xyz__1/test",
269-
text='{"Architectures":["amd64"],"Distribution":"test","Label":"",'
281+
text='{"AcquireByHash":false,"Architectures":["amd64"],"Distribution":"test","Label":"",'
270282
'"Origin":"","Prefix":"test/xyz_1","SkipContents":false,'
271283
'"SourceKind":"snapshot","Sources":[{"Component":"main","Name":"aptly-repo-1"}],'
272284
'"Storage":"s3:aptly-repo"}')
@@ -293,7 +305,8 @@ def test_update_snapshot_default_key(self, *, rmock: requests_mock.Mocker) -> No
293305
}],
294306
architectures=['amd64'],
295307
label='',
296-
origin=''
308+
origin='',
309+
acquire_by_hash=False
297310
)
298311
)
299312

0 commit comments

Comments
 (0)