|
14 | 14 | import pystac
|
15 | 15 | import pystac.validation
|
16 | 16 | from pystac import CatalogType, Collection
|
| 17 | +from requests import Request |
17 | 18 |
|
18 | 19 | from pystac_client._utils import Modifiable, call_modifier
|
19 | 20 | from pystac_client.collection_client import CollectionClient
|
@@ -93,6 +94,8 @@ def open(
|
93 | 94 | parameters: Optional[Dict[str, Any]] = None,
|
94 | 95 | ignore_conformance: bool = False,
|
95 | 96 | modifier: Optional[Callable[[Modifiable], None]] = None,
|
| 97 | + request_modifier: Optional[Callable[[Request], Union[Request, None]]] = None, |
| 98 | + stac_io: Optional[StacApiIO] = None, |
96 | 99 | ) -> "Client":
|
97 | 100 | """Opens a STAC Catalog or API
|
98 | 101 | This function will read the root catalog of a STAC Catalog or API
|
@@ -128,12 +131,31 @@ def open(
|
128 | 131 | After getting a child collection with, e.g.
|
129 | 132 | :meth:`Client.get_collection`, the child items of that collection
|
130 | 133 | will still be signed with ``modifier``.
|
| 134 | + request_modifier: A callable that eitehr modifies a `Request` instance or |
| 135 | + returns a new one. This can be useful for injecting Authentication |
| 136 | + headers and/or signing fully-formed requests (e.g. signing requests |
| 137 | + using AWS SigV4). |
| 138 | +
|
| 139 | + The callable should expect a single argument, which will be an instance |
| 140 | + of :class:`requests.Request`. |
| 141 | +
|
| 142 | + If the callable returns a `requests.Request`, that will be used. |
| 143 | + Alternately, the calable may simply modify the provided request object |
| 144 | + and return `None`. |
| 145 | + stac_io: A `StacApiIO` object to use for I/O requests. Generally, leave |
| 146 | + this to the default. However in cases where customized I/O processing |
| 147 | + is required, a custom instance can be provided here. |
131 | 148 |
|
132 | 149 | Return:
|
133 | 150 | catalog : A :class:`Client` instance for this Catalog/API
|
134 | 151 | """
|
135 | 152 | client: Client = cls.from_file(
|
136 |
| - url, headers=headers, parameters=parameters, modifier=modifier |
| 153 | + url, |
| 154 | + headers=headers, |
| 155 | + parameters=parameters, |
| 156 | + modifier=modifier, |
| 157 | + request_modifier=request_modifier, |
| 158 | + stac_io=stac_io, |
137 | 159 | )
|
138 | 160 | search_link = client.get_search_link()
|
139 | 161 | # if there is a search link, but no conformsTo advertised, ignore
|
@@ -161,14 +183,19 @@ def from_file( # type: ignore
|
161 | 183 | headers: Optional[Dict[str, str]] = None,
|
162 | 184 | parameters: Optional[Dict[str, Any]] = None,
|
163 | 185 | modifier: Optional[Callable[[Modifiable], None]] = None,
|
| 186 | + request_modifier: Optional[Callable[[Request], Union[Request, None]]] = None, |
164 | 187 | ) -> "Client":
|
165 | 188 | """Open a STAC Catalog/API
|
166 | 189 |
|
167 | 190 | Returns:
|
168 | 191 | Client: A Client (PySTAC Catalog) of the root Catalog for this Catalog/API
|
169 | 192 | """
|
170 | 193 | if stac_io is None:
|
171 |
| - stac_io = StacApiIO(headers=headers, parameters=parameters) |
| 194 | + stac_io = StacApiIO( |
| 195 | + headers=headers, |
| 196 | + parameters=parameters, |
| 197 | + request_modifier=request_modifier, |
| 198 | + ) |
172 | 199 |
|
173 | 200 | client: Client = super().from_file(href, stac_io) # type: ignore
|
174 | 201 |
|
|
0 commit comments