|
43 | 43 | SBOMS_WITHDRAW, |
44 | 44 | SBOMS_PUBLISH, |
45 | 45 | ) |
| 46 | +from . import publisher, withdrawer |
46 | 47 | from .dictmerge import _deepmerge |
47 | 48 | from .sbommetadata import SBOM |
48 | 49 |
|
@@ -171,44 +172,86 @@ def list( |
171 | 172 | ) |
172 | 173 | ) |
173 | 174 |
|
174 | | - def publish(self, identity: str) -> SBOM: |
| 175 | + def publish(self, identity: str, confirm: bool = False) -> SBOM: |
175 | 176 | """Publish SBOMt |
176 | 177 |
|
177 | 178 | Makes an SBOM public. |
178 | 179 |
|
179 | 180 | Args: |
180 | 181 | identity (str): identity of SBOM |
| 182 | + confirm (bool): if True wait for sbom to be published. |
181 | 183 |
|
182 | 184 | Returns: |
183 | 185 | :class:`SBOM` instance |
184 | 186 |
|
185 | 187 | """ |
186 | 188 | LOGGER.debug("Publish SBOM %s", identity) |
187 | | - return SBOM( |
| 189 | + sbom = SBOM( |
188 | 190 | **self._archivist.post( |
189 | 191 | f"{SBOMS_SUBPATH}/{identity}", |
190 | 192 | None, |
191 | 193 | verb=SBOMS_PUBLISH, |
192 | 194 | ) |
193 | 195 | ) |
| 196 | + if not confirm: |
| 197 | + return sbom |
| 198 | + |
| 199 | + return self.wait_for_publication(sbom.identity) |
| 200 | + |
| 201 | + def wait_for_publication(self, identity: str) -> SBOM: |
| 202 | + """Wait for sbom to be published. |
| 203 | +
|
| 204 | + Waits for sbom to be published. |
| 205 | +
|
| 206 | + Args: |
| 207 | + identity (str): identity of sbom |
| 208 | +
|
| 209 | + Returns: |
| 210 | + True if sbom is confirmed. |
| 211 | +
|
| 212 | + """ |
| 213 | + publisher.MAX_TIME = self._archivist.max_time |
| 214 | + # pylint: disable=protected-access |
| 215 | + return publisher._wait_for_publication(self, identity) |
194 | 216 |
|
195 | | - def withdraw(self, identity: str) -> SBOM: |
| 217 | + def withdraw(self, identity: str, confirm: bool = False) -> SBOM: |
196 | 218 | """Withdraw SBOM |
197 | 219 |
|
198 | 220 | Withdraws an SBOM. |
199 | 221 |
|
200 | 222 | Args: |
201 | 223 | identity (str): identity of SBOM |
| 224 | + confirm (bool): if True wait for sbom to be withdrawn. |
202 | 225 |
|
203 | 226 | Returns: |
204 | 227 | :class:`SBOM` instance |
205 | 228 |
|
206 | 229 | """ |
207 | 230 | LOGGER.debug("Withdraw SBOM %s", identity) |
208 | | - return SBOM( |
| 231 | + sbom = SBOM( |
209 | 232 | **self._archivist.post( |
210 | 233 | f"{SBOMS_SUBPATH}/{identity}", |
211 | 234 | None, |
212 | 235 | verb=SBOMS_WITHDRAW, |
213 | 236 | ) |
214 | 237 | ) |
| 238 | + if not confirm: |
| 239 | + return sbom |
| 240 | + |
| 241 | + return self.wait_for_withdrawn(sbom.identity) |
| 242 | + |
| 243 | + def wait_for_withdrawn(self, identity: str) -> SBOM: |
| 244 | + """Wait for sbom to be withdrawn. |
| 245 | +
|
| 246 | + Waits for sbom to be withdrawn. |
| 247 | +
|
| 248 | + Args: |
| 249 | + identity (str): identity of sbom |
| 250 | +
|
| 251 | + Returns: |
| 252 | + True if sbom is confirmed. |
| 253 | +
|
| 254 | + """ |
| 255 | + withdrawer.MAX_TIME = self._archivist.max_time |
| 256 | + # pylint: disable=protected-access |
| 257 | + return withdrawer._wait_for_withdrawn(self, identity) |
0 commit comments