|
68 | 68 | _RestObjectBase = object |
69 | 69 |
|
70 | 70 |
|
71 | | -class GetMixin(_RestManagerBase): |
| 71 | +class HeadMixin(_RestManagerBase): |
| 72 | + @exc.on_http_error(exc.GitlabHeadError) |
| 73 | + def head( |
| 74 | + self, id: Optional[Union[str, int]] = None, **kwargs: Any |
| 75 | + ) -> requests.structures.CaseInsensitiveDict: |
| 76 | + """Retrieve headers from an endpoint. |
| 77 | +
|
| 78 | + Args: |
| 79 | + id: ID of the object to retrieve |
| 80 | + **kwargs: Extra options to send to the server (e.g. sudo) |
| 81 | +
|
| 82 | + Returns: |
| 83 | + A requests header object. |
| 84 | +
|
| 85 | + Raises: |
| 86 | + GitlabAuthenticationError: If authentication is not correct |
| 87 | + GitlabHeadError: If the server cannot perform the request |
| 88 | + """ |
| 89 | + if TYPE_CHECKING: |
| 90 | + assert self.path is not None |
| 91 | + |
| 92 | + path = self.path |
| 93 | + if id is not None: |
| 94 | + path = f"{path}/{utils.EncodedId(id)}" |
| 95 | + |
| 96 | + return self.gitlab.http_head(path, **kwargs) |
| 97 | + |
| 98 | + |
| 99 | +class GetMixin(HeadMixin, _RestManagerBase): |
72 | 100 | _computed_path: Optional[str] |
73 | 101 | _from_parent_attrs: Dict[str, Any] |
74 | 102 | _obj_cls: Optional[Type[base.RESTObject]] |
@@ -113,7 +141,7 @@ def get( |
113 | 141 | return self._obj_cls(self, server_data) |
114 | 142 |
|
115 | 143 |
|
116 | | -class GetWithoutIdMixin(_RestManagerBase): |
| 144 | +class GetWithoutIdMixin(HeadMixin, _RestManagerBase): |
117 | 145 | _computed_path: Optional[str] |
118 | 146 | _from_parent_attrs: Dict[str, Any] |
119 | 147 | _obj_cls: Optional[Type[base.RESTObject]] |
@@ -181,7 +209,7 @@ def refresh(self, **kwargs: Any) -> None: |
181 | 209 | self._update_attrs(server_data) |
182 | 210 |
|
183 | 211 |
|
184 | | -class ListMixin(_RestManagerBase): |
| 212 | +class ListMixin(HeadMixin, _RestManagerBase): |
185 | 213 | _computed_path: Optional[str] |
186 | 214 | _from_parent_attrs: Dict[str, Any] |
187 | 215 | _list_filters: Tuple[str, ...] = () |
|
0 commit comments