stac_auth_proxy.utils.filters
¶
Utility functions.
InvalidFilterRequestError
¶
Bases: ValueError
The request's params can't be unambiguously combined with the proxy's filter.
Source code in src/stac_auth_proxy/utils/filters.py
25 26 | |
append_body_filter(body: dict, filter: Expr, filter_lang: Optional[str] = None) -> dict
¶
Insert a filter expression into a request body. If a filter already exists, combine them.
Source code in src/stac_auth_proxy/utils/filters.py
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | |
append_qs_filter(qs: bytes, filter: Expr) -> bytes
¶
Insert a filter expression into a raw query string (scope["query_string"]).
If a filter already exists, combine them.
The query string is parsed exactly as filter factories receive it
(dict(request.query_params)), so the forwarded params are the ones the
filter was computed for. Repeated params are rejected rather than collapsed,
as upstreams disagree on which value wins.
Source code in src/stac_auth_proxy/utils/filters.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
check_query_size(qs: bytes) -> None
¶
Reject query strings with more pieces than an upstream is sure to read.
Source code in src/stac_auth_proxy/utils/filters.py
55 56 57 58 59 60 | |
check_unique_params(keys: Iterable[str]) -> None
¶
Reject query params that filter factories and the upstream could read differently: repeated params, as upstreams disagree on which value wins (first, last, or all as an array) while factories see one, and bracket params ("collections[]"), which Express's qs parser reads as "collections".
Source code in src/stac_auth_proxy/utils/filters.py
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
dict_to_query_string(params: dict) -> str
¶
Convert a dictionary to a percent-encoded query string.
Keys and values MUST be encoded: an unescaped "&", "=", "#", "+" or "%" in a client-supplied value (e.g. a filter) would smuggle extra params upstream. Non-string values (e.g. a CQL2-JSON filter) are JSON-encoded.
Source code in src/stac_auth_proxy/utils/filters.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
parse_query_params(qs: bytes) -> QueryParams
¶
Parse a raw query string (scope["query_string"]).
Starlette's request.query_params decodes raw non-ASCII bytes as latin-1,
unlike their percent-encoded form (UTF-8). Percent-encode them first so filter
factories and the upstream see the same value.
Source code in src/stac_auth_proxy/utils/filters.py
85 86 87 88 89 90 91 92 93 | |