|
5 | 5 | import copy
|
6 | 6 | import os
|
7 | 7 | import urllib
|
| 8 | +from contextlib import contextmanager, nullcontext |
8 | 9 | from dataclasses import asdict, dataclass
|
9 | 10 | from http.cookiejar import DefaultCookiePolicy
|
10 |
| -from typing import Callable, List, Optional, Tuple, Union |
| 11 | +from tempfile import TemporaryDirectory |
| 12 | +from typing import Callable, Generator, List, Optional, Tuple, Union |
11 | 13 |
|
12 | 14 | import jsonschema
|
13 | 15 | import requests
|
|
25 | 27 | container_type = Union[str, oras.container.Container]
|
26 | 28 |
|
27 | 29 |
|
| 30 | +@contextmanager |
| 31 | +def temporary_empty_config() -> Generator[str, None, None]: |
| 32 | + with TemporaryDirectory() as tmpdir: |
| 33 | + config_file = oras.utils.get_tmpfile(tmpdir=tmpdir, suffix=".json") |
| 34 | + oras.utils.write_file(config_file, "{}") |
| 35 | + yield config_file |
| 36 | + |
| 37 | + |
28 | 38 | @dataclass
|
29 | 39 | class Subject:
|
30 | 40 | mediaType: str
|
@@ -747,7 +757,11 @@ def push(self, *args, **kwargs) -> requests.Response:
|
747 | 757 |
|
748 | 758 | # Config is just another layer blob!
|
749 | 759 | logger.debug(f"Preparing config {conf}")
|
750 |
| - response = self.upload_blob(config_file, container, conf) |
| 760 | + with temporary_empty_config() if config_file is None else nullcontext( |
| 761 | + config_file |
| 762 | + ) as config_file: |
| 763 | + response = self.upload_blob(config_file, container, conf) |
| 764 | + |
751 | 765 | self._check_200_response(response)
|
752 | 766 |
|
753 | 767 | # Final upload of the manifest
|
|
0 commit comments